A mathematical application problem solving method and device and computer readable storage medium
By combining the loss functions of text and equation encoders in the mathematical word problem solving model to train the text encoder, the problem of low accuracy and reliability caused by focusing only on text sample analogy learning in the existing technology is solved, and higher accuracy and reliability of the solution effect is achieved.
Patent Information
- Application Number
- CN202410366151.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-28
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2044-03-28
AI Technical Summary
Existing methods for solving mathematical word problems focus only on analogical learning between text samples during the model training phase, neglecting analogical learning between equation samples, resulting in low accuracy and reliability of the solution model.
We obtain the text and equations of training samples of mathematical word problems, extract feature vectors through text encoder and equation encoder respectively, construct text loss function and equation loss function, and iteratively train the text encoder by combining the target loss function of the text encoder, focusing on analogical learning between text and equation samples.
This improves the accuracy and reliability of the mathematical word problem solving model. By focusing on analogical learning of text and equation samples, it fully extracts the quantitative and logical relationships in the word problem text, thereby enhancing the accuracy of feature extraction in the model.
Smart Images

Figure CN118070924B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of automated problem-solving technology for mathematical word problems, and in particular to a method, apparatus, and computer-readable storage medium for solving mathematical word problems. Background Technology
[0002] Math Word Problem (MWP) is a task that automatically performs logical reasoning and generates mathematical solutions from mathematical problems described in natural language. When solving math word problems, one cannot rely on superficial keyword matching, but must have a comprehensive understanding of the text information.
[0003] Analogy learning constructs representations by encoding the similarity or dissimilarity of two things. In the process of learning mathematics in daily life, teachers often use analogy questions to test students' learning abilities. This shows that how to establish analogy between problems is one of the keys to solving mathematical problems. Therefore, analogy learning-based methods are widely used in solving mathematical problems. Existing analogy-based mathematical word problem solving models train by calculating the similarity between the problem to be solved in the training set and various problem texts in the problem text database to filter positive and negative samples of the problem to be solved. Analogy learning is then performed on the problem to be solved and each of the positive and negative samples to minimize the distance between the problem and the positive samples and maximize the distance between the problem and the negative samples, thus obtaining a trained mathematical word problem solving model. However, this method only constructs text samples based on the text similarity of the problems, ignoring the equation information corresponding to the problems. The lack of equation samples, which are the core of mathematical word problems, can more accurately describe the quantitative and logical relationships within the problems. Therefore, the current technology, which only focuses on analogy learning between text samples and ignores analogy learning between equation samples during model training, will lead to deviations in the model during problem solving, affecting the accuracy and reliability of the solutions.
[0004] In summary, existing methods for solving mathematical word problems only focus on analogical learning between text samples during the model training phase, neglecting analogical learning between equation samples, resulting in low accuracy and reliability of the final solution model. Summary of the Invention
[0005] Therefore, the technical problem to be solved by the present invention is to overcome the problem that the existing mathematical application problem solving methods only focus on analogical learning between text samples during the model training stage, ignoring the analogical learning of equation samples, resulting in low accuracy and reliability of the final solution model.
[0006] To solve the above-mentioned technical problems, the present invention provides a method for solving mathematical word problems, including:
[0007] Obtain the text and equations of training samples of mathematical word problems, including positive and negative text samples of training samples of mathematical word problems, and positive and negative equation samples of training samples of mathematical word problems.
[0008] The text encoder extracts the feature vectors of the text, positive text samples, and negative text samples of the training samples of mathematical word problems. Based on the analogy scores of the text feature vectors of the training samples of mathematical word problems and the feature vectors of the positive text samples, as well as the analogy scores of the text feature vectors of the training samples of mathematical word problems and the feature vectors of the negative text samples, the text loss function of the text encoder is constructed.
[0009] The equation encoder extracts the feature vectors of the equation, positive equation sample, and negative equation sample of the training samples of mathematical word problems. Based on the analogy scores of the feature vectors of the equation of the training samples of mathematical word problems and the feature vectors of the positive equation sample, as well as the analogy scores of the feature vectors of the equation of the training samples of mathematical word problems and the feature vectors of the negative equation sample, the equation loss function of the equation encoder is constructed.
[0010] Based on the text loss function of the text encoder and the equation loss function of the equation encoder, the target loss function of the text encoder is constructed. The text encoder is iteratively trained until the value of the target loss function of the text encoder is minimized, and the trained text encoder is obtained. The trained text encoder is used as the target encoder of the mathematical word problem solving model.
[0011] Preferably, the process of obtaining positive and negative equation samples from the mathematical word problem training samples includes:
[0012] If the equations in the math word problem training samples contain addition and / or multiplication and subtraction and / or division operators, then randomly swap the positions of the numbers on both sides of the addition and / or multiplication operators in the equation, and use the equation after each swap as a positive sample; randomly swap the positions of the subtrahend and minuend and / or the divisor and dividend in the equation, and use the equation after each swap as a negative sample.
[0013] If the equations in the math word problem training samples contain only addition and / or multiplication operators, then randomly swap the positions of the numbers on both sides of the addition and / or multiplication operators in the equation, and use the equation after each swap as a positive sample; randomly replace the addition and / or multiplication operators in the equation, and use the equation after each replacement as a negative sample.
[0014] If the equations in the training samples of mathematical word problems only contain subtraction and / or division, then the equation itself is taken as a positive sample; the positions of the subtrahend and minuend and / or divisor and dividend in the equation are randomly swapped, and the equation after each swap is taken as a negative sample.
[0015] Preferably, the process of obtaining positive and negative text samples for mathematical word problem training includes:
[0016] The text of the training samples of mathematical word problems and the text of each word problem in the mathematical word problem database are respectively input into the word2vec model, and the output is the sentence vector of the training samples of mathematical word problems and the sentence vector of each word problem in the mathematical word problem database.
[0017] Calculate the cosine similarity between the sentence vectors of the training samples of mathematical word problems and the sentence vectors of each word problem in the mathematical word problem database;
[0018] The texts of the N word problems with the highest cosine similarity are used as positive text samples, and the texts of the M word problems with the lowest cosine similarity are used as negative text samples.
[0019] Preferably, the formula for calculating the cosine similarity between the sentence vectors of the math word problem training samples and the sentence vectors of each word problem in the math word problem database is as follows:
[0020]
[0021] Among them, similarity i Let f(X) represent the cosine similarity between the sentence vector of the training sample of math word problems and the sentence vector of the i-th word problem in the math word problem database. i Let f(X) represent the sentence vector of the i-th word problem in the math word problem database, and let ||f(X)|| represent the magnitude of the sentence vectors of the training samples of math word problems. i )‖ represents the magnitude of the sentence vector of the i-th application problem in the math application problem database, and θ represents the angle between the sentence vector of the training sample of math application problems and the sentence vector of the i-th application problem in the math application problem database.
[0022] Preferably, after taking the texts of the N word problems with the highest cosine similarity as positive text samples, the method further includes:
[0023] Step 1: Using the tree-based top node decomposition algorithm, generate an expression binary tree for the training samples of mathematical word problems and an expression binary tree for each positive text sample based on the text of the training samples of mathematical word problems and each positive text sample. Obtain a set of binary trees based on the expression binary trees of all positive text samples.
[0024] Step 2: Initialize l = 1;
[0025] Step 3: Determine whether the l-th level node of each expression binary tree in the binary tree set is the same as the l-th level node of the expression binary tree of the math word problem training sample. Remove the expression binary trees whose l-th level nodes are different from those of the expression binary trees of the math word problem training sample from the binary tree set to obtain a new binary tree set. Update l = l + 1 and return to execute Step 3 until l equals the preset tree depth. Obtain the binary tree set when l equals the preset tree depth. Use the text positive samples corresponding to the expression binary trees in the binary tree set as the new text positive samples.
[0026] Preferably, the formula for calculating the analogy score between the text feature vector of the mathematical word problem training sample and the feature vector of the positive text sample is as follows:
[0027] s tn =W2(ReLU(W1*[En t (X):En t (X n )])),
[0028] Among them, s tn ReLU represents the analogy score between the text feature vector of the training sample of the math word problem and the feature vector of the nth positive text sample, and En represents the activation function. t En represents a text encoder. t (X) represents the text feature vector of the training samples of mathematical word problems, En t (X n ) represents the feature vector of the nth positive text sample, W1 and W2 represent trainable parameter matrices, n∈[1,N], and N represents the number of positive text samples;
[0029] The formula for calculating the analogy score between the feature vectors of the text feature vectors of the training samples of mathematical word problems and the feature vectors of the text negative samples is as follows:
[0030] s tm =W2(ReLU(W1*[En t (X):En t (X m )])),
[0031] Among them, s tm En represents the analogy score between the text feature vector of the training sample of a mathematical word problem and the feature vector of the m-th negative text sample. t (X m ) represents the feature vector of the m-th negative text sample, where m∈[1,M] and M represents the number of negative text samples;
[0032] The text loss function of the text encoder is:
[0033]
[0034] Among them, L t This represents the text loss function of the text encoder.
[0035] Preferably, the formula for calculating the analogy score between the feature vectors of the equations in the training samples of mathematical word problems and the feature vectors of the positive equation samples is as follows:
[0036] s ej =W4(ReLU(W3*[En e (e):En e (e j )])),
[0037] Among them, s ej ReLU represents the analogy score between the feature vectors of the equations in the training samples of mathematical word problems and the feature vectors of the positive samples of the j-th equation. En represents the activation function. e En represents the equation encoder. e (e) represents the feature vector of the equation in the training samples of mathematical word problems, En e (e j W1 represents the feature vector of the positive sample of the j-th equation, W2 and W3 represent the trainable parameter matrices, j∈[1,J], and J represents the number of positive samples of the equation;
[0038] The formula for calculating the equation feature vector of the training samples of mathematical word problems and the analogy score of the negative samples of the equation is as follows:
[0039] s ek =W4(ReLU(W3*[En e (e):En e (e k )])),
[0040] Among them, s ek En represents the analogy score between the feature vectors of the equations in the training samples of mathematical word problems and the feature vectors of the negative samples of the k-th equation. e (e k ) represents the feature vector of the k-th negative sample of the equation, k∈[1,K], where K represents the number of negative samples of the equation;
[0041] The equation loss function of the equation encoder is:
[0042]
[0043] Among them, L e This represents the equation loss function of the equation encoder.
[0044] Preferably, the target loss function of the text encoder is:
[0045] L=λ1Lt +λ2L e ,
[0046] Where L represents the target loss function of the text encoder, λ1 represents the weights of the text loss function of the text encoder, and L t Let λ represent the text loss function of the text encoder, λ² represent the weights of the equation loss function of the equation encoder, and L represent the weights of L. e This represents the equation loss function of the equation encoder.
[0047] The present invention also provides a mathematical word problem solving device, comprising:
[0048] The data acquisition module is used to acquire the text and equations of training samples of mathematical word problems, positive and negative text samples of training samples of mathematical word problems, and positive and negative equation samples of training samples of mathematical word problems.
[0049] The text loss function construction module is used to extract the feature vectors of the text, positive text samples, and negative text samples of the training samples of mathematical word problems using the text encoder. Based on the analogy scores of the text feature vectors of the training samples of mathematical word problems and the feature vectors of the positive text samples, as well as the analogy scores of the text feature vectors of the training samples of mathematical word problems and the feature vectors of the negative text samples, the text loss function of the text encoder is constructed.
[0050] The equation loss function construction module is used to extract the feature vectors of the equation, positive equation sample, and negative equation sample of the training samples of mathematical word problems using the equation encoder. Based on the analogy score between the feature vector of the equation of the training samples of mathematical word problems and the feature vector of the positive equation sample, and the analogy score between the feature vector of the equation of the training samples of mathematical word problems and the feature vector of the negative equation sample, the equation loss function of the equation encoder is constructed.
[0051] The target encoder acquisition module is used to construct the target loss function of the text encoder based on the text loss function of the text encoder and the equation loss function of the equation encoder, to iteratively train the text encoder until the value of the target loss function of the text encoder is minimized, and to obtain the trained text encoder. The trained text encoder is then used as the target encoder of the mathematical word problem solving model.
[0052] 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 above-described method for solving mathematical word problems.
[0053] The mathematical word problem solving method provided in this application obtains the text and equations of training samples of mathematical word problems, as well as positive text samples, negative text samples, positive equation samples, and negative equation samples of the training samples. It constructs a text loss function by analogy learning between the text of the training samples and the positive and negative text samples; it constructs an equation loss function by analogy learning between the equations of the training samples and the positive and negative equation samples; and it constructs a mathematical word problem solving loss function based on the text loss function and the equation loss function, for iterative training of the text encoder. Since the equations of word problems better reflect the quantitative and logical relationships inherent in the problem text, this application not only focuses on analogy learning between text samples but also considers analogy learning between equation samples during the training process. This allows the trained text encoder to more fully extract the quantitative and logical relationships contained in the word problem text, improving the accuracy of the features extracted by the text encoder, thereby making the solutions output by the mathematical word problem solving model have higher precision and reliability. Attached Figure Description
[0054] To make the content of this invention easier to understand, the invention will be further described in detail below with reference to specific embodiments and accompanying drawings, wherein:
[0055] Figure 1 The flowchart of the mathematical application problem-solving method provided in this application;
[0056] Figure 2 A schematic diagram illustrating the principle of the mathematical application problem-solving method provided in this application;
[0057] Figure 3 A schematic diagram of positive text samples for training samples of mathematical word problems obtained based on cosine similarity filtering provided in this application;
[0058] Figure 4 A schematic diagram of positive text samples for training mathematical application problems obtained based on the top node filtering of a tree, as provided in this application;
[0059] Figure 5 A visual illustration of encoding mathematical word problem text using encoders from different models, provided for this application; wherein, Figure 5 (a) in the image is a visualization of how the encoder in the GTS model encodes the text of math word problems in the Math23K dataset. Figure 5 (b) in the figure is a visualization of how the encoder in the GTS+MWP-AL model encodes the text of mathematical word problems in the Math23K dataset;
[0060] Figure 6A schematic diagram illustrating the impact of different sample sizes provided in this application on model performance; wherein, Figure 6 (a) in the figure illustrates the impact of changing the number of samples on the MathQA dataset on model performance. Figure 6 (b) in the figure illustrates the impact of changing the number of samples on model performance on the Math23K dataset;
[0061] Figure 7 A schematic diagram of the mathematical application problem solving device provided in this application. Detailed Implementation
[0062] The present invention will be further described below with reference to the accompanying drawings and specific embodiments, so that those skilled in the art can better understand and implement the present invention. However, the embodiments described are not intended to limit the present invention.
[0063] Please see Figure 1 , Figure 1 The diagram shown is a flowchart of the mathematical application problem-solving method provided in this application. The method specifically includes:
[0064] S10: Obtain the text and equations of the training samples of mathematical word problems, positive and negative text samples of the training samples of mathematical word problems, and positive and negative equation samples of the training samples of mathematical word problems.
[0065] S20: Use a text encoder to extract the feature vectors of the text, positive text samples, and negative text samples of the training samples of mathematical word problems respectively. Based on the analogy scores of the text feature vectors of the training samples of mathematical word problems and the feature vectors of the positive text samples, as well as the analogy scores of the text feature vectors of the training samples of mathematical word problems and the feature vectors of the negative text samples, construct the text loss function of the text encoder.
[0066] S30: Use the equation encoder to extract the feature vectors of the equation, positive equation sample, and negative equation sample of the mathematical word problem training samples respectively. Based on the analogy score between the feature vector of the equation of the mathematical word problem training samples and the feature vector of the positive equation sample, and the analogy score between the feature vector of the equation of the mathematical word problem training samples and the feature vector of the negative equation sample, construct the equation loss function of the equation encoder.
[0067] Specifically, the equation encoder in this application is a trained equation encoder;
[0068] S40: Construct the target loss function of the text encoder based on the text loss function of the text encoder and the equation loss function of the equation encoder. Iterate the text encoder until the value of the target loss function of the text encoder is minimized to obtain the trained text encoder. Use the trained text encoder as the target encoder of the mathematical word problem solving model.
[0069] The mathematical word problem solving method provided in this application obtains the text and equations of training samples of mathematical word problems, as well as positive text samples, negative text samples, positive equation samples, and negative equation samples of the training samples. It constructs a text loss function by analogy learning between the text of the training samples and the positive and negative text samples; it constructs an equation loss function by analogy learning between the equations of the training samples and the positive and negative equation samples; and it constructs a mathematical word problem solving loss function based on the text loss function and the equation loss function, for iterative training of the text encoder. Since the equations of word problems better reflect the quantitative and logical relationships inherent in the problem text, this application not only focuses on analogy learning between text samples but also considers analogy learning between equation samples during the training process. This allows the trained text encoder to more fully extract the quantitative and logical relationships contained in the word problem text, improving the accuracy of the features extracted by the text encoder, thereby making the solutions output by the mathematical word problem solving model have higher precision and reliability.
[0070] like Figure 2 The diagram shown illustrates the principle of the mathematical word problem solving method provided in this application. Figure 3 The image shows a schematic diagram of positive text samples from training samples of mathematical word problems obtained based on cosine similarity filtering. Figure 4 This is a schematic diagram of positive text samples for training mathematical application problems obtained based on the top node filtering of a tree solution.
[0071] In mathematical word problem databases, problems with similar textual semantics are also very likely to have similar equation-solving structures, such as... Figure 3 In the case of the road planting problem, the keywords in the problem matched by cosine similarity are basically similar, and the equations of some samples are basically the same. Therefore, this application uses cosine similarity to filter positive and negative samples of text.
[0072] Specifically, the process of obtaining positive and negative text samples of the mathematical word problem training samples in step S10 includes:
[0073] The text of the training samples of mathematical word problems and the text of each word problem in the mathematical word problem database are respectively input into the word2vec model, and the output is the sentence vector of the training samples of mathematical word problems and the sentence vector of each word problem in the mathematical word problem database.
[0074] Specifically, the word2vec model can transform words in a text into dense word vectors, and the sentence vectors of the text can be obtained by averaging the word vectors.
[0075] Calculate the cosine similarity between the sentence vectors of the training samples of mathematical word problems and the sentence vectors of each word problem in the mathematical word problem database;
[0076] The texts of the N word problems with the highest cosine similarity are used as positive text samples, and the texts of the M word problems with the lowest cosine similarity are used as negative text samples.
[0077] Specifically, the formula for calculating the cosine similarity between the sentence vectors of the math word problem training samples and the sentence vectors of each word problem in the math word problem database is as follows:
[0078]
[0079] Among them, similarity i Let f(X) represent the cosine similarity between the sentence vector of the training sample of math word problems and the sentence vector of the i-th word problem in the math word problem database. i Let f(X) represent the sentence vector of the i-th word problem in the math word problem database, and let ||f(X)|| represent the magnitude of the sentence vectors of the training samples of math word problems. i )‖ represents the magnitude of the sentence vector of the i-th application problem in the math application problem database, and θ represents the angle between the sentence vector of the training sample of math application problems and the sentence vector of the i-th application problem in the math application problem database.
[0080] Furthermore, from Figure 3 As can be seen, although it is also a problem of planting trees on roads, the logic of Sample 2 is different from other problems. It requires the solution to be the length of the road rather than the number of trees. Therefore, Sample 2 is different from the original problem in the structure of the solution equation and is not suitable as a positive text sample. Based on this, after selecting positive text samples based on cosine similarity, this application also adds a method to select positive text samples based on the top node of the tree solution.
[0081] The logic of a mathematical equation is closely related to its top node (i.e., the operator), such as... Figure 4As shown, problems 1 and 2, selected based on the tree decoding top node, are not very similar in terms of keywords, but they are highly consistent in logic, both solving the problem of finding the difference between one object and another multiple of that object. Since the tree decoder decodes from top to bottom, the nodes near the top (root node) reflect the final goal more. Therefore, it can be seen from the tree decoding that problems 1 and 2 have the same top node, meaning they have the same problem-solving approach. However, due to semantic dissimilarity, samples with the same top node but relatively more complex, such as problem 3, might also be selected. To address this issue, this application further filters based on semantic similarity using the tree decoding top node, significantly narrowing the selection range of positive text samples and enabling the selection of higher-quality positive text samples, such as... Figure 3 As shown, samples 3 and 4 are not only semantically similar, but also highly similar in equation structure. Although sample 1 has the same top nodes as the training samples of mathematical word problems, its complexity is much higher than that of the training samples of mathematical word problems. If sample 1 is used as a positive text sample for analogical learning, it may mislead the decoder of the mathematical word problem solving model to generate incorrect expressions.
[0082] Since the samples selected based on the top node of the tree are insufficient in terms of logical constraints, and the tree depth is closely related to the number of operators in the equation, we can limit the tree depth to prune redundant number nodes and operator nodes, that is, delete samples with overly complex logic, so as to retain samples that are highly consistent with the training samples of mathematical word problems in terms of both semantics and logic as positive text samples.
[0083] Specifically, after taking the texts of the N word problems with the highest cosine similarity as positive text samples, the following is also included:
[0084] Step 1: Using the tree-based top node decomposition algorithm, generate an expression binary tree for the training samples of mathematical word problems and an expression binary tree for each positive text sample based on the text of the training samples of mathematical word problems and each positive text sample. Obtain a set of binary trees based on the expression binary trees of all positive text samples.
[0085] Step 2: Initialize l = 1;
[0086] Step 3: Determine whether the l-th level node of each expression binary tree in the binary tree set is the same as the l-th level node of the expression binary tree of the math word problem training sample. Remove the expression binary trees whose l-th level nodes are different from those of the expression binary trees of the math word problem training sample from the binary tree set to obtain a new binary tree set. Update l = l + 1 and return to execute Step 3 until l equals the preset tree depth. Obtain the binary tree set when l equals the preset tree depth. Use the text positive samples corresponding to the expression binary trees in the binary tree set as the new text positive samples.
[0087] Optionally, in some embodiments of this application, when screening positive and negative samples of mathematical word problem equations, equations with high similarity to mathematical word problem training samples can be selected from the mathematical word problem database as positive samples, and equations with low similarity to mathematical word problem training samples can be selected from the mathematical word problem database as negative samples.
[0088] However, the positive and negative samples of equations obtained by filtering from the database are limited by the size of the database. Therefore, as a preferred embodiment of this application, positive and negative samples of equations can also be obtained by varying the equations of the training samples of mathematical word problems.
[0089] Specifically, the process of obtaining positive and negative equation samples for mathematical word problem training includes:
[0090] If the equations in the math word problem training samples contain addition and / or multiplication and subtraction and / or division operators, then randomly swap the positions of the numbers on both sides of the addition and / or multiplication operators in the equation, and use the equation after each swap as a positive sample; randomly swap the positions of the subtrahend and minuend and / or the divisor and dividend in the equation, and use the equation after each swap as a negative sample.
[0091] If the equations in the math word problem training samples contain only addition and / or multiplication operators, then randomly swap the positions of the numbers on both sides of the addition and / or multiplication operators in the equation, and use the equation after each swap as a positive sample; randomly replace the addition and / or multiplication operators in the equation, and use the equation after each replacement as a negative sample.
[0092] If the equations in the training samples of mathematical word problems only contain subtraction and / or division, then the equation itself is taken as a positive sample; the positions of the subtrahend and minuend and / or divisor and dividend in the equation are randomly swapped, and the equation after each swap is taken as a negative sample.
[0093] Since swapping the numbers on both sides of addition and multiplication operators does not change the result of the equation, but division and subtraction involve divisor, dividend, subtrahend, and minuend, changing the order of the numbers on both sides of addition and multiplication operators will not change the result of the equation, but changing the order of the divisor and dividend or the subtrahend and minuend will change the result of the equation.
[0094] Furthermore, after constructing positive and negative text samples and positive and negative equation samples for training, the text encoder of the mathematical word problem solving model is trained through analogy learning.
[0095] Specifically, in step S20, the formula for calculating the analogy score between the text feature vector of the mathematical word problem training sample and the feature vector of the positive text sample is as follows:
[0096] stn =W2(ReLU(W1*[En t (X):En t (X n )])),
[0097] Among them, s tn ReLU represents the analogy score between the text feature vector of the training sample of the mathematical word problem and the feature vector of the nth positive text sample. En represents the activation function. t En represents a text encoder. t (X) represents the text feature vector of the training samples of mathematical word problems, En t (X n ) represents the feature vector of the nth positive text sample, W1 and W2 represent trainable parameter matrices, n∈[1,N], and N represents the number of positive text samples;
[0098] The formula for calculating the analogy score between the feature vectors of the text feature vectors of the training samples of mathematical word problems and the feature vectors of the text negative samples is as follows:
[0099] s tm =W2(ReLU(W1*[En t (X):En t (X m )])),
[0100] Among them, s tm En represents the analogy score between the text feature vector of the training sample of a mathematical word problem and the feature vector of the m-th negative text sample. t (X m ) represents the feature vector of the m-th negative text sample, where m∈[1,M] and M represents the number of negative text samples;
[0101] The text loss function of the text encoder is:
[0102]
[0103] Among them, L t This represents the text loss function of the text encoder.
[0104] In step S30, the formula for calculating the analogy score between the feature vectors of the equations in the training samples of mathematical word problems and the feature vectors of the positive equation samples is as follows:
[0105] s ej =W4(ReLU(W3*[En e (e):En e (e j )])),
[0106] Among them, s ejReLU represents the analogy score between the feature vectors of the equations in the training samples of mathematical word problems and the feature vectors of the positive samples of the j-th equation. En represents the activation function. e En represents the equation encoder. e (e) represents the feature vector of the equation in the training samples of mathematical word problems, En e (e j W1 represents the feature vector of the positive sample of the j-th equation, W2 and W3 represent the trainable parameter matrices, j∈[1,J], and J represents the number of positive samples of the equation;
[0107] The formula for calculating the equation feature vector of the training samples of mathematical word problems and the analogy score of the negative samples of the equation is as follows:
[0108] s ek =W4(ReLU(W3*[En e (e):En e (e k )])),
[0109] Among them, s ek En represents the analogy score between the feature vectors of the equations in the training samples of mathematical word problems and the feature vectors of the negative samples of the k-th equation. e (e k ) represents the feature vector of the k-th negative sample of the equation, k∈[1,K], where K represents the number of negative samples of the equation;
[0110] The equation loss function of the equation encoder is:
[0111]
[0112] Among them, L e This represents the equation loss function of the equation encoder.
[0113] Based on the above text loss function and equation loss function, the target loss function of the text encoder is constructed as follows:
[0114] L=λ1L t +λ2L e ,
[0115] Where L represents the target loss function of the text encoder, λ1 represents the weights of the text loss function of the text encoder, and L t Let λ represent the text loss function of the text encoder, λ² represent the weights of the equation loss function of the equation encoder, and L represent the weights of L. e This represents the equation loss function of the equation encoder.
[0116] Optionally, the training process of the text encoder provided in this application can also be directly applied to mathematical word problem solving models with encoder and decoder architectures. When the training method provided in this application is applied to other mathematical word problem solving models, the objective loss function of the text encoder can also be:
[0117] L = L a +λ1L t +λ2L e ,
[0118] Among them, L a This represents the loss function used by the model itself, which has an encoder and decoder architecture, to train the encoder.
[0119] To demonstrate the effectiveness of the mathematical word problem solving method provided in this application, the embodiments of this application have also been validated on different datasets using various baseline models:
[0120] The datasets used in this application are the English dataset MathQA and the Chinese dataset Math23K. MathQA contains 23,369 English math word problems, and Math23K contains 23,162 Chinese math word problems. The statistical data of the datasets are shown in Table 1.
[0121] Table 1
[0122] Dataset MathQA Math23K Dataset size 23369 23161 Operators {+,-,*, / } {+,-,*, / ,^} Average text length 38.7 28.0 Average expression length 10.4 5.6
[0123] This application embodiment selects GTS and MWP-BERT models with encoder-decoder architectures, and trains the encoder based on these models using the methods provided in this application. Specifically, the baseline models selected in this application embodiment include:
[0124] 1. GTS is the first to use a sequence-to-sequence model based on neural networks to handle the task of generating expressions. The encoder uses GRU and the decoder uses LSTM.
[0125] 2. GTS-teacher: By designing a teacher module, the MWP encoding vector is matched with the correct solution and not with the incorrect solution, and operations are performed from the correct solution.
[0126] 3. Graph2Tree uses a BiLSTM encoder and a tree decoder proposed by GTS as the decoder, and uses a graph neural network to add a digital unit graph and a value greater than the graph to enhance the numerical representation in the text.
[0127] 4. DCTE-GTS is a dual-channel text encoder based on recurrent neural networks and Transformer coding networks to obtain long-distance contextual semantic information of words, thereby enhancing the semantic representation of words and text.
[0128] 5. MGNet is an encoder structure based on multi-granularity word segmentation and graph convolutional networks. It improves task performance by utilizing multi-granularity word segmentation and using graph encoders to mine the implicit relationships between quantity and attributes in the text.
[0129] 6. REAL, a human-like analogy learning method based on memory and learning, proposes a framework consisting of a memory module, a representation module, an analogy module, and a reasoning module.
[0130] 7. Generate & Rank: A multi-task framework based on generative pre-trained language models. Through joint training of generation and ranking, the model learns from its own mistakes and can distinguish between correct and incorrect expressions.
[0131] 8. BERT-CL proposes a contrastive learning method in which the divergence of neural network perception patterns is collected by converting prototype equations into trees and searching for similar tree structures to gather contrastive examples.
[0132] 9. MWP-BERT, a dedicated PLM model for MWP with 8 pre-training objectives, proposes an incremental pre-training task that considers inference logic and numerical properties, and can access different levels of supervision signals.
[0133] 10. Deductive Reasoner proposed interpretable deductive reasoning steps to iteratively construct a target expression, where each step involves basic operations on two quantities.
[0134] In this embodiment, the word embedding dimension is 128, the hidden layer dimension is 512, and the batch size is 32 in the GTS encoder training. In the MWP-BERT encoder training, the word embedding dimension is 128, the hidden layer dimension is 768, and the batch size is 32. Based on the GTS and MWP-BERT solvers, Adam optimizers with initial learning rates of 0.001 and 0.00005 are used respectively. The learning rate decays to 0.5 times the original rate after every 30 epochs. The solver is trained for 180 epochs. In the encoder's objective loss function, λ1 = 0.01, λ2 = 0.001, and the beam search size is 5.
[0135] The expression generated by the tree decoder is used to perform arithmetic operations to obtain the answer, which is then compared with the correct answers provided in the test set. Finally, the number of all correct answers is counted, and the percentage of correct answers in the test set is calculated, which is denoted as the accuracy (ACC).
[0136]
[0137] Where N CN represents the number of questions with correct answers in a test. t This represents the total number of items in the test set.
[0138] Table 2 shows the test results of different baseline models on different datasets:
[0139] Table 2
[0140]
[0141]
[0142] As shown in Table 2, based on the method provided in this application, the accuracies of GTS and MWP-BERT on the MathQA dataset are 69.8% and 79.7%, respectively, representing improvements of 1.8% and 2.5% compared to the original models. On the Math23K dataset, the accuracies of GTS and MWP-BERT are 78.4% and 85.9%, respectively, representing improvements of 2.8% and 1.3% compared to the original models. Furthermore, implementing the method provided in this application on both the GTS and MWP-BERT models improves the accuracy compared to other baseline models.
[0143] Table 3 shows the accuracy of the mathematical word problem solving model trained on the dataset after removing the text sample analogy learning (w / o Text) or equation sample analogy learning (w / o Equation) provided in this application:
[0144] Table 3
[0145]
[0146] As can be seen from the data in Table 3, the accuracy of the model decreased after removing the text sample analogy learning, indicating that the text sample selection method provided in this application obtains positive text samples with a higher degree of matching with the original questions, which is beneficial to training. Meanwhile, removing the equation sample analogy learning also has a negative impact on the model, indicating a connection between equation analogy learning and text encoding training. Furthermore, the embodiments of this application also visualized the sample distance on the models in these ablation experiments, allowing for a direct comparison of the distance between the vectors generated by each model in the two-dimensional plane. The encoders in the GTS and GTS+MWP-AL models were used to encode the mathematical word problem text in the Math23K dataset, generating 512-dimensional vectors, which were then visualized using Radviz radar charts, as shown below. Figure 5As shown in (a) and (b) in the figure, it can be seen from the figure that, compared with the GTS model, the original anchor vector (anchor) encoded by the GTS+MWP-AL model is closer to the positive sample (pos) and farther away from the negative sample (neg) on the plane. At the same time, the division between positive and negative samples is also more obvious, which fully demonstrates the effectiveness of the text sample screening method and analogy learning provided in this application.
[0147] Furthermore, this application embodiment also verifies the impact of the number of selected samples on model performance. During the sample selection stage, the number of samples is set within the range of [5, 10, 15, 20]. Figure 6 As shown, the model performs best on both datasets when there are 10 samples, while overfitting occurs when there are too many samples.
[0148] This application also verifies the impact of equation expression length on model performance. On the Math23K dataset, expressions are classified according to the number of operators. The performance of GTS+MWP-AL is compared with that of three models using tree structure decoders: AST-Dec, GTS, and Graph2Tree. The comparison results are shown in Table 4. As can be seen from Table 4, the performance of all models shows a downward trend as the expression length increases. This is because longer expressions often correspond to more complex mathematical problems, and there are fewer training samples for these problems. In addition, the table also shows that the model obtained by the method of this application has improved accuracy compared with other baseline models when the number of operators is large (except for the case of op=2), indicating that the method provided by this application has more advantages in handling complex mathematical problems.
[0149] Table 4
[0150] Op Pro AST-Dec GTS Graph2Tree MWP-AL 1 17.4 82.7 84.9 85.5 89.1 2 52.1 74.5 80.6 83.7 82.3 3 19.1 59.9 70.7 71.7 74.3 4 6.6 42.4 50.0 51.5 56.1 5 3.4 44.1 38.2 38.2 44.1 6 0.9 55.6 44.4 55.6 55.6
[0151] Where Pro represents the percentage of application problems with different operators in the test dataset, and the Math23K test set size is 1000.
[0152] Based on the mathematical word problem solving method provided in the above embodiments, this application also provides a mathematical word problem solving device, such as... Figure 7 As shown, the device specifically includes:
[0153] The data acquisition module 10 is used to acquire the text and equations of the training samples of mathematical word problems, positive text samples and negative text samples of the training samples of mathematical word problems, and positive equation samples and negative equation samples of the training samples of mathematical word problems.
[0154] The text loss function construction module 20 is used to extract the feature vectors of the text, positive text samples and negative text samples of the training samples of mathematical word problems using the text encoder. Based on the analogy score between the text feature vector of the training samples of mathematical word problems and the feature vector of the positive text samples, and the analogy score between the text feature vector of the training samples of mathematical word problems and the feature vector of the negative text samples, the text loss function of the text encoder is constructed.
[0155] The equation loss function construction module 30 is used to extract the feature vectors of the equation, positive equation sample and negative equation sample of the mathematical word problem training sample respectively using the equation encoder. Based on the analogy score between the feature vector of the equation of the mathematical word problem training sample and the feature vector of the positive equation sample, and the analogy score between the feature vector of the equation of the mathematical word problem training sample and the feature vector of the negative equation sample, the equation loss function of the equation encoder is constructed.
[0156] The target encoder acquisition module 40 is used to construct the target loss function of the text encoder based on the text loss function of the text encoder and the equation loss function of the equation encoder, to iteratively train the text encoder until the value of the target loss function of the text encoder is minimized, and to obtain the trained text encoder. The trained text encoder is used as the target encoder of the mathematical word problem solving model.
[0157] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the above-described method for solving mathematical word problems.
[0158] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0159] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0160] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0161] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0162] Obviously, the above embodiments are merely illustrative examples for clear explanation and are not intended to limit the implementation. Those skilled in the art will recognize that other variations or modifications can be made based on the above description. It is neither necessary nor possible to exhaustively list all possible implementations here. However, obvious variations or modifications derived therefrom are still within the scope of protection of this invention.
Claims
1. A method for solving mathematical word problems, characterized in that, include: Obtain the text and equations of the training samples of mathematical word problems, including positive and negative text samples, and positive and negative equation samples. The process of obtaining the positive and negative equation samples includes: If the equations in the math word problem training samples contain addition and / or multiplication and subtraction and / or division operators, then randomly swap the positions of the numbers on both sides of the addition and / or multiplication operators in the equation, and use the equation after each swap as a positive sample; randomly swap the positions of the subtrahend and minuend and / or the divisor and dividend in the equation, and use the equation after each swap as a negative sample. If the equations in the math word problem training samples contain only addition and / or multiplication operators, then randomly swap the positions of the numbers on both sides of the addition and / or multiplication operators in the equation, and use the equation after each swap as a positive sample; randomly replace the addition and / or multiplication operators in the equation, and use the equation after each replacement as a negative sample. If the equations in the training samples of mathematical word problems only contain subtraction and / or division, then the equation itself is taken as a positive sample; the positions of the subtrahend and minuend and / or the divisor and dividend in the equation are randomly swapped, and the equation after each swap is taken as a negative sample. The process of obtaining positive and negative text samples for math word problem training includes: The text of the training samples of mathematical word problems and the text of each word problem in the mathematical word problem database are respectively input into the word2vec model, and the output is the sentence vector of the training samples of mathematical word problems and the sentence vector of each word problem in the mathematical word problem database. Calculate the cosine similarity between the sentence vectors of the training samples of mathematical word problems and the sentence vectors of each word problem in the mathematical word problem database; The texts of the N word problems with the highest cosine similarity are taken as positive text samples, and the texts of the M word problems with the lowest cosine similarity are taken as negative text samples. The text encoder extracts the feature vectors of the text, positive text samples, and negative text samples of the training samples of mathematical word problems. Based on the analogy scores of the text feature vectors of the training samples of mathematical word problems and the feature vectors of the positive text samples, as well as the analogy scores of the text feature vectors of the training samples of mathematical word problems and the feature vectors of the negative text samples, the text loss function of the text encoder is constructed. The equation encoder extracts the feature vectors of the equation, positive equation sample, and negative equation sample of the training samples of mathematical word problems. Based on the analogy scores of the feature vectors of the equation of the training samples of mathematical word problems and the feature vectors of the positive equation sample, as well as the analogy scores of the feature vectors of the equation of the training samples of mathematical word problems and the feature vectors of the negative equation sample, the equation loss function of the equation encoder is constructed. Based on the text loss function of the text encoder and the equation loss function of the equation encoder, the target loss function of the text encoder is constructed. The text encoder is iteratively trained until the value of the target loss function of the text encoder is minimized, and the trained text encoder is obtained. The trained text encoder is used as the target encoder of the mathematical word problem solving model.
2. The method for solving mathematical word problems according to claim 1, characterized in that, The formula for calculating the cosine similarity between the sentence vectors of the math word problem training samples and the sentence vectors of each word problem in the math word problem database is as follows: , in, The sentence vectors representing training samples of math word problems and the first sentence in the math word problem database. Cosine similarity between sentence vectors of a word problem The sentence vectors representing training samples of mathematical word problems. This represents the first number in the mathematical word problem database. Sentence vectors for a word problem The magnitude of the sentence vectors representing training samples of mathematical word problems. This represents the first number in the mathematical word problem database. The modulus of the sentence vector of a word problem. The sentence vectors representing training samples of math word problems and the first sentence in the math word problem database. The angle between the sentence vectors of the word problem.
3. The method for solving mathematical word problems according to claim 1, characterized in that, After taking the texts of the N word problems with the highest cosine similarity as positive text samples, the following is also included: Step 1: Using the tree-based top node decomposition algorithm, generate an expression binary tree for the training samples of mathematical word problems and an expression binary tree for each positive text sample based on the text of the training samples of mathematical word problems and each positive text sample. Obtain a set of binary trees based on the expression binary trees of all positive text samples. Step 2: Initialization ; Step 3: Determine the first position of each expression binary tree in the binary tree set. Are the layer nodes related to the expression of the binary tree in the training samples of mathematical word problems? The same layer nodes, will the first The expression of the layer nodes and mathematical word problem training samples in the binary tree Binary trees with different expressions at each level are removed from the binary tree set, resulting in a new binary tree set, which is then updated. And return to step 3 until... Equal to the preset tree depth, obtain Given a set of binary trees of the same depth as the preset tree, take the positive text samples corresponding to the expression binary trees in the set as the new positive text samples.
4. The method for solving mathematical word problems according to claim 1, characterized in that, The formula for calculating the analogy score between the feature vectors of the training samples of mathematical word problems and the feature vectors of the positive samples is as follows: , in, The text feature vectors of the training samples of mathematical word problems are related to the first... The analogy score of the feature vectors of a positive text sample. This represents the activation function. Indicates a text encoder. The text feature vector representing the training samples of mathematical word problems. Indicates the first Feature vectors of positive text samples , Represents the trainable parameter matrix. , This indicates the number of positive samples in the text. The formula for calculating the analogy score between the feature vectors of the text feature vectors of the training samples of mathematical word problems and the feature vectors of the text negative samples is as follows: , in, The text feature vectors of the training samples of mathematical word problems are related to the first... Analogy score of the feature vectors of a negative text sample Indicates the first The feature vector of a negative text sample , This indicates the number of negative samples in the text. The text loss function of the text encoder is: , in, This represents the text loss function of the text encoder.
5. The method for solving mathematical word problems according to claim 1, characterized in that, The formula for calculating the analogy score between the eigenvectors of the equations in the training samples of mathematical word problems and the eigenvectors of the positive samples is as follows: , in, The equation eigenvectors of the training samples of mathematical word problems and the first... The analogy score of the feature vectors of the positive samples of the equation. This represents the activation function. Represents an equation encoder. The equation feature vectors representing training samples of mathematical word problems. Indicates the first The feature vectors of positive samples in the equation , Represents the trainable parameter matrix. , This represents the number of positive samples in the equation; The formula for calculating the equation feature vector of the training samples of mathematical word problems and the analogy score of the negative samples of the equation is as follows: , in, The equation eigenvectors of the training samples of mathematical word problems and the first... The analogy score of the feature vectors of the negative samples of the equation. Indicates the first The feature vectors of the negative samples of the equation , This indicates the number of negative samples in the equation; The equation loss function of the equation encoder is: , in, This represents the equation loss function of the equation encoder.
6. The method for solving mathematical word problems according to claim 1, characterized in that, The objective loss function of the text encoder is: , in, This represents the target loss function of the text encoder. The weights represent the text loss function of the text encoder. This represents the text loss function of the text encoder. The weights represent the equation loss function of the equation encoder. This represents the equation loss function of the equation encoder.
7. A device for solving mathematical word problems, characterized in that, A method for solving mathematical word problems according to any one of claims 1 to 6, comprising: The data acquisition module is used to acquire the text and equations of training samples of mathematical word problems, positive and negative text samples of training samples of mathematical word problems, and positive and negative equation samples of training samples of mathematical word problems. The text loss function construction module is used to extract the feature vectors of the text, positive text samples, and negative text samples of the training samples of mathematical word problems using the text encoder. Based on the analogy scores of the text feature vectors of the training samples of mathematical word problems and the feature vectors of the positive text samples, as well as the analogy scores of the text feature vectors of the training samples of mathematical word problems and the feature vectors of the negative text samples, the text loss function of the text encoder is constructed. The equation loss function construction module is used to extract the feature vectors of the equation, positive equation sample, and negative equation sample of the training samples of mathematical word problems using the equation encoder. Based on the analogy score between the feature vector of the equation of the training samples of mathematical word problems and the feature vector of the positive equation sample, and the analogy score between the feature vector of the equation of the training samples of mathematical word problems and the feature vector of the negative equation sample, the equation loss function of the equation encoder is constructed. The target encoder acquisition module is used to construct the target loss function of the text encoder based on the text loss function of the text encoder and the equation loss function of the equation encoder, to iteratively train the text encoder until the value of the target loss function of the text encoder is minimized, and to obtain the trained text encoder. The trained text encoder is then used as the target encoder of the mathematical word problem solving model.
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 mathematical word problem solving method according to any one of claims 1-6.
Citation Information
Patent Citations
Tree structure mathematics application question solving method and system based on semantic alignment
CN111259632A
Chinese mathematics application question data enhancement method based on reverse operation
CN113095045A
