Problem-solving model training method and device, problem-solving method and device
By combining the Bert model and the LSTM model, the problem-solving model is trained and processed for mathematical problems, which solves the problems of low problem-solving accuracy and low computational efficiency in the existing technology, and achieves efficient and accurate mathematical problem-solving.
Patent Information
- Application Number
- CN202010658157.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-09
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2040-07-09
AI Technical Summary
Existing mathematical problem-solving methods are based on rule statistics or RNN coding, which have problems such as high labor costs, low problem-solving accuracy, and low computational efficiency.
A problem-solving model training method is used to obtain the sample text to be answered, perform preprocessing, encoding and decoding, generate answers, and iteratively train the model based on the loss value. The Bert model and the LSTM model are combined to perform text and symbol word units respectively. Embeddings are processed and pre-trained encoders and decoders are fine-tuned before model training.
It improves the accuracy and efficiency of the problem-solving model, reduces labor costs, and can quickly and accurately answer mathematical problems.
Smart Images

Figure CN111783423B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method and device for training a problem-solving model, a problem-solving method and device, a computing device, and a computer-readable storage medium. Background Art
[0002] Existing math problem-solving methods are generally based on rule statistics or seq2seq methods. Among them, the rule statistics method requires pre-defining the formula template for math problem solving, then calculating the conditional probability of each template based on the statistical method, and using the template with the highest probability to solve the math problem. The seq2seq method requires building an encoder to encode the problem text and a decoder to generate the solution formula for the problem. Usually, both the encoder and the decoder are RNN structures.
[0003] However, the existing technology has some defects: the statistical method requires artificial construction of features, which has high labor costs; the method based on RNN encoding problems cannot understand the text of mathematical problems well, so the accuracy of solving problems is low. At the same time, RNN is a recursive calculation structure, and the calculation at time t depends on the information at time t-1, which cannot realize parallel calculation and has low calculation efficiency. Summary of the invention
[0004] In view of this, the embodiments of the present application provide a problem-solving model training method and device, a problem-solving method and device, a computing device and a computer-readable storage medium to solve the technical defects existing in the prior art.
[0005] Specifically, this application provides the following technical solutions:
[0006] The present application provides a training method for a problem-solving model, wherein the problem-solving model is composed of an encoder and a decoder, and comprises the following steps:
[0007] Get the sample text to be answered and the answer label;
[0008] Preprocessing the sample text to be answered to generate a target sample text;
[0009] Inputting the target sample text into the encoder of the problem-solving model for encoding to generate an encoding vector of the target sample text;
[0010] Input the encoding vector into a decoder of the problem-solving model for decoding to generate a sample answer;
[0011] Calculate the sample answer and the answer label to determine the loss value;
[0012] The problem-solving model is iteratively trained based on the loss value until a training stop condition is reached.
[0013] Optionally, for the training method, the sample text to be answered includes text word units and number word units;
[0014] The preprocessing of the sample text to be answered to generate the target sample text comprises:
[0015] Based on the position sequence of the number word units in the sample text to be answered, the number word units are replaced in the position sequence using preset symbols to generate the target sample text.
[0016] Optionally, for the training method, the encoder includes an embedding layer and a plurality of sequentially connected encoding layers;
[0017] The step of inputting the target sample text into the encoder of the problem-solving model for encoding to generate an encoding vector of the target sample text includes:
[0018] Inputting the target sample text into the embedding layer for embedding processing to obtain an embedding vector of the target sample text;
[0019] The embedding vector is input into the encoding layer for encoding in sequence to generate the encoding vector of the target sample text.
[0020] Optionally, for the training method, the embedding layer includes a first embedding layer and a second embedding layer;
[0021] The step of inputting the target sample text into the embedding layer for embedding processing to obtain an embedding vector of the target sample text includes:
[0022] Embedding the word units in the target sample text using the first embedding layer to generate a word embedding vector;
[0023] Embedding the symbol word units in the target sample text using a second embedding layer to generate a symbol embedding vector;
[0024] The embedding vector of the target sample text is obtained based on the combination of the text embedding vector and the symbol embedding vector.
[0025] Optionally, for the training method, the encoding vector includes a plurality of vector units;
[0026] Inputting the encoded vector into a decoder of the problem-solving model for decoding to generate a sample answer includes:
[0027] Performing parameter initialization processing on the decoder according to the first vector unit of the encoding vector;
[0028] Based on the decoder, each of the vector units is decoded respectively, a decoding vector corresponding to each of the vector units is output, and a sample answer is generated based on the decoding vector corresponding to each of the vector units.
[0029] Optionally, the training method further includes, before inputting the target sample text into an encoder of a problem-solving model for encoding:
[0030] Using an encoding optimizer to fine-tune the pre-trained encoder, and using a decoding optimizer to fine-tune the pre-trained decoder;
[0031] When the encoder update step number reaches a first threshold, the encoder fine-tuning stops;
[0032] When the decoder update step number reaches a second threshold, the decoder fine-tuning stops.
[0033] Optionally, for the training method, the iterative training of the problem-solving model based on the loss value until a training stop condition is reached includes:
[0034] Determine whether the loss value is less than a preset threshold;
[0035] If not, continue to obtain the sample text to be answered and the answer label for training;
[0036] If yes, stop training.
[0037] This application provides a problem-solving method, including:
[0038] Get the text to be answered;
[0039] Preprocessing the text to be answered to generate a target text;
[0040] Inputting the target text into the encoder of the problem-solving model for encoding to generate an encoding vector of the target text;
[0041] Input the encoded vector into a decoder of the problem-solving model for decoding to generate an answer;
[0042] The problem-solving model is obtained by training using the above-mentioned problem-solving model training method.
[0043] Optionally, for the method described, the text to be answered includes text word units and number word units;
[0044] The preprocessing of the text to be answered to generate the target text comprises:
[0045] Based on the position sequence of the number word units in the text to be answered, the number word units are replaced in the position sequence using preset symbols to generate the target text.
[0046] Optionally, for the method, the decoder of the problem-solving model includes an embedding layer and a plurality of sequentially connected encoding layers;
[0047] The step of inputting the target text into the encoder of the problem-solving model for encoding to generate the encoding vector of the target text comprises:
[0048] Inputting the target text into the embedding layer for embedding processing to obtain an embedding vector of the target text;
[0049] The embedding vector is input into the encoding layer for encoding in sequence to generate the encoding vector of the target text.
[0050] Optionally, for the method described, the embedding layer includes a first embedding layer and a second embedding layer;
[0051] The step of inputting the target text into the embedding layer for embedding processing to obtain an embedding vector of the target text includes:
[0052] Embedding the word units in the target text using the first embedding layer to generate a word embedding vector;
[0053] Embedding the symbol word units in the target text using a second embedding layer to generate a symbol embedding vector;
[0054] The embedding vector of the target text is obtained based on the combination of the text embedding vector and the symbol embedding vector.
[0055] Optionally, for the method described, the encoding vector includes a plurality of vector units;
[0056] Inputting the encoded vector into a decoder of the problem-solving model for decoding to generate an answer includes:
[0057] Performing parameter initialization processing on the decoder according to the first vector unit of the encoding vector;
[0058] Based on the decoder, each of the vector units is decoded respectively, a decoding vector corresponding to each of the vector units is output, and an answer is generated based on the decoding vector corresponding to each of the vector units.
[0059] The present application provides a training device for a problem-solving model, comprising:
[0060] A sample acquisition module is configured to acquire sample texts to be answered and answer labels;
[0061] A sample preprocessing module is configured to preprocess the sample text to be answered to generate a target sample text;
[0062] An encoding module is configured to input the target sample text into an encoder of a problem-solving model for encoding, and generate an encoding vector of the target sample text;
[0063] A decoding module, configured to input the encoding vector into a decoder of the problem-solving model for decoding to generate a sample answer;
[0064] A calculation module, configured to calculate the sample answer and the answer label to determine a loss value;
[0065] The iterative training module is configured to iteratively train the problem-solving model based on the loss value until a training stop condition is reached.
[0066] The present application provides a problem-solving device, comprising:
[0067] An acquisition module is configured to acquire the text to be answered;
[0068] A text preprocessing module is configured to preprocess the text to be answered to generate a target text;
[0069] An encoding module, configured to input the target text into an encoder of a problem-solving model for encoding, and generate an encoding vector of the target text;
[0070] The decoding module is configured to input the encoding vector into the decoder of the problem-solving model for decoding to generate an answer.
[0071] A computing device comprises a memory, a processor and computer instructions stored in the memory and executable on the processor, wherein when the processor executes the instructions, the training method of the aforementioned problem-solving model or the steps of the problem-solving method are implemented.
[0072] A computer-readable storage medium storing computer instructions, characterized in that when the instructions are executed by a processor, the training method of the aforementioned problem-solving model or the steps of the problem-solving method are implemented.
[0073] The training method and device of the problem-solving model provided in the present application are based on a preprocessing operation of replacing digital word units with symbols on the text to be answered. When performing an embedded coding model, two different embedding layers, the first and the second, are used to embed text vectors and symbol vectors respectively, which can increase the accuracy of the model during the training process.
[0074] In addition, the training method and device of the problem-solving model provided in the application are based on the pre-trained encoder and decoder used in the model training process. Before encoding and decoding, the pre-trained encoder and decoder need to be fine-tuned using optimizers with different initial learning rates. The pre-trained encoder and decoder that are directly used can be further optimized. In addition, the use of optimizers with different initial learning rates for encoders and decoders with different functions can avoid the defect of using one optimizer to pre-train the entire model and fail to achieve the optimal effect, thereby improving the accuracy of the entire problem-solving model.
[0075] In addition, the problem-solving method and device provided by the present application input the text to be answered into the problem-solving model for processing, and determine the answer to the text to be answered, which can effectively improve the accuracy of problem solving. For example, when the problem-solving model described in the present application performs the task of solving elementary school mathematics problems, the problem-solving method provided by the present application can be applied. The model can automatically output the solution formula of the problem by inputting the text of the mathematics application problem through understanding the numerical information related to the problem in the question stem, wherein the problem-solving method can complete the understanding of the mathematics problem and obtain the solution result quickly and accurately. BRIEF DESCRIPTION OF THE DRAWINGS
[0076] Figure 1 is a schematic diagram of the structure of a computing device according to an embodiment of the present application;
[0077] Figure 2 It is a flowchart of a problem-solving model training method according to an embodiment of the present application;
[0078] Figure 3 It is a structural schematic diagram of the model used in the problem-solving model training method described in one embodiment of the present application;
[0079] Figure 4 A schematic diagram of the structure of a problem-solving model embedding layer used in the problem-solving model training method described in an embodiment of the present application;
[0080] Figure 5 This is a schematic diagram of decoding in a decoder provided in an embodiment of the present application;
[0081] Figure 6 It is a flowchart of a problem-solving method provided by an embodiment of the present application;
[0082] Figure 7 It is a structural schematic diagram of a problem-solving model training device provided in one embodiment of the present application;
[0083] Figure 8 It is a schematic diagram of the structure of a problem-solving device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0084] Many specific details are described in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present application, so the present application is not limited by the specific implementation disclosed below.
[0085] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0086] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0087] First, the terms involved in one or more embodiments of the present invention are explained.
[0088] Bert model: a bidirectional attention neural network model. The Bert model can predict the current word through the left and right contexts and predict the next sentence through the current sentence. The goal of the Bert model is to use large-scale unlabeled corpus training to obtain the semantic representation of text containing rich semantic information, and then fine-tune the semantic representation of the text in a specific NLP task, and finally apply it to the NLP task.
[0089] Long Short-Term Memory (LSTM) model: a time recurrent neural network suitable for processing and predicting important events with relatively long intervals and delays in time series. The LSTM model can be used to connect previous information to the current task, such as using past sentences to infer the understanding of the current sentence.
[0090] Token: Before any actual processing is done on the input text, it needs to be segmented into language units such as characters, punctuation marks, numbers or letters. These units are called tokens. For English text, a token can be a word, a punctuation mark, a number, etc. For Chinese text, the smallest token can be a character, a punctuation mark, a number, etc.
[0091] Word embedding: It means embedding a high-dimensional space with the dimension of all words into a continuous vector space with much lower dimension, where each word or phrase is mapped to a vector in the real number field.
[0092] word2vec: is a group of related models used to generate word vectors. These models are shallow, two-layer neural networks that are trained to reconstruct linguistic word text. The network is represented by words and needs to guess the input words in adjacent positions. Under the bag-of-words model assumption in word2vec, the order of words is not important. After training, the word2vec model can be used to map each word to a vector that can be used to represent the relationship between words. The vector is the hidden layer of the neural network.
[0093] Transformer model: It is essentially an encoder-decoder structure. The encoder is composed of 6 encoding layers connected in sequence, and the decoder is composed of 6 decoding layers connected in sequence. Like all generative models, the encoder receives the original input text and outputs the encoding vector to the decoder. The decoder generates the decoding vector and obtains the final output text.
[0094] Encoder: Converts the sentence to be translated from text into an encoded vector.
[0095] Decoder: Generates a decoded vector from the encoded vector and converts the decoded vector into the answer.
[0096] Mapping: In mathematics, mapping refers to the "corresponding" relationship between two sets of elements. It is necessary to predefine the function of the projection rule before performing the operation. In this application, mapping refers to using a predefined algorithm to replace the numbers contained in the text in the input model with symbols, such as d1, d2, etc.
[0097] In the present application, a training method and apparatus for a problem-solving model, a problem-solving method and apparatus, a computing device and a computer-readable storage medium are provided, which are described in detail one by one in the following embodiments.
[0098] Figure 11 is a block diagram showing a structure of a computing device 100 according to an embodiment of the present specification. The components of the computing device 100 include but are not limited to a memory 110 and a processor 120. The processor 120 is connected to the memory 110 via a bus 130, and a database 150 is used to store data.
[0099] The computing device 100 also includes an access device 140 that enables the computing device 100 to communicate via one or more networks 160. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 140 may include one or more of any type of network interface (e.g., a network interface card (NIC)) whether wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a World Wide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.
[0100] In one embodiment of the present specification, the above components of the computing device 100 and Figure 1 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 1 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.
[0101] The computing device 100 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or PC. The computing device 100 may also be a mobile or stationary server.
[0102] The processor 120 may execute Figure 2 Steps in the method shown. Figure 2 It is a schematic flowchart showing a method for training a problem-solving model according to an embodiment of the present application, including steps S201 to S206.
[0103] S201, obtaining sample text to be answered and answer labels.
[0104] Among them, the sample text to be answered is a sample text used to train the problem-solving model. The sample text to be answered should include a stem text part and a question text part, and the stem text part in the sample text to be answered must include both text and numbers.
[0105] In this application, the sample texts to be answered are in batches, and the sample texts to be answered in the same batch are input together into the problem-solving model for processing; each sample text to be answered includes multiple sub-samples, each sub-sample includes a complete math problem information, and there is no limit on the number of words in each sub-sample.
[0106] The answer label includes the correct answer corresponding to the sample text to be answered. The correct answer is usually in the form of a solution formula composed of numbers contained in the sample text to be answered. For example, if the sample text to be answered is "There are 6 apples divided equally among 3 children, how many apples does each child have", then the corresponding answer label is "6 / 3".
[0107] S202: pre-process the sample text to be answered to generate a target sample text.
[0108] In the present application, since the sample text to be answered contains text word units and numeric word units, and the numerical values, number of digits and order of digits contained in different sample texts to be answered are different, the sample text to be answered needs to be preprocessed in the problem-solving training model provided in the present application.
[0109] In this application, the sample text to be answered is preprocessed to generate the target sample text, including:
[0110] Based on the position sequence of the number word units in the sample text to be answered, the number word units are replaced in the position sequence using preset symbols to generate the target sample text.
[0111] In this application, the sample text to be answered is preprocessed and the numeric word units therein are replaced with symbols, which can effectively improve the accuracy of the subsequent training problem-solving model and reduce the errors caused by the differences in numeric word units in different sample texts to be answered.
[0112] S203: Input the target sample text into the encoder of the problem-solving model for encoding to generate an encoding vector of the target sample text.
[0113] In the present application, the encoder used in the problem-solving model for training includes an embedding layer and multiple sequentially connected encoding layers.
[0114] In a specific implementation of the present application, the encoder used by the problem-solving model is a Bert model.
[0115] Furthermore, the step of inputting the target sample text into an encoder of a problem-solving model for encoding to generate an encoding vector of the target sample text includes:
[0116] Inputting the target sample text into the embedding layer for embedding processing to obtain an embedding vector of the target sample text;
[0117] The embedding vector is input into the encoding layer for encoding in sequence to generate the encoding vector of the target sample text.
[0118] Since the numbers in the sample text to be answered are replaced by symbols in the above operation, many related words {d1, ..., d m}, these symbols do not exist in the pre-trained Bert. Therefore, in order to improve the accuracy of the model and strengthen the model's understanding of the target sample text, this application uses the trained word2vec model to further expand the embedding layer of the Bert model, that is, for {d1, ..., d m The symbol word unit of} is represented by word2vec vector, while other text word units are represented by the embedding vector of the original Bert model.
[0119] Specifically, corresponding to the text word unit and the symbol word unit, the embedding layer of the encoder in the present application includes a first embedding layer and a second embedding layer.
[0120] Specifically, the step of inputting the target sample text into the embedding layer for embedding processing to obtain an embedding vector of the target sample text includes:
[0121] Embedding the word units in the target sample text using the first embedding layer to generate a word embedding vector;
[0122] Embedding the symbol word units in the target sample text using a second embedding layer to generate a symbol embedding vector;
[0123] The embedding vector of the target sample text is obtained based on the combination of the text embedding vector and the symbol embedding vector.
[0124] like Figure 4As shown, the first embedding layer uses the Bert model for embedding, and the embedded word units are the character word units in the target text (excluding symbol word units). The text embedding vector generated after embedding is consistent with the original Bert word vector volume, and the size of the resulting text embedding vector is [22128,768]; the second embedding layer uses the trained word2vec model to embed the symbol word units in the target text, and the size of the generated symbol embedding vector is [200,768]. Then, based on the obtained text embedding vector and symbol embedding vector, the two are added together to obtain the final target text embedding vector, and the vector size is [22328,768].
[0125] Among them, the first embedding layer in the problem-solving model training method provided by the present application includes the following sub-embedding layers: word embedding layer, position embedding layer, and sentence embedding layer. After the above three levels of embedding processing, the discrete word units in the input model are converted into vector representations; and the encoded vectors of the above three levels are added together to generate the embedding vectors of the text word units in the target sample text.
[0126] In the problem-solving model training method provided in the present application, the first embedding layer and the second embedding layer are used to embed the text word units and the symbol word units in the sample text respectively. Compared with embedding all the text word units and the symbol word units using the same Bert model, the problem-solving model training method provided in the present application can improve the overall understanding ability and accuracy of the model and has better results.
[0127] Furthermore, the step of inputting the embedding vector into the encoding layer for sequential encoding to generate the encoding vector of the target sample text specifically includes:
[0128] In the problem-solving model training method provided in the present application, the encoding layer of the encoder adopts a Transformer structure to encode the context information of the target sample text.
[0129] In this application, only the encoder structure of the Transformer model is adopted.
[0130] In the present application, the above embedding layer (including the first embedding layer and the second embedding layer) is the input layer of the Transformer encoder.
[0131] Specifically, the Transformer encoder structure includes multiple encoding layers (for example, 6 encoding layers connected in sequence), each of which includes a multi-head self-attention layer and a fully connected feed-forward network (FFN).
[0132] For the encoding vector of a multi-head attention layer among the multiple encoding layers connected in sequence to the Transformer encoder, each word unit corresponds to three different vectors, namely, the word vector Q (Query), K (Key), and V (Value). The calculation of the multi-head attention layer is to project the word vectors Q, K, and V through h different linear transformations, and finally concatenate the different attention results.
[0133] Among them, in the attention calculation of the encoder, the word vectors Q (Query), K (Key), and V (Value) are equal to each other. They are the encoding vectors output by the previous encoding layer. For the first encoding layer, the word vectors Q, K, and V are the embedding vectors (the sum of the text embedding vector and the symbol embedding vector) of the target sample text output by the embedding layer (including the first embedding layer and the second embedding layer) multiplied by the weight matrix.
[0134] Specifically, the calculation formula of the multi-head attention layer is as follows:
[0135] =Attention (QW i Q , KW i K , VW i V )(1)
[0136] Multihead(Q,K,V)=Concat( ,…, )W O (2)
[0137] Among them, Q, K, and V are the word vectors corresponding to the input encoding vectors;
[0138] head i It is the self-attention result of each head of the multi-head attention layer;
[0139] Multihead is the output result of the multi-head attention layer;
[0140] Concat is the concatenation function;
[0141] Wi Q , W i K , W i V The weight matrix for linear transformation of each word vector Q, K, V. For example, each word unit corresponds to three different word vectors Q, K, V, all of which are 64-dimensional. They are obtained by multiplying the embedding vector by three different weight matrices W through three different weight matrices. i Q , W i K , W i V As a result, all three matrices are 512*64 dimensions.
[0142] W O The weight matrix required for linear transformation is 512*512 in size.
[0143] Then, the output of the multi-head attention layer is input into the fully connected layer (FFN). The calculation formula of the fully connected layer (FFN) is as follows:
[0144] (3)
[0145] Among them, H1 and H2 are parameter matrices obtained through training;
[0146] b1 and b2 are parameters obtained through training;
[0147] x is the output result of the multi-head attention layer;
[0148] FFN(x) is the output of the fully connected layer.
[0149] After the output of the fully connected layer, the encoding vector output by the encoding layer is obtained.
[0150] Furthermore, the present application uses a Transformer encoding layer to convert the embedding vector of the target sample text into an encoding vector, and the sentence output of the target sample text is represented as E=[e cls ,e1,…,e n ,e sep ], where e is the hidden vector unit.
[0151] To sum up, in the process of training the problem-solving model, the present application adopts the Bert model to encode the target sample text, and expands the embedding layer of the Bert model with the word2vec structure, which can achieve a better understanding of the contextual information of the target sample text; especially in solving mathematical word problems, it can also increase the problem-solving model's understanding of the stem information of the word problems during the training process, thereby improving the overall answer accuracy of the problem-solving model; at the same time, the model training method provided by the present application does not require artificial construction of features, saving labor costs.
[0152] S204: Input the encoding vector into the decoder of the problem-solving model for decoding to generate a sample answer.
[0153] See also Figure 2 and Figure 3 As shown, during the training process, after the target sample text is encoded by the encoder of the problem-solving model, the obtained encoding vector is further input into the decoder of the problem-solving model for decoding. In a specific implementation scheme of the present application, the decoder of the problem-solving model is a pre-trained LSTM model. Specifically, the following steps are included:
[0154] Performing parameter initialization processing on the decoder according to the first vector unit of the encoding vector;
[0155] Based on the decoder, each of the vector units is decoded respectively, a decoding vector corresponding to each of the vector units is output, and a sample answer is generated based on the decoding vector corresponding to each of the vector units.
[0156] Specifically, performing parameter initialization processing on the decoder according to the first vector unit of the encoding vector includes:
[0157] According to the sentence output E of the encoder above, the first output vector e cls It represents the overall information of the target sample text of the original input. Therefore, in the decoding training process, e is first used cls Initialize the parameters of the LSTM model, where the parameters include: h and c.
[0158] h represents the output of the cell in the LSTM model; c represents the state of the cell in the LSTM model.
[0159] Since the sample text to be answered and the answer label used in each training are different during the training process, during the decoding process, this application will use the first vector unit in the encoding vector output of each new target sample text to initialize the parameters in the decoder, which can effectively improve the decoding accuracy and reduce interference factors to the decoder.
[0160] Specifically, decoding each of the vector units based on the decoder, outputting a decoding vector corresponding to each of the vector units, and generating a sample answer based on the decoding vector corresponding to each of the vector units, includes:
[0161] Furthermore, if Figure 3 As shown, when the LSTM model is used as a decoder to decode the sample answer, the encoding vector E obtained from the target sample text and the starting symbol are input into the decoder LSTM to generate a sample answer.
[0162] Specifically, the LSTM model performs decoding as a decoder as follows: Figure 5 As shown, according to the text encoding vector E and the starting symbol input to the decoder <bos>, get the first decoding hidden layer output h1, and get the first decoding word "X" according to the first decoding hidden layer output h1; according to the first decoding word "X" and the first decoding hidden layer output h1, get the second decoding hidden layer output h2 and the second decoding word "=", according to the second decoding word "=" and the second decoding hidden layer output h2, get the third decoding hidden layer output h3 and the third decoding word "O1", and so on, until according to O n-1 Get the nth decoded word O n .
[0163] Specifically applied to the decoding process in this application, by default, "X=" is first decoded, and the "teacher forcing" strategy is used during the decoder training process, that is, when predicting the output at time t, the input of all the previous t-1 moments in the target will be considered. Figure 3 As shown in , first decode "X", then decode "=", and so on, until decode " <eos>”End flag, and the generated answer is "X=O1O2O3…O n ”.
[0164] In the problem-solving model training method provided by this application, a pre-trained LSTM model is used as the decoder to decode the encoded vector, which can take into account the output of the previous moment during the decoding process, further strengthening the model's understanding of context information and making the predicted sample answers more accurate.
[0165] S205. Calculate the loss value by comparing the sample answer with the answer label.
[0166] Furthermore, the sample answer can be compared with the answer label, and the loss value is calculated through a loss function.
[0167] In practical applications, the loss function can be, for example, categorical cross-entropy, maximum entropy function, etc., and this application does not limit this.
[0168] S206. Iteratively train the problem-solving model based on the loss value until the training stop condition is reached.
[0169] Furthermore, step S206 further includes:
[0170] Judge whether the loss value is less than a preset threshold;
[0171] If not, continue to obtain the text to be answered and the answer label for training;
[0172] If so, stop training.
[0173] Among them, the preset threshold can be set according to the actual situation of the trained model for the purpose of achieving stable operation of the model, and this application does not limit this here.
[0174] Next, this embodiment will be further described with specific examples.
[0175] For example, the text of the sample to be answered includes "Xiaoming is 8 years old this year. The age of Xiaoming's father is 1 year more than 4 times Xiaoming's age. The age of Xiaoming's father this year", and the answer label is "d1*d2+d3".
[0176] First, preprocess the text of the sample to be answered, replace the numbers in it with symbols, and obtain the target sample text as "Xiaoming is d1 years old this year. The age of Xiaoming's father is d2 times more than Xiaoming's age by d3 years. The age of Xiaoming's father this year".
[0177] Then, perform word segmentation on the obtained target sample text to obtain the word unit set [cls, Xiaoming, this, year, d1, years old... age, sep]. The obtained word unit set contains literal word units and symbolic word units.
[0178] The above word units are input into the embedding layer of the encoder in the problem-solving model, wherein the text word units are embedded using the first embedding layer to generate text embedding vectors; wherein the symbol word units are embedded using the second embedding layer to obtain symbol embedding vectors; and then the two embedding vectors are added together to obtain the complete embedding vector of the target sample text.
[0179] The obtained complete embedding vector is then input into the encoding layer in the encoder for encoding to generate the encoding vector E = [e cls ,e1,…,e n ,e sep ].
[0180] Then, based on the first word vector unit of the obtained encoding vector E, that is, e cls Initialize the decoder parameters h and c; then use the initialized decoder to decode each word vector unit contained in E, and finally obtain the sample answer X=O1O2O3…O n .
[0181] Then, based on the obtained sample answers and answer labels, the loss function is used to calculate the loss value, and the loss value is 0.2.
[0182] Assuming that the preset loss value threshold is 0.10, the obtained loss value is greater than the preset loss value threshold, so continue to obtain the sample text to be answered and the answer label for iterative training.
[0183] Furthermore, in the problem-solving model training method provided in the present application, before inputting the target text into the encoder of the problem-solving model for encoding, the method further includes:
[0184] Using an encoding optimizer to fine-tune the pre-trained encoder, and using a decoding optimizer to fine-tune the pre-trained decoder;
[0185] When the encoder update step number reaches a first threshold, the encoder fine-tuning stops;
[0186] When the decoder update step number reaches a second threshold, the decoder fine-tuning stops;
[0187] Among them, the learning rates of the encoding optimizer and the decoding optimizer are initialized differently.
[0188] For example, in the process of fine-tuning the encoder using the encoder optimizer, the learning rate of the encoder optimizer is set to be initialized to 0.00001, and the parameter update stops after the encoder is updated for 20,000 steps;
[0189] When fine-tuning the decoder using the decoding optimizer, the decoding optimizer learning rate is initialized to 0.001, and the parameters stop updating after the decoder is updated 100,000 times.
[0190] Different optimizers are used to fine-tune the encoder and decoder respectively, which further improves the stability of the model and the accuracy of problem solving.
[0191] The problem-solving model training method provided by the present application first pre-processes the sample text to be answered, replaces the numbers obtained in the text with symbols for representation, and then encodes the text using the Bert model. In the encoding process, different embedding layers are used to embed text word units and symbol word units respectively, which can effectively improve the accuracy of the model, and the use of the Bert model for encoding can enable the model to better understand the question text and improve the accuracy of prediction; and in the problem-solving model training method provided by the present application, the coded vector obtained by the Bert model encoding is decoded using the LSTM model and the sample answer is predicted. Through the "teacher forcing" strategy of the LSTM model, the understanding of contextual information can be further enhanced, thereby improving the accuracy of the answer; at the same time, before the present application is trained, different optimizers are used to fine-tune the encoder and decoder in the model respectively, and the learning rates set by the two optimizers are initialized differently, so that the model can reach the optimal state and further improve the accuracy of the model's problem-solving answers.
[0192] Based on the problem-solving model obtained by the training method provided above, this application also provides a problem-solving method, such as Figure 6 As shown, the following steps are included:
[0193] S601, obtaining the text to be answered.
[0194] Among them, the text to be solved is the text for solving problems using the problem-solving model. The text to be solved should include a stem text part and a question text part, and the stem text part in the sample text to be solved must include both text and numbers.
[0195] Optionally, the text to be answered includes text word units and number word units.
[0196] Furthermore, for the numerical meanings expressed in words in the text with answers, they can be uniformly converted into numbers first, for example, "one week" can be converted into "7 days", "2 hours" can be converted into "120 minutes", etc. The conversion can be made according to the actual question, and this application does not impose any restrictions on this.
[0197] S602: Preprocess the text to be answered to generate a target text.
[0198] In the present application, since the text to be answered contains text word units and numeric word units, and the numerical values, number of digits and order of digits contained in different texts to be answered are different, the text to be answered needs to be preprocessed in the problem-solving method provided in the present application.
[0199] Optionally, preprocessing the text to be answered to generate a target text includes:
[0200] Based on the position sequence of the number word units in the text to be answered, the number word units are replaced in the position sequence using preset symbols to generate the target text.
[0201] In a specific implementation of the present application, the preprocessing of the sample text to be answered is normalizing the numbers contained in the sample text to be answered, which specifically includes:
[0202] A mapping M is constructed for the number word units contained in the question stem of the text to be answered. The answer text is a question P with m number word units. According to the order of each number word unit in the question P, the mapping M is used to map the number word units in the question P to the number tag list {d1, ..., d m }, that is, the digital word units in the text to be answered are represented by symbols to obtain the target text.
[0203] For example, the original text to be answered is "The school divides 135 exercise books equally among 3 classes. How many books does each class have?" After the above preprocessing, the target text obtained is "The school divides d1 exercise books equally among d2 classes. How many books does each class have?"
[0204] In the present application, the text to be solved is preprocessed and the numeric word units therein are replaced with symbols, which can effectively improve the accuracy of the subsequent problem-solving method and reduce the errors caused by the differences in numeric word units when solving different math problems.
[0205] S603: Input the target text into the encoder of the problem-solving model for encoding to generate an encoding vector of the target text.
[0206] In the problem-solving method provided in the present application, the decoder of the problem-solving model adopted includes an embedding layer and multiple sequentially connected encoding layers.
[0207] In a specific implementation of the present application, the encoder used by the problem-solving model is a Bert model.
[0208] Furthermore, in practical applications, before the input embedding layer is performed, the target text can be pre-segmented to obtain text word units and symbol word units.
[0209] Specifically include, Figure 3 As shown in the figure, in the process of solving the problem, the characteristic symbols cls and sep of the Bert model are added to the target text to be input into the Bert model, where cls is the beginning of the sentence symbol and sep is the sentence symbol; for example, using w i (i=1, …, n) is used to represent the input target text, where n represents the length of the target text. After adding the above feature symbols, the input is represented as W=[cls,w1,w2,…,w n ,sep].
[0210] For example, if the target text obtained after preprocessing is "each exercise book costs d1 yuan, d2 exercise books cost how much", then the input is expressed as W=[cls,each,exercise,book,d1,yuan,d2,exercise,book,more,less,money,sep].
[0211] Furthermore, the step of inputting the target text into an encoder of a problem-solving model for encoding to generate an encoding vector of the target text includes:
[0212] Inputting the target text into the embedding layer for embedding processing to obtain an embedding vector of the target text;
[0213] The embedding vector is input into the encoding layer for encoding in sequence to generate the encoding vector of the target text.
[0214] Since the numbers in the text to be solved are replaced by symbols in the above operation, many related words {d1, ..., d m }, these symbols do not exist in the dictionary of the pre-trained Bert model, and they are newly appeared in the process of converting numbers to symbols. Therefore, in order to improve the accuracy of the model and strengthen the model's understanding of the target text, especially the understanding of symbol word units, this application uses the trained word2vec model to further expand the embedding layer of the Bert model, that is, for {d1, ..., d m The symbol word unit of} is represented by word2vec vector, while other text word units are represented by the embedding vector of the original Bert model.
[0215] Specifically, corresponding to the text word unit and the symbol word unit, the embedding layer of the encoder in the problem-solving method provided in the present application includes a first embedding layer and a second embedding layer.
[0216] Furthermore, the step of inputting the target text into the embedding layer for embedding processing to obtain an embedding vector of the target text includes:
[0217] Embedding the word units in the target text using the first embedding layer to generate a word embedding vector;
[0218] Embedding the symbol word units in the target text using a second embedding layer to generate a symbol embedding vector;
[0219] The embedding vector of the target text is obtained based on the combination of the text embedding vector and the symbol embedding vector.
[0220] For example, in a specific implementation of the present application, the first embedding layer uses the Bert model for embedding, and the embedded word units are the character word units in the target text (excluding symbol word units). The text embedding vector generated after embedding is consistent with the original Bert word vector volume, and the resulting text embedding vector size is [22128,768]; the second embedding layer uses the trained word2vec model to embed the symbol word units in the target text, and the generated symbol embedding vector size is [200,768]. Then, based on the obtained text embedding vector and symbol embedding vector, the two are added together to obtain the final target text embedding vector, and the vector size is [22328,768].
[0221] For example, the target text obtained after preprocessing is "Xiao Ming has d1 pens, Xiao Ming gives Xiao Hong d2 pens, how many pens does Xiao Ming have left?" Before embedding, the input text is firstly represented as W=[cls,Xiao,Ming,has,d1,root,pen,....root,pen,sep] by adding feature symbols, and W is input into the model for embedding; the text word units (Xiao,Ming,has,root,pen,Xiao,Ming,divides,to,Xiao,Hong,root,Xiao,Ming,still,left,more,less,root,pen) are embedded by the original Bert model embedding layer (i.e., the first embedding layer) to obtain a text embedding vector of size [22128,768]; the symbol word unit (d1,d2) is embedded by word2vec (i.e., the second embedding layer) to obtain a symbol embedding vector of size [200,768]; then the two are added to generate the embedding vector of the target text of size [22328,768].
[0222] Furthermore, the step of inputting the embedding vector into the encoding layer for sequential encoding to generate the encoding vector of the target text includes:
[0223] In the problem-solving method provided in the present application, the encoding layer is specifically a Transformer encoding structure, and the Transformer encoding structure includes multiple encoding layers connected in sequence (for example, 6 encoding layers connected in sequence); wherein each encoding layer includes a multi-head self-attention layer and a fully connected layer (fully connected feed-forward network, FFN).
[0224] In the problem-solving process, the embedding vector of the target text obtained by the embedding layer passes through each encoding layer connected in sequence, and finally outputs the encoding vector of the target text; specifically, the sentence encoding vector output by the target text is expressed as E=[e cls ,e1,…,e n ,e sep ], where e is the hidden vector unit.
[0225] In the problem-solving method provided in the present application, the embedding vectors of the target text generated by the encoder embedding layer are input into multiple encoding layers connected in sequence. Based on the self-attention mechanism in each encoding layer, the encoder's understanding of the context of the input target text can be further enhanced, and finally the encoding vector of the target text with enhanced semantic information is obtained.
[0226] To sum up, in the problem-solving method of the present application, the Bert model is first used to embed the target text, and the word2vec embedding structure is added to the embedding layer of the Bert model for expansion, which can achieve a better understanding of the contextual information of the target text including words and symbols; in addition, for solving mathematical word problems, the problem-solving model can also increase its understanding of the information in the word problem stem, thereby improving the accuracy of the problem-solving method; at the same time, the problem-solving method provided by the present application does not require artificial construction of features, saving labor costs.
[0227] S604: Input the encoding vector into the decoder of the problem-solving model for decoding to generate an answer.
[0228] In the problem-solving method provided in this application, an LSTM model is used to decode the encoding vector of the target text generated above. Specifically, the following steps are included:
[0229] Performing parameter initialization processing on the decoder according to the first vector unit of the encoding vector;
[0230] Based on the decoder, each of the vector units is decoded respectively, a decoding vector corresponding to each of the vector units is output, and an answer is generated based on the decoding vector corresponding to each of the vector units.
[0231] Further, the performing parameter initialization processing on the decoder according to the first vector unit of the encoding vector includes:
[0232] Among them, according to the above output encoding vector E=[e cls ,e1,…,e n ,e sep ] It can be seen that the encoding vector includes multiple vector units; among which, the first vector unit e in the encoding vector cls It represents the overall information of the original input target text, so in the decoding process, e is first used cls Initialize the parameters of the LSTM model, where the parameters include: h and c.
[0233] h represents the output of the cell in the LSTM model; c represents the state of the cell in the LSTM model.
[0234] Since the questions to be solved each time are different during the problem-solving process, during the decoding process, the present application will use the first vector unit in the encoding vector obtained for each new question to initialize the parameters in the decoder, which can effectively improve the decoding accuracy and reduce interference factors to the decoder.
[0235] Furthermore, the decoder decodes each of the vector units respectively, outputs a decoding vector corresponding to each of the vector units, and generates an answer based on the decoding vector corresponding to each of the vector units, including: when the LSTM model is used as the decoder to decode the answer, the encoding vector E obtained from the target text and the starting symbol of the decoder are converted into the decoded vector E. <bos>They are input into the decoder LSTM together to finally generate a sample answer.
[0236] Specifically, when the problem-solving method provided in this application is decoded, "X=" is decoded by default first, and the "teacher forcing" strategy is used in the decoding process of the decoder, that is, when predicting the output at time t, the input of all previous time t-1 is considered. For example, in a specific implementation scheme of this application, Figure 3 As shown, the decoder passes the input encoding vector and the starting symbol <bos>, the first decoded word is "X"; when decoding the second encoding vector, not only the second encoding vector but also the first decoding word "X" is needed, and the second decoding word is "="; when decoding the third encoding vector, not only the third encoding vector but also the second decoding word "=" is needed to get the third decoding word "O1"; when decoding the fourth encoding vector, not only the third encoding vector but also the second decoding word "O1" is needed, and so on. The LSTM model uses recursive decoding until the decoded word is " <eos>”End flag, and the generated answer is "X=O1O2O3…O n ”, where O i (all integers between i = 1 and n) belong to the decoder vocabulary, which is composed of all digital symbols and digital operators. Among them, the digital symbols are the symbols that replace numbers during the preprocessing process; the digital operators are various operation symbols in the field of mathematics, such as "+", "-", "*", " / ", etc. For example, if the target sample text is "Xiaoming is d1 years old this year, how old will Xiaoming be after d2 years", after encoding it and then decoding it using the decoder, the input sample answer is "X=d1 + d2".
[0237] In the problem-solving method provided by this application, the LSTM model is used as the decoder to decode the encoded vector, which can take into account the outputs at all previous moments during the decoding process, further strengthening the model's understanding of context information and making the predicted sample answer more accurate.
[0238] Among them, the problem-solving model is trained by the training method provided above.
[0239] Furthermore, after step S604, it further includes: replacing the symbols included in the obtained answer with the original real numbers.
[0240] The above problem-solving method will be further explained below in combination with practical applications.
[0241] For example, the text of the problem to be solved is "There are 20 boxes of mineral water in the store, and 2 boxes are sold on average every day. How many boxes are left after 3 days", and the target text obtained after preprocessing is "There are d1 boxes of mineral water in the store, and d2 boxes are sold on average every day. How many boxes are left after d3 days".
[0242] Then, the obtained target sample text is tokenized to obtain a set of word units [cls, store, total, have, d1, box... more, less, box, sep]. The obtained set of word units contains literal word units and symbol word units.
[0243] The above word units are input into the embedding layer of the encoder in the problem-solving model. Among them, the literal word units are embedded using the first embedding layer to generate literal embedding vectors; the symbol word units are embedded using the second embedding layer to obtain symbol embedding vectors; then the two embedding vectors are added to obtain the complete embedding vector of the target text.
[0244] Then, the obtained complete embedding vector is input into the encoding layer in the encoder for encoding to generate the encoded vector E = [e cls , e1,..., e n , e sep of the target sample text.
[0245] Then, based on the first word vector unit of the obtained encoding vector E, that is, e cls Initialize the decoder parameters h and c; then use the initialized decoder to decode each word vector unit contained in E, and finally obtain the answer X=d1-d2*d3.
[0246] Then, based on the answer obtained, replace the symbols with the corresponding real numbers to obtain X=20-2*3, which is the target answer.
[0247] The problem-solving method provided by the present application first pre-processes the text to be answered, replaces the numbers obtained in the text with symbolic representations, and then encodes the text using the Bert model. In the encoding process, different embedding layers are used to embed text word units and symbolic word units respectively, which can effectively improve the accuracy of the model; and the use of the Bert model for encoding can enable the model to better understand the question text and improve the accuracy of the prediction; in addition, in the problem-solving model training method provided by the present application, the coded vector obtained by encoding with the Bert model is decoded using the LSTM model to generate the answer. Through the "teacher forcing" strategy of the LSTM model, the understanding of contextual information can be further enhanced, thereby improving the accuracy of the answer.
[0248] The present application also provides a training device for a problem-solving model, such as Figure 7 As shown, it includes the following modules:
[0249] The sample acquisition module 701 is configured to acquire sample text to be answered and answer labels;
[0250] The sample preprocessing module 702 is configured to preprocess the sample text to be answered to generate a target sample text;
[0251] The encoding module 703 is configured to input the target sample text into the encoder of the problem-solving model for encoding, and generate an encoding vector of the target sample text;
[0252] A decoding module 704 is configured to input the encoding vector into a decoder of the problem-solving model for decoding to generate a sample answer;
[0253] A calculation module 705 is configured to calculate the sample answer and the answer label to determine a loss value;
[0254] The iterative training module 706 is configured to iteratively train the problem-solving model based on the loss value until a training stop condition is reached.
[0255] Optionally, the sample preprocessing module 702 is further configured to: based on the position order of the number word units in the text to be answered, use preset symbols to replace the number word units in the position order to generate the target text.
[0256] Optionally, the encoding module 703 is further configured as follows: the encoder includes an embedding layer and a plurality of sequentially connected encoding layers;
[0257] The step of inputting the target text into the encoder of the problem-solving model for encoding to generate the encoding vector of the target text comprises:
[0258] Inputting the target text into the embedding layer for embedding processing to obtain an embedding vector of the target text;
[0259] The embedding vector is input into the encoding layer for encoding in sequence to generate the encoding vector of the target text.
[0260] Optionally, the encoding module 703 is further configured as follows: the embedding layer includes a first embedding layer and a second embedding layer;
[0261] The step of inputting the target text into the embedding layer for embedding processing to obtain an embedding vector of the target text includes:
[0262] Embedding the word units in the target text using the first embedding layer to generate a word embedding vector;
[0263] Embedding the symbol word units in the target text using a second embedding layer to generate a symbol embedding vector;
[0264] The embedding vector of the target text is obtained based on the combination of the text embedding vector and the symbol embedding vector.
[0265] Optionally, the decoding module 704 is further configured to: perform parameter initialization processing on the decoder according to the first vector unit of the encoding vector;
[0266] Based on the decoder, each of the vector units is decoded respectively, a decoding vector corresponding to each of the vector units is output, and a sample answer is generated based on the decoding vector corresponding to each of the vector units.
[0267] Optionally, the device further comprises: a model fine-tuning module configured to use an encoding optimizer to perform fine-tuning processing on the pre-trained encoder, and use a decoding optimizer to perform fine-tuning processing on the pre-trained decoder;
[0268] When the encoder update step number reaches a first threshold, the encoder fine-tuning stops;
[0269] When the decoder update step number reaches a second threshold, the decoder fine-tuning stops.
[0270] Optionally, the iterative training module 706 is further configured to: determine whether the loss value is less than a preset threshold;
[0271] If not, continue to obtain the text to be answered and the answer label for training;
[0272] If yes, stop training.
[0273] The problem-solving model training device provided by the present application adopts the Bert model to encode the text, and adopts different embedding layers to embed the text word units and the symbol word units respectively during the encoding process, which can effectively improve the accuracy of the model, and the use of the Bert model for encoding can enable the model to better understand the question text and improve the prediction accuracy; and the problem-solving model training device provided by the present application adopts the LSTM model to decode the encoded vector obtained by the Bert model encoding and predict the sample answer, which can further enhance the understanding of contextual information and thus improve the accuracy of the answer; at the same time, before the present application performs training, different optimizers are used to fine-tune the encoder and decoder in the model respectively, and the learning rates set by the two optimizers are initialized differently, which can enable the model to reach the optimal state and further improve the accuracy of the model's problem-solving answers.
[0274] The present application also provides a problem-solving device, such as Figure 8 As shown, including:
[0275] An acquisition module 810 is configured to acquire a text to be answered;
[0276] The text preprocessing module 820 is configured to preprocess the text to be answered to generate a target text;
[0277] The encoding module 830 is configured to input the target text into the encoder of the problem-solving model for encoding, and generate an encoding vector of the target text;
[0278] The decoding module 840 is configured to input the encoding vector into the decoder of the problem-solving model for decoding to generate an answer.
[0279] Wherein, the text to be answered includes text word units and number word units;
[0280] The text preprocessing module 820 is further configured to use preset symbols to replace the numeric word units in the position order based on the position order of the numeric word units in the text to be answered, so as to generate the target text.
[0281] Wherein, the decoder of the problem-solving model includes an embedding layer and a plurality of sequentially connected encoding layers;
[0282] The encoding module 830 is further configured to input the target text into the encoder of the problem-solving model for encoding, and generating the encoding vector of the target text includes:
[0283] Inputting the target text into the embedding layer for embedding processing to obtain an embedding vector of the target text;
[0284] The embedding vector is input into the encoding layer for encoding in sequence to generate the encoding vector of the target text.
[0285] Wherein, the embedding layer comprises a first embedding layer and a second embedding layer;
[0286] The encoding module 830 is further configured to input the target text into the embedding layer for embedding processing to obtain an embedding vector of the target text, including:
[0287] Embedding the word units in the target text using the first embedding layer to generate a word embedding vector;
[0288] Embedding the symbol word units in the target text using a second embedding layer to generate a symbol embedding vector;
[0289] The embedding vector of the target text is obtained based on the combination of the text embedding vector and the symbol embedding vector.
[0290] Wherein, the encoding vector includes a plurality of vector units;
[0291] The decoding module 840 is further configured to perform parameter initialization processing on the decoder according to the first vector unit of the encoding vector;
[0292] Based on the decoder, each of the vector units is decoded respectively, a decoding vector corresponding to each of the vector units is output, and an answer is generated based on the decoding vector corresponding to each of the vector units.
[0293] The problem-solving device provided by the present application first pre-processes the text to be answered, replaces the numbers obtained in the text with symbolic representations, and then encodes the text using the Bert model. In the encoding process, different embedding layers are used to embed text word units and symbolic word units respectively, which can effectively improve the accuracy of the model; and the use of the Bert model for encoding can enable the model to better understand the question text and improve the prediction accuracy; at the same time, in the problem-solving device provided by the present application, the coded vector obtained by encoding with the Bert model is decoded using the LSTM model and the answer is predicted. Through the "teacher forcing" strategy of the LSTM model, the understanding of contextual information can be further enhanced, thereby improving the accuracy of the answer.
[0294] An embodiment of the present application also provides a computer-readable storage medium storing computer instructions, which, when executed by a processor, implement the training method of the problem-solving model or the steps of the problem-solving method as described above.
[0295] The above is a schematic scheme of a computer-readable storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the training method of the problem-solving model or the problem-solving method mentioned above belong to the same concept, and the details not described in detail in the technical scheme of the storage medium can be referred to the description of the technical scheme of the training method of the problem-solving model or the problem-solving method mentioned above.
[0296] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0297] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described action sequence, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0298] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0299] The preferred embodiments of the present application disclosed above are only used to help explain the present application. The optional embodiments do not describe all the details in detail, nor do they limit the invention to the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the present application, so that those skilled in the art can understand and use the present application well. The present application is limited only by the claims and their full scope and equivalents.< / eos> < / bos> < / bos> < / eos> < / bos>
Claims
1. A method for training a problem-solving model, wherein the problem-solving model is composed of an encoder and a decoder, characterized in that: The following steps are involved: Get the sample text to be answered and the answer label; Preprocessing the sample text to be answered to generate a target sample text; Inputting the text word units in the target sample text into the first embedding layer of the encoder for embedding processing to generate a text embedding vector; Inputting the symbol word unit in the target sample text into the second embedding layer of the encoder for embedding processing to generate a symbol embedding vector; Obtaining an embedding vector of the target sample text based on a combination of the text embedding vector and the symbol embedding vector; Inputting the embedding vector into a plurality of sequentially connected encoding layers of the encoder for encoding in sequence to generate an encoding vector of the target sample text; Input the encoding vector into a decoder of the problem-solving model for decoding to generate a sample answer; Calculate the sample answer and the answer label to determine the loss value; The problem-solving model is iteratively trained based on the loss value until a training stop condition is reached.
2. The training method according to claim 1, characterized in that: The sample text to be answered includes text word units and number word units; The preprocessing of the sample text to be answered to generate the target sample text comprises: Based on the position sequence of the number word units in the sample text to be answered, the number word units are replaced in the position sequence using preset symbols to generate the target sample text.
3. The training method according to claim 1, characterized in that: The encoding vector includes a plurality of vector units; Inputting the encoded vector into a decoder of the problem-solving model for decoding to generate a sample answer includes: Performing parameter initialization processing on the decoder according to the first vector unit of the encoding vector; Based on the decoder, each of the vector units is decoded respectively, a decoding vector corresponding to each of the vector units is output, and a sample answer is generated based on the decoding vector corresponding to each of the vector units.
4. The training method according to claim 1, characterized in that: Before inputting the target sample text into the encoder of the problem-solving model for encoding, the method further includes: Using an encoding optimizer to fine-tune the pre-trained encoder, and using a decoding optimizer to fine-tune the pre-trained decoder; When the encoder update step number reaches a first threshold, the encoder fine-tuning stops; When the decoder update step number reaches a second threshold, the decoder fine-tuning stops.
5. The training method according to claim 1, characterized in that: The iterative training of the problem-solving model based on the loss value until a training stop condition is reached includes: Determine whether the loss value is less than a preset threshold; If not, continue to obtain the sample text to be answered and the answer label for training; If yes, stop training.
6. A problem-solving method, characterized in that: include: Get the text to be answered; Preprocessing the text to be answered to generate a target text; Inputting the text word units in the target text into the first embedding layer of the encoder in the problem-solving model for embedding processing to generate a text embedding vector; Inputting the symbol word unit in the target text into the second embedding layer of the encoder for embedding processing to generate a symbol embedding vector; Obtaining an embedding vector of the target text based on a combination of the text embedding vector and the symbol embedding vector; Inputting the embedding vector into a plurality of sequentially connected encoding layers of the encoder for encoding in sequence to generate an encoding vector of the target text; Input the encoded vector into a decoder of the problem-solving model for decoding to generate an answer; The problem-solving model is obtained by training using the training method described in any one of claims 1 to 5.
7. The method according to claim 6, characterized in that The text to be answered includes text word units and number word units; The preprocessing of the text to be answered to generate the target text comprises: Based on the position sequence of the number word units in the text to be answered, the number word units are replaced in the position sequence using preset symbols to generate the target text.
8. The method according to claim 6, characterized in that The encoding vector includes a plurality of vector units; Inputting the encoded vector into a decoder of the problem-solving model for decoding to generate an answer includes: Performing parameter initialization processing on the decoder according to the first vector unit of the encoding vector; Based on the decoder, each of the vector units is decoded respectively, a decoding vector corresponding to each of the vector units is output, and an answer is generated based on the decoding vector corresponding to each of the vector units.
9. A training device for a problem-solving model, characterized in that: include: A sample acquisition module is configured to acquire sample texts to be answered and answer labels; A sample preprocessing module is configured to preprocess the sample text to be answered to generate a target sample text; An encoding module is configured to input the text word units in the target sample text into the first embedding layer of the encoder in the problem-solving model for embedding processing to generate a text embedding vector; Inputting the symbol word unit in the target sample text into the second embedding layer of the encoder for embedding processing to generate a symbol embedding vector; Obtaining an embedding vector of the target sample text based on a combination of the text embedding vector and the symbol embedding vector; Inputting the embedding vector into a plurality of sequentially connected encoding layers of the encoder for encoding in sequence to generate an encoding vector of the target sample text; A decoding module, configured to input the encoding vector into a decoder of the problem-solving model for decoding to generate a sample answer; A calculation module, configured to calculate the sample answer and the answer label to determine a loss value; The iterative training module is configured to iteratively train the problem-solving model based on the loss value until a training stop condition is reached.
10. A problem-solving device, characterized in that: include: An acquisition module is configured to acquire the text to be answered; A text preprocessing module is configured to preprocess the text to be answered to generate a target text; An encoding module is configured to input the text word units in the target text into the first embedding layer of the encoder in the problem-solving model for embedding processing to generate a text embedding vector; Inputting the symbol word unit in the target text into the second embedding layer of the encoder for embedding processing to generate a symbol embedding vector; Obtaining an embedding vector of the target text based on a combination of the text embedding vector and the symbol embedding vector; Inputting the embedding vector into a plurality of sequentially connected encoding layers of the encoder for encoding in sequence to generate an encoding vector of the target text; The decoding module is configured to input the encoding vector into the decoder of the problem-solving model for decoding to generate an answer.
11. A computing device comprising a memory, a processor, and computer instructions stored in the memory and executable on the processor, characterized in that: When the processor executes the instructions, the steps of the method described in any one of claims 1-5 or 6-8 are implemented.
12. A computer-readable storage medium storing computer instructions, characterized in that: When the instruction is executed by the processor, the steps of the method described in any one of claims 1-5 or 6-8 are implemented.
