Model-based question and answer method, electronic equipment and medium
By generating and utilizing new sample mathematical problem text and reply information, the data set is expanded, and the problem of insufficient scale and diversity of data sets in the existing technology is solved, and the mathematical calculation ability and generalization ability of the model are improved.
Patent Information
- Application Number
- CN202411996850.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2044-12-30
AI Technical Summary
The insufficient scale and diversity of data sets in the prior art leads to a low mathematical calculation ability of the model, which in turn reduces the model's ability to answer users' mathematical reasoning questions.
By obtaining the initial sample mathematical problem text set and reply information, new sample mathematical problem text and reply information are generated, and these data are used for model training, expanding the data set, and improving the mathematical calculation ability of the model.
The expansion of the data set is achieved, the mathematical calculation ability of the model is improved, the accuracy of prediction of the reply result of the text of the answered mathematical problem is improved, and the generalization ability of the model is enhanced.
Smart Images

Figure CN119721256A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of model reasoning technology, and in particular to a model-based question-answering method, electronic equipment and medium. Background Art
[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 are designed to simulate the mathematical thinking process of humans and understand and answer mathematical problems through language processing and deep learning technology.
[0003] The size and diversity of the data set are key factors in determining model performance. How to increase the size and diversity of the data set to improve the mathematical computing power of the model, thereby improving the model's ability to answer users' mathematical reasoning questions, is a technical problem that researchers in this field urgently need to solve. Summary of the invention
[0004] The purpose of the present invention is to provide a model-based question-answering method, electronic device and medium to solve the technical problem that the small size and diversity of the data set lead to low mathematical computing power of the model, thereby reducing the model's ability to answer users' mathematical reasoning questions.
[0005] In order to solve the above technical problems, the present invention provides a model-based question-answering method, comprising:
[0006] Obtaining an initial sample math problem text set and initial sample answer information corresponding to each initial sample math problem text;
[0007] generating new sample math problem texts according to information of each initial sample math problem text;
[0008] Obtain new sample answer information corresponding to the new sample math problem text;
[0009] Performing model training using the initial sample math problem text set, the initial sample answer information, the new sample math problem text, and the new sample answer information to obtain a model for answering math problem texts;
[0010] The math question text to be answered is input into the model for answering the math question text, and the answer information corresponding to the math question text to be answered is output through the model for answering the math question text.
[0011] On the one hand, generating new sample math problem texts according to information of each initial sample math problem text comprises:
[0012] Obtaining a preset generation rule; wherein the preset generation rule includes at least one of a number replacement rule and an operation symbol addition rule;
[0013] The new sample math problem text is generated according to the preset generation rule based on the information of each initial sample math problem text.
[0014] On the other hand, the preset generation rule is a number replacement rule, and before the information of each initial sample math problem text is generated according to the preset generation rule, the method further includes:
[0015] Recording the position of the extracted numerical information in the corresponding initial sample math problem text and the number of the extracted numerical information;
[0016] The generating of the new sample math problem text according to the preset generating rule based on the information of each initial sample math problem text comprises:
[0017] Generate a random number and use the random number to replace the extracted current numerical information;
[0018] Obtaining the current position of the current numerical information in the initial sample math problem text;
[0019] 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 the new sample math problem text.
[0020] On the other hand, the preset generation rule is an operation symbol adding rule, and the generation of the new sample math problem text according to the preset generation rule for the information of each initial sample math problem text includes:
[0021] Build a list of preset operation symbols;
[0022] Matching a numerical value extracted from the initial sample math problem text for each operation symbol in the operation symbol list according to a preset symbol adding rule, and obtaining a matching result;
[0023] If the matching result is that the operator matches the value, the operator that matches the value is determined to be the operator to be added;
[0024] Randomly extract a value to be added from the matched values, and add the operation symbol to be added to the value to be added according to the value adding rule corresponding to the symbol;
[0025] Obtaining the current position of the value to be added in the initial sample math 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 the added operation symbol, and the text after the current position in the initial sample math problem text;
[0027] The step of matching the numerical values extracted from the initial sample math problem text for each operation symbol in the operation symbol list according to the preset symbol adding rule and obtaining the matching result comprises:
[0028] Obtaining operation results obtained by matching the current operation symbol with the respective numerical values extracted from the initial sample math problem text;
[0029] If it is detected that all operation results are greater than the first preset value, it is determined that the matching result is that the current operation symbol does not match a value;
[0030] If it is detected that there is an operation result that is less than or equal to the first preset value, it is determined that the matching result is that the current operation symbol matches the value.
[0031] On the other hand, before adding the to-be-added numerical value to the to-be-added operation symbol according to the numerical value adding 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 yes, then enter the step of adding the to-be-added numerical value and the to-be-added operation symbol according to the numerical value adding 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 generating of the new sample math problem text according to the preset generating rule based on the information of each initial sample math problem text includes at least one of the following methods:
[0036] Method 1:
[0037] Obtaining a value of the precision to be adjusted from the initial sample math problem text;
[0038] Obtaining an operation symbol acting on the numerical value of the precision to be adjusted;
[0039] Determine whether to adjust the precision of the value to be adjusted according to the numerical operation rule of the operation symbol;
[0040] If so, adjust the precision of the value to be adjusted and obtain the precision-adjusted value; obtain the current position of the value to be adjusted in the initial sample math problem text; concatenate the text before the current position in the initial sample math problem text, the precision-adjusted value and the text after the current position in the initial sample math problem text to form the new sample math problem text;
[0041] If not, the value of the precision to be adjusted remains unchanged;
[0042] Method 2:
[0043] Obtaining each operation symbol in the initial sample math problem text;
[0044] Replacing each operation symbol in the initial sample math problem text;
[0045] Using the initial sample math problem text after replacing the operation symbol as the new sample math problem text;
[0046] Method 3:
[0047] Obtaining a position of a to-be-adjusted format from the initial sample math problem text;
[0048] Determining whether to perform format adjustment at the position of the format to be adjusted according to the representation of the operation symbol;
[0049] If yes, then the format of the position to be formatted is adjusted, and the initial sample math problem text after the format adjustment is used as the new sample math problem text;
[0050] If not, the format adjustment operation at the position of the to-be-adjusted format is canceled.
[0051] On the other hand, before obtaining new sample answer information corresponding to the new sample math problem text, the method further includes:
[0052] Determining whether the new sample math problem text meets preset requirements;
[0053] If yes, then enter the step of obtaining new sample answer information corresponding to the new sample math problem text;
[0054] If not, the new sample math problem texts that do not meet the preset requirements are eliminated from all the new sample math problem texts, and the remaining sample math problem texts are used as the new sample math problem texts; and the step of obtaining new sample answer information corresponding to the new sample math problem texts is entered.
[0055] On the other hand, the obtaining of new sample answer information corresponding to the new sample math problem text includes:
[0056] According to the pre-established correspondence between the operation symbols and the marks, the operation symbols in the new sample math problem text are converted into corresponding marks, the constant letters in the new sample math problem text are replaced with corresponding numbers, and the infix expressions in the new sample math problem text are converted into postfix expressions by stacking; wherein the mark is a character;
[0057] Iterate over each element in the suffix expression;
[0058] Perform corresponding processing according to the condition of the element; wherein the condition of the element at least includes whether the element is an operand, a unary operator or a binary operator;
[0059] splicing the expression list according to the processed results, and if it is detected that the suffix expression includes a numerical value, transforming the mark in the expression list into the corresponding operation symbol according to the corresponding relationship, and using the transformed value as the new sample reply information;
[0060] If it is detected that the suffix expression contains multiple values, then return to the step of traversing each element in the suffix expression;
[0061] The performing corresponding processing according to the situation of the element includes:
[0062] If it is detected that the current element is an operand, the current element is pushed into the stack;
[0063] If it is detected that the current element is a binary operator and the binary operator has not processed an operand, the two operands at the top of the stack are popped, the binary operation is performed, the calculation result is pushed into the stack, and the corresponding calculation result and the corresponding part of the new sample math problem text are updated;
[0064] If it is detected that the current element is a unary operator and the unary operator has not processed an operand, an operand at the top of the stack is popped, the unary operation is performed, the calculation result is pushed into the stack, and the corresponding calculation result and the corresponding part of the new sample math problem text are updated.
[0065] In order to solve the above technical problem, the present invention further provides an electronic device, comprising:
[0066] Memory for storing computer programs;
[0067] A processor is used to implement the steps of the above-mentioned model-based question-answering method when executing the computer program.
[0068] In order to solve the above technical problem, the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above model-based question-answering method are implemented.
[0069] The beneficial effect of the present invention is that in the method, in the model-based question-answering method, a new sample mathematical question text is generated according to the information of each initial sample mathematical question text, and new sample answer information corresponding to the new sample mathematical question text is obtained, that is, the expansion of the data set is realized; the model is trained using the initial sample mathematical question text set, the initial sample answer information, the new sample mathematical question text and the new sample answer information, that is, the model is trained using the expanded data set, and the mathematical calculation ability of the model is improved. When the trained model for answering mathematical question text is used to predict the answer result of the mathematical question text to be answered, the accuracy of the answer result prediction of the mathematical question text to be answered is improved. Moreover, when expanding the data set, a new sample mathematical question text is generated based on the information of each initial sample mathematical question text, that is, the initial sample mathematical question text is fine-tuned, and the training data set can be expanded without actually collecting more original data, thereby enhancing the generalization ability of the model.
[0070] In addition, a new sample math problem text is generated for each initial sample math problem text according to a preset generation rule (including at least one of a number replacement rule and an operation symbol addition rule), so that a new sample math problem text can be obtained flexibly. Specifically, a new sample math problem text is generated by replacing the numerical value in the new sample math problem text by generating a random number; a new sample math problem text is generated by adding an operation symbol, and a numerical value is matched for each operation symbol in the operation symbol list from the numerical value extracted from the initial sample math problem text according to the preset symbol addition rule, so that the generated new sample math problem text conforms to the actual operation situation.
[0071] Before adding the operation symbol to the numerical value to be added according to the numerical value adding rule corresponding to the symbol, it is determined whether the generated random number is less than or equal to the second preset value to determine whether to add the operation symbol to the numerical value, thereby achieving control over the number of added operation symbols.
[0072] Moreover, new sample math problem texts can be generated by adjusting the precision of numerical values in the initial sample math problem texts, replacing operation symbols, or adjusting the format of the initial sample math problem texts, thereby further expanding the scale and diversity of the data set.
[0073] Before obtaining new sample answer information corresponding to a new sample math problem text, it is judged whether the new sample math problem text meets preset requirements, and it is ensured as much as possible that only valid new sample math problem text is calculated.
[0074] According to the pre-established correspondence between operators and marks, the operators in the new sample math problem text are converted into corresponding marks, and the constant letters in the new sample math problem text are replaced with corresponding numbers. The infix expressions in the new sample math problem text are generated into suffix expressions through a stack. Each element in the suffix expression is traversed and processed accordingly according to the situation of the element; the expression list is concatenated according to the processed result. If the suffix expression is detected to be a numeric value, the mark in the expression list is transformed into the corresponding operator according to the correspondence, and the converted value is used as the new sample answer information. The new sample answer information corresponding to the new sample math problem text is determined.
[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 above-mentioned model-based question-answering method and have the same effects as above. BRIEF DESCRIPTION OF THE DRAWINGS
[0076] In order to more clearly illustrate the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0077] Figure 1 A flowchart of a model-based question-answering method provided by an embodiment of the present invention;
[0078] Figure 2 A flowchart of a method for generating a complex computing problem provided by an embodiment of the present invention;
[0079] Figure 3 A flowchart of a method for gradually solving a generated complex computing problem provided by an embodiment of the present invention;
[0080] Figure 4 A structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0081] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0082] The core of the present invention is to provide a model-based question-answering method, electronic device and medium to solve the technical problem that the small size and diversity of the data set lead to low mathematical computing power of the model, thereby reducing the model's ability to answer users' mathematical reasoning questions.
[0083] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods. Figure 1 A flowchart of a model-based question-answering method provided by an embodiment of the present invention, such as Figure 1 As shown, the method includes:
[0084] S10: Obtaining an initial sample math problem text set and initial sample answer information corresponding to each initial sample math problem text;
[0085] S11: generating a new sample math problem text according to the information of each initial sample math problem text;
[0086] S12: Obtain new sample answer information corresponding to the new sample math problem text;
[0087] S13: Performing model training using the initial sample math problem text set, the initial sample answer information, the new sample math problem text, and the new sample answer information to obtain a model for answering the math problem text;
[0088] S14: inputting the math question text to be answered into the model for answering the math question text, and outputting answer information corresponding to the math question text to be answered through the model for answering the math question text.
[0089] There is no limitation on the initial sample math problem text set, which is determined according to the actual situation. In order to improve the mathematical calculation ability of the model, the embodiment of the present invention expands the sample data set based on the initial sample math problem text set. The expansion of the data set mainly includes two aspects. The first aspect is the generation of complex calculation problems (such as generating sin1+cos1), and the second aspect is the step-by-step solution of the generated complex calculation problems (i.e., the collection of solution steps, such as first solving the value of sin1, then solving the value of cos1, and finally adding the value of sin1 to the value of cos1).
[0090] First, the process of generating complex computational problems is explained.
[0091] When generating new sample math problem texts according to the information of each initial sample math problem text, first obtain a preset generation rule; wherein the preset generation rule includes at least one of a number replacement rule and an operation symbol addition rule; then generate a new sample math problem text according to the preset generation rule for the information of each initial sample math problem text.
[0092] Specifically, in some embodiments, the preset generation rule is a number replacement rule. Before generating a new sample math problem text according to the preset generation rule for the information of each initial sample math problem text, the method further includes:
[0093] The position of the extracted numerical information in the corresponding initial sample math problem text and the number of extracted numerical information are recorded.
[0094] Generating new sample math problem texts according to preset generation rules for the information of each initial sample math problem text includes:
[0095] Generate a random number and use the random number to replace the current numerical information extracted;
[0096] Get the current position of the current numerical information in the initial sample math 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] That is, in order to expand the original calculation data set, this embodiment generates different combinations by changing the numbers in the original data, and counts the positions and numbers of the numbers, and finally generates new data variants. The following are detailed steps and specific implementations:
[0099] Step 1: Extract the numbers in the original template data and count them.
[0100] It is necessary to extract all the numbers in the original template data. For example, for the original data: 100 - (10 / 2), the three numbers 100, 10 and 2 can be extracted. The extracted numbers will be stored in a list for subsequent processing. In order to avoid confusion during the replacement process, such as replacing 10 and 10 in 100 at the same time, it is necessary to count the number of numbers in the list at the same time so that the corresponding number can be accurately located according to the index.
[0101] Step 2: Loop and replace the generated numbers.
[0102] In each loop, a number is selected from the list of extracted numbers and replaced according to its position in the text. To avoid confusion, it is necessary to ensure that the replacement operation is performed in order and that each number is replaced independently. A random number is generated (usually a random integer between 1 and 5 digits), 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 the next number. Repeat this process until enough variations are generated.
[0104] In the above, different combinations are generated by changing the numbers in the original data, and the positions and numbers of the numbers are counted, and finally new data variants are generated, thereby expanding the data set. In order to further expand the data set, in some embodiments, the preset generation rule is an operation symbol addition rule, and the information of each initial sample math problem text is generated according to the preset generation rule. The new sample math problem text includes:
[0105] Build a list of preset operation symbols;
[0106] According to a preset symbol adding rule, a numerical value is matched for each operation symbol in the operation symbol list from the numerical values extracted from the initial sample math problem text, and a matching result is obtained;
[0107] If the matching result is that the operator matches the value, the operator that matches the value is determined to be the operator to be added;
[0108] A value to be added is randomly selected from the matched values, and the value to be added is added with the operation symbol to be added according to the value adding rule 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 the added operation symbol, 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] Among them, according to the preset symbol adding rule, matching the numerical value of each operation symbol in the operation symbol list from the numerical value extracted from the initial sample math problem text, and obtaining the matching result includes:
[0112] Obtain the operation results obtained by matching the current operation symbol with the values extracted from the initial sample math problem text;
[0113] If it is detected that all operation results are greater than the first preset value, it is determined that the matching result is that the current operation symbol does not match a value;
[0114] If it is detected that there is an operation result that is less than or equal to the first preset value, the matching result is determined as the current operation symbol matching the value. The first preset value is not limited and is determined according to actual conditions.
[0115] That is, in order to expand the data set, some operators are randomly added to the data in this embodiment to generate complex and diverse calculation expressions. First, define and build a list containing multiple operators, such as ['!', 'e', 'π', '%', '°', 'sin', 'cos', 'tan', 'ln', 'lg', '√', '^', 'log']. According to the calculation method of different operators, different digital patterns are matched, and the symbols are added to the data according to the rules. The detailed steps are:
[0116] Step 1: Determine whether to add the specified operator.
[0117] Loop according to the order of symbols in the list. There is no restriction on the rules for adding operators, which are determined according to the actual operators. For example, for the factorial symbol !, due to the large amount of factorial calculation, it can only be added after a single number 1 to 9. If such a number is not matched, the factorial symbol is skipped. For the exponentiation operator ^, in order to avoid too large a value, it is necessary to match a value of at most two digits, and satisfy the condition that no other operators have been added before and after the number. For other operators ['e', 'π', '%', '°', 'sin', 'cos', 'tan', 'ln', 'lg', '√', 'log'], it is necessary to satisfy the condition that no other symbols have been added before and after the number. If such a number is not matched, the addition of the operator is skipped and the loop continues.
[0118] Step 2: Connect the symbols and numbers.
[0119] Randomly select a number from the matched numbers that meet the requirements as the number to be added, and concatenate symbols such as 'e', 'π', '%', '°', etc. after the given number. Concatenate symbols such as 'sin', 'cos', 'tan', 'ln', 'lg', '√', etc. in front of the given number. Since the '^' and 'log' symbols require a base when they are operated, they need to be randomly generated while concatenating. Concatenate the text before the starting position, the number with the special operator added, and the text after the starting position to form new data.
[0120] After completing multiple cycles, multiple different data combinations 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] In addition, when adding an operator, the ratio of adding the operator can be set. Specifically, before adding the operator to be added to the value according to the numerical value adding rule corresponding to the symbol, it also includes:
[0122] Generate a random number, and determine whether the generated random number is less than or equal to a second preset value;
[0123] If yes, then proceed to the step of adding the operation symbol to be added to the value to be added according to the value adding rule corresponding to the symbol;
[0124] If not, return to the step of randomly selecting a value to be added from the matched values.
[0125] There is no limitation on the second preset value, which is determined according to actual conditions, such as setting the random probability to 15%.
[0126] In the above, by randomly adding some operation symbols to the data to generate complex and diverse calculation expressions, the data set is expanded. In order to further expand the data set, in some embodiments, the information of each initial sample math problem text is generated according to the preset generation rules, which 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 math problem text;
[0129] Get the operator that acts on the value whose precision is to be adjusted;
[0130] Determine whether to adjust the precision of the value to be adjusted according to the numerical operation rules of the operator;
[0131] If so, adjust the precision of the value to be adjusted, and obtain the precision-adjusted value; obtain the current position of the value to be adjusted in the initial sample math problem text; concatenate the text before the current position in the initial sample math problem text, the precision-adjusted value, and the text after the current position in the initial sample math problem text to form a new sample math problem text;
[0132] If not, the value of the precision to be adjusted remains unchanged.
[0133] Method 2:
[0134] Obtain each operation symbol in the initial sample math problem text;
[0135] Replace each operation symbol in the initial sample math problem text;
[0136] The initial sample math problem text after the operation symbols are replaced is used as the new sample math problem text.
[0137] Method 3:
[0138] Obtaining positions to be formatted from an initial sample math problem text;
[0139] Determine whether to perform format adjustment at the position of the format to be adjusted according to the representation of the operation symbol;
[0140] If so, the format of the position to be formatted is adjusted, and the initial sample math problem text after the format adjustment is used as a new sample math problem text;
[0141] If not, the format adjustment operation on the position to be formatted is canceled.
[0142] That is, in method 1, the data set is expanded by adjusting the numerical precision, such as adding decimals. In method 2, the data set is expanded by replacing symbols. In method 3, the data set is expanded by adjusting the format of the initial sample math problem text, such as adding spaces.
[0143] The following is an example of using the above three methods to expand the data set. The data diversity is further enriched by randomly adding decimals, changing operation symbols, and adding spaces. The following are some steps and methods for modifying the operation.
[0144] Step 1: Add decimals.
[0145] Add decimals randomly to the data to generate more diverse numeric expressions. Check the matched numbers for a factorial symbol!. If a factorial symbol exists, skip the number and do not add a decimal. Generate a random two-digit decimal for the matched numbers that do not have a factorial symbol. Concatenate the text before the start position, the number with the decimal added, and the text after the start position to form new data. For example, for the original data 100 - (10 / 2), you can generate different combinations such as 100.12 - (10 / 2) or 100 - (10.34 / 2).
[0146] Step 2: Symbol replacement.
[0147] Symbol replacement not only increases the diversity of data, but also ensures conversion between different formats. For example, replacing the division symbol / with ÷, the multiplication symbol * with ×, and the exponential operator ^ with ** can effectively change the appearance and format of the expression.
[0148] Step 3: Add spaces.
[0149] By randomly adding spaces before and after symbols, we can increase the randomness of expressions and make them clearer and easier to read in some cases. Specifically, we randomly insert spaces before and after common operators such as addition, subtraction, division, and multiplication. For the exponential operator **, we need to avoid inserting spaces in the middle of **, because ** is a whole operator and separating it will change its meaning.
[0150] Similarly, when adding spaces and decimals, you can control the proportion of addition. For example, you can set the random probability to 15% in the loop to control the proportion of special characters, spaces, and decimals.
[0151] The method provided in this embodiment can effectively expand the original data set by replacing the original numbers, randomly adding special operation symbols, replacing operators, adding spaces and adding decimals, thereby generating more diverse calculation expressions. This transformation method can make the generated data more random, which can help improve the adaptability to different writing formats in model training and ensure that the generated expressions are still mathematically reasonable.
[0152] Figure 2 A flowchart of a method for generating a complex computing problem provided by an embodiment of the present invention, such as Figure 2 As shown, the method includes:
[0153] S15: original digital expansion and replacement;
[0154] S16: Add special operation symbols;
[0155] S17: Add decimals, symbol replacement, and space addition.
[0156] So far, the expansion and regeneration of complex calculation problems involving other than four arithmetic operations have been completed. Next, the generated complex calculation problems need to be solved step by step. Since the generated new sample math problem text may contain invalid text (such as only the front bracket, no back bracket, etc.), before obtaining the new sample answer information corresponding to the new sample math problem text, it also includes:
[0157] Determine whether the new sample math problem text meets the preset requirements;
[0158] If yes, then enter the step of obtaining new sample answer information corresponding to the new sample math problem text;
[0159] If not, then the new sample math problem texts that do not meet the preset requirements are eliminated from all new sample math problem texts, and the remaining sample math problem texts are used as new sample math problem texts; and the step of obtaining new sample answer information corresponding to the new sample math problem texts is entered.
[0160] In some embodiments, obtaining new sample answer information corresponding to the new sample math problem text includes:
[0161] According to the pre-established correspondence between operator symbols and marks, the operator symbols in the new sample math problem text are converted into corresponding marks, the constant letters in the new sample math problem text are replaced with corresponding numbers, and the infix expressions (infix expressions are: the operator is placed in the middle of the operands, and parentheses and operator priority are usually required to clarify the order of operations, such as 3+5 is an infix expression) in the new sample math problem text are converted into postfix expressions (postfix expressions are: the operator follows the operands. It does not require parentheses to control the order of operations, and the order of operations is determined by the order of operators and stack operations. During calculation, the operands are first pushed into the stack. When an operator is encountered, the corresponding operands are popped from the stack for calculation. For example, 53+ is a postfix expression); wherein the mark is a character;
[0162] Iterate over each element in the suffix expression;
[0163] Perform corresponding processing according to the condition of the element; wherein the condition of the element at least includes whether the element is an operand, a unary operator or a binary operator;
[0164] Concatenate the expression list according to the processed results. If it is detected that the suffix expression includes a numerical value, transform the marks in the expression list into corresponding operation symbols according to the corresponding relationship, and use the transformed value as the new sample reply information;
[0165] If it is detected that the suffix expression contains multiple values, then return to the step of traversing each element in the suffix expression;
[0166] Among them, corresponding processing according to the situation of the element includes:
[0167] If it is detected that the current element is an operand, the current element is pushed into the stack;
[0168] If it is detected that the current element is a binary operator and the binary operator has not processed operands, the two operands at the top of the stack are popped, the binary operation is performed, the calculation result is pushed into the stack, and the corresponding calculation result and the corresponding part of the new sample math problem text are updated;
[0169] If it is detected that the current element is a unary operator and the unary operator has not processed an operand, an operand at the top of the stack is popped, the unary operation is performed, the calculation result is pushed into the stack, and the corresponding calculation result and the corresponding part of the new sample math problem text are updated.
[0170] In order to help those skilled in the art better understand the process of collecting the above 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 whether the generated expression is legal, such as checking whether the brackets and special characters in the expression are legal.
[0172] Use a stack (a data structure whose basic characteristic is to follow the last-in-first-out principle, which means that the last element pushed into the stack will be popped out first) to store the left bracket and match it when the right bracket is encountered. If the match is unsuccessful, skip the data. If the stack is empty after the entire expression is processed, it means that the bracket is matched successfully, otherwise skip the data.
[0173] Store all valid characters or strings, traverse all valid characters, and delete them one by one from the input expression. If the string is empty after deletion, it means it only contains valid characters, otherwise skip the data.
[0174] Step 2: Generate a postfix expression.
[0175] To generate a postfix expression from an infix expression through a stack, each special operator in the expression needs to be rewritten as a specific token. The corresponding dictionary list is { "sin": "$", "cos": "@", "tan": "#", "ln": "&", "√": "_", "lg": "`", "log": ";"}. Replace the constants in the expression with corresponding numbers, such as e as 2.718281, and insert corresponding operator symbols such as * and parentheses to ensure the calculation relationship between symbols and numbers.
[0176] Step 3: Generate calculation results step by step according to the suffix expression.
[0177] Create an empty stack to store operands, and set the initial mark to indicate whether the operand has been processed. Loop through each element in the suffix expression to determine whether it is an operand or an operator. If the current element is a binary operator +-* / ^, and the operand has not been processed, pop the two operands at the top of the stack, perform the binary operation, push the result into the stack, set the mark to True, and update the corresponding calculation result and the corresponding part of the original expression. If the current element is a unary operator such as $ @#&_ ! `, and the operand has not been processed, pop an operand at the top of the stack, perform the unary operation, push the result into the stack, set the mark to True, and update the corresponding calculation result and the corresponding part of the original expression. If the current element is an operand, push it directly into the stack.
[0178] Repeat the above operation continuously, concatenating the expression list each time, checking the length of the suffix expression, and exiting the loop if it is less than or equal to 1 value. Then replace the special characters in the expression list with the original sin, cos, etc. expressions, rounding all floating numbers to three decimal places to get the complete calculation process.
[0179] The final generated fine-tuning data looks 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 of a method for gradually solving a complex computing problem generated by an embodiment of the present invention is provided, such as Figure 3 As shown, the method includes:
[0186] S18: Check the legality of the generated expression;
[0187] S19: insert specific tokens to generate suffix expressions;
[0188] S20: loop and gradually generate calculation results;
[0189] S21: concatenate the results and replace the special symbols.
[0190] The above process realizes the collection of problem computational solution steps.
[0191] In the method provided in the embodiment of the present invention, an initial sample math problem text set (i.e., an original data set template) is used to change numbers, and operators are randomly added to numbers according to the characteristics of special operation symbols, decimals are randomly added after the numbers, operation symbols in the expression are replaced, and spaces are added to obtain a construction method for obtaining data containing complex operation problem expressions. At the same time, an expression verification method is provided, and a data expansion method is provided for gradually looping calculations to generate complete calculation and solution steps.
[0192] After obtaining the initial sample math problem text set, the initial sample answer information, the new sample math problem text and the new sample answer information, the initial sample math problem text set, the initial sample answer information, the new sample math problem text and the new sample answer information are used to perform model training to obtain a model for answering math problem texts. After obtaining the math problem text to be answered, the math problem text to be answered can be input into the model for answering the math problem text, and the answer information corresponding to the math problem text to be answered is output by the model for answering the math problem text.
[0193] In implementation, in order to improve the accuracy of the model's prediction of the answer information of the math question text to be answered, after the model is trained using the initial sample math question text set, the initial sample answer information, the new sample math question text and the new sample answer information to obtain the model for answering the math question text, before the math question text to be answered is input into the model for answering the math question text, the method further includes:
[0194] Get a text set of math problems for testing;
[0195] Inputting each test math question text in the math question text set for testing into the model for answering math question texts respectively, and outputting answer information corresponding to each test math question text through the model for answering math question texts;
[0196] Obtain the actual answer information corresponding to each test math question text;
[0197] In the case where it is detected that the accuracy of the answer information of the math problem text set used for the test is greater than or equal to a preset value, entering the step of inputting the math problem text to be answered into the model used for answering the math problem text;
[0198] When it is detected that the accuracy of the answer information of the math problem text set used for testing is less than a preset value, the process returns to the step of generating new sample math problem texts according to the information of each initial sample math problem text.
[0199] There is no limit on the preset value, and the predicted answer information of the math problem text set used for testing is exactly the same as the actual answer information, indicating that the higher the accuracy of the model prediction results used to answer the math problem text, the better.
[0200] In the method, the accuracy of the prediction of the model for answering the mathematical question text is judged by using the mathematical question text set used for testing. When it is detected that the accuracy of the answer information of the mathematical question text set used for testing is greater than or equal to a preset value, the model for answering the mathematical question text is used to predict the mathematical question text to be answered, thereby ensuring the accuracy of the model prediction results as much as possible.
[0201] The present invention achieves the expansion of the data set through the method described above. Numerical calculation data sets play an important role in improving mathematical calculation capabilities in large model training. They include:
[0202] 1. Strengthen basic mathematical skills.
[0203] Arithmetic operations: Through a large number of addition, subtraction, multiplication and division operations, the model is better able to 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 processing a large number of mathematical calculations, the model can learn how to maintain numerical stability and avoid calculation errors.
[0208] Precision training: Numerical computing datasets can help models be more accurate when processing precise numbers such as decimals and fractions.
[0209] By numerically calculating the data set, the performance of the model can be evaluated more accurately and its weaknesses in mathematical calculations can be identified. Based on the evaluation results, the model can be optimized in a targeted manner. The purpose of expanding the calculation data is to increase the diversity and scale of the data set to enhance the performance and generalization ability of the large model.
[0210] For tasks that rely on large amounts of data for effective training, the size and diversity of the dataset are key factors in determining model performance. Common open source datasets usually only include basic addition, subtraction, multiplication and division operations. By expanding the dataset, the model can be exposed to more diverse training samples containing complex symbols and special characters, helping it learn to cope with different scenarios, features and variations. 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 improving computing power for large model fine-tuning training.
[0211] In the above embodiments, the model-based question-answering method is described in detail, and the present invention also provides embodiments of a model-based question-answering device and an electronic device. It should be noted that the present invention describes the embodiments of the device part from two perspectives, one is based on the functional module perspective, and the other is based on the hardware perspective.
[0212] The model-based question-answering device provided by the embodiment of the present invention includes, from the perspective of functional modules:
[0213] A first acquisition module is used to acquire an initial sample math problem text set and initial sample answer information corresponding to each initial sample math problem text;
[0214] A generation module, used for generating new sample math problem texts according to the information of each initial sample math problem text;
[0215] The second acquisition module is used to acquire new sample answer information corresponding to the new sample math problem text;
[0216] A training module, used for performing model training using an initial sample math problem text set, initial sample answer information, new sample math problem texts and new sample answer information to obtain a model for answering math problem texts;
[0217] The input and output module is used to input the math question text to be answered into the model for answering the math question text, and output the answer information corresponding to the math question text to be answered through the model for answering the math question text.
[0218] In some embodiments, the model-based question-answering apparatus further includes:
[0219] The recording module is used to record the position of the extracted numerical information in the corresponding initial sample math problem text and the number of the extracted numerical information.
[0220] In some embodiments, the model-based question-answering apparatus further includes:
[0221] A generation and judgment module, used for generating a random number and judging whether the generated random number is less than or equal to a second preset value; if so, triggering the adding module; if not, triggering the extracting module;
[0222] An adding module, used for adding the operation symbol to be added to the value to be added according to the value adding rule 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 apparatus further includes:
[0225] The first judgment module is used to judge whether the new sample math problem text meets the preset requirements; if so, the second acquisition module is triggered; if not, the elimination module is triggered;
[0226] The elimination module is used to eliminate new sample math problem texts that do not meet 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 part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the apparatus part, which will not be repeated here.
[0228] Figure 4 This is a structural diagram of an electronic device provided by an embodiment of the present invention. This embodiment is based on the hardware perspective, such as Figure 4 As shown, the electronic equipment includes:
[0229] A memory 20, used for storing computer programs;
[0230] The processor 21 is used to implement the steps of the model-based question-answering method mentioned in the above embodiment when executing the computer program.
[0231] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of a digital signal processor (DSP), a field-programmable gate array (FPGA), and a programmable logic array. The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a central processing unit (CPU); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a graphics processing unit (GPU), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an artificial intelligence (AI) processor, which is used to process computing 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 a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 20 is at least used to store the following computer program 201, wherein, after the computer program is loaded and executed by the processor 21, it can implement the relevant steps of the model-based question-answering method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, etc., and the storage method may be temporary storage or permanent storage. Among them, 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 above-mentioned model-based question-answering method, etc.
[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 source 25 , and a communication bus 26 .
[0234] Those skilled in the art will understand that Figure 4 The structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure.
[0235] The electronic device provided by an embodiment of the present invention includes a memory and a processor. When the processor executes the program stored in the memory, it can implement the following method: a model-based question-answering method, with the same effect as above.
[0236] The present invention also provides a computer program product, comprising a computer program / instruction, which implements the steps of the above-mentioned model-based question-answering method when executed by a processor.
[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, and when the computer program is executed by a processor, the steps recorded in the above method embodiment are implemented.
[0238] It is understandable that if the method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, 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, and the computer software product is stored in a storage medium to execute all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc. Various media that can store program codes.
[0239] The computer-readable storage medium provided by the present invention includes the above-mentioned model-based question-answering method, and the effect is the same as above.
[0240] The above is a detailed introduction to a model-based question-and-answer method, electronic device, and medium provided by the present invention. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referenced to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principle of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the scope of protection of the present invention.
[0241] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
Claims
1. A model-based question answering method, characterized in that: include: Obtaining an initial sample math problem text set and initial sample answer information corresponding to each initial sample math problem text; generating new sample math problem texts according to information of each initial sample math problem text; Obtain new sample answer information corresponding to the new sample math problem text; Performing model training using the initial sample math problem text set, the initial sample answer information, the new sample math problem text, and the new sample answer information to obtain a model for answering math problem texts; The math question text to be answered is input into the model for answering the math question text, and the answer information corresponding to the math question text to be answered is output through the model for answering the math question text.
2. The model-based question-answering method according to claim 1, characterized in that: Generating new sample math problem texts according to the information of each initial sample math problem text comprises: Obtaining a preset generation rule; wherein the preset generation rule includes at least one of a number replacement rule and an operation symbol addition rule; The new sample math problem text is generated according to the preset generation rule based on the information of each initial sample math problem text.
3. The model-based question-answering method according to claim 2, characterized in that: The preset generation rule is a number replacement rule. Before generating the new sample math problem text according to the preset generation rule for the information of each initial sample math problem text, the method further includes: Recording the position of the extracted numerical information in the corresponding initial sample math problem text and the number of the extracted numerical information; The generating of the new sample math problem text according to the preset generating rule based on the information of each initial sample math problem text comprises: Generate a random number and use the random number to replace the extracted current numerical information; Obtaining the current position of the current numerical value information in the initial sample math problem text; 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 the new sample math problem text.
4. The model-based question-answering method according to claim 2, characterized in that: The preset generation rule is an operation symbol adding rule, and the generation of the new sample math problem text according to the preset generation rule for the information of each initial sample math problem text includes: Build a list of preset operation symbols; Matching a numerical value extracted from the initial sample math problem text for each operation symbol in the operation symbol list according to a preset symbol adding rule, and obtaining a matching result; If the matching result is that the operator matches the value, the operator that matches the value is determined to be the operator to be added; Randomly extract a value to be added from the matched values, and add the operation symbol to be added to the value to be added according to the value adding rule corresponding to the symbol; Obtaining the current position of the value to be added in the initial sample math 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 the added operation symbol, and the text after the current position in the initial sample math problem text; The step of matching the numerical values extracted from the initial sample math problem text for each operation symbol in the operation symbol list according to the preset symbol adding rule and obtaining the matching result comprises: Obtaining operation results obtained by matching the current operation symbol with the respective numerical values extracted from the initial sample math problem text; If it is detected that all operation results are greater than the first preset value, it is determined that the matching result is that the current operation symbol does not match a value; If it is detected that there is an operation result that is less than or equal to the first preset value, it is determined that the matching result is that the current operation symbol matches the value.
5. The model-based question-answering method according to claim 4, characterized in that: Before adding the value to be added to the operation symbol to be added according to the value adding rule 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 yes, then enter the step of adding the to-be-added numerical value and the to-be-added operation symbol according to the numerical value adding rule corresponding to the symbol; If not, return to the step of randomly selecting a value to be added from the matched values.
6. The model-based question-answering method according to claim 2, characterized in that: The generating of the new sample math problem text according to the preset generating rule based on the information of each initial sample math problem text includes at least one of the following methods: Method 1: Obtaining a value of the precision to be adjusted from the initial sample math problem text; Obtaining an operation symbol acting on the numerical value of the precision to be adjusted; Determine whether to adjust the precision of the value to be adjusted according to the numerical operation rule of the operation symbol; If so, adjust the precision of the value to be adjusted and obtain the precision-adjusted value; obtain the current position of the value to be adjusted in the initial sample math problem text; concatenate the text before the current position in the initial sample math problem text, the precision-adjusted value and the text after the current position in the initial sample math problem text to form the new sample math problem text; If not, the value of the precision to be adjusted remains unchanged; Method 2: Obtaining each operation symbol in the initial sample math problem text; Replacing each operation symbol in the initial sample math problem text; Using the initial sample math problem text after replacing the operation symbol as the new sample math problem text; Method 3: Obtaining a position of a to-be-adjusted format from the initial sample math problem text; Determining whether to perform format adjustment at the position of the format to be adjusted according to the representation of the operation symbol; If yes, then the format of the position to be formatted is adjusted, and the initial sample math problem text after the format adjustment is used as the new sample math problem text; If not, the format adjustment operation at the position of the to-be-adjusted format is canceled.
7. The model-based question-answering method according to any one of claims 2 to 6, characterized in that: Before obtaining new sample answer information corresponding to the new sample math problem text, the method further includes: Determining whether the new sample math problem text meets preset requirements; If yes, then enter the step of obtaining new sample answer information corresponding to the new sample math problem text; If not, the new sample math problem texts that do not meet the preset requirements are eliminated from all the new sample math problem texts, and the remaining sample math problem texts are used as the new sample math problem texts; and the step of obtaining new sample answer information corresponding to the new sample math problem texts is entered.
8. The model-based question-answering method according to claim 7, characterized in that: The obtaining of new sample answer information corresponding to the new sample math problem text includes: According to the pre-established correspondence between the operation symbols and the marks, the operation symbols in the new sample math problem text are converted into corresponding marks, the constant letters in the new sample math problem text are replaced with corresponding numbers, and the infix expressions in the new sample math problem text are converted into postfix expressions by stacking; wherein the mark is a character; Iterate over each element in the suffix expression; Perform corresponding processing according to the condition of the element; wherein the condition of the element at least includes whether the element is an operand, a unary operator or a binary operator; splicing the expression list according to the processed results, and if it is detected that the suffix expression includes a numerical value, transforming the mark in the expression list into the corresponding operation symbol according to the corresponding relationship, and using the transformed value as the new sample reply information; If it is detected that the suffix expression contains multiple values, then return to the step of traversing each element in the suffix expression; The performing corresponding processing according to the situation of the element includes: If it is detected that the current element is an operand, the current element is pushed into the stack; If it is detected that the current element is a binary operator and the binary operator has not processed an operand, the two operands at the top of the stack are popped, the binary operation is performed, the calculation result is pushed into the stack, and the corresponding calculation result and the corresponding part of the new sample math problem text are updated; If it is detected that the current element is a unary operator and the unary operator has not processed an operand, an operand at the top of the stack is popped, the unary operation is performed, the calculation result is pushed into the stack, and the corresponding calculation result and the corresponding part of the new sample math problem text are updated.
9. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the model-based question-answering method according to any one of claims 1 to 8 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the model-based question-answering method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Numerical reasoning method and system based on reasoning step cascading and storage medium
CN116151373A
Mathematical reasoning question and answer method and device, storage medium and equipment
CN117764175A
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