Unified pre-training method for Chinese question generation based on word lattice and relative position embedding
By integrating domain word lattice embedding and relative position coding in the Unilm language model, and conducting domain pre-training and task pre-training, the problem of poor application results of Chinese question generation models in different professional fields has been solved, and more efficient domain specificity has been achieved. Sexual problems arise.
Patent Information
- Application Number
- CN202110814546.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-19
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-07-19
AI Technical Summary
Existing Chinese question generation models have poor application results in different professional fields and are difficult to generate high-quality domain-specific questions.
A question and answer system based on the Unilm language model is used to integrate domain word embedding and relative position coding, and perform domain pre-training and task pre-training to construct a special mask matrix and relative position embedding matrix to enhance the generation capability of the Transformer layer.
The model improves the accuracy and efficiency of question generation in the target field, can better capture the positional relationship between words and domain-specific information, and generates more meaningful questions.
Smart Images

Figure CN113743095B
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of question generation in Chinese natural language processing, and provides a unified pre-training method for Chinese question generation based on word lattice and relative position embedding. Background Art
[0002] With the development of the Internet and information technology, a large amount of information has poured into the Internet, which has also promoted the development of artificial intelligence. In the field of natural language processing, intelligent systems usually have to process a large amount of input corpus, so it is valuable to find a better way to process a large amount of corpus information.
[0003] Intelligent question-answering system QG (Question Generation) is a hot topic in natural language processing. Due to the activeness and innovation of human thinking, traditional rule-based question-answering systems are difficult to obtain satisfactory questions. At the same time, the substantial improvement in computer computing power in recent years has led to the gradual application of many deep learning-based question-answering systems. A very important application area is in the field of education. Since students are often exposed to a large amount of professional knowledge and professional vocabulary during the learning stage, in order to improve their familiarity with knowledge, they need to use some questions to consolidate their memory. The question generation system can assist teachers in raising relevant questions in the field and reduce teaching pressure. Question generation can also be used in chatbots to enhance human-computer interaction capabilities. In summary, generating high-quality questions can not only promote research in natural language processing, but also promote the development of fields such as psychotherapy and education. Therefore, it is of great practical significance to study question-answering systems that can raise high-quality questions.
[0004] In recent years, a large number of Transformer-based models have emerged. Since Transformer proposes an attention mechanism, this mechanism can effectively obtain context information from the input corpus. Training the Transformer model with a large amount of text can enable the model to learn the implicit relationship of context in natural language. For example, Bert, RoBert, GPT, GPT2, and the joint masking language model Unilm have achieved excellent performance in the field of NLP. In addition, these models can be migrated for different downstream tasks. After pre-training, the downstream tasks can converge the model with a small amount of annotated text, and the migrated model has better performance in downstream tasks. Among them, the Unilm language model combines various masking training ideas of other models. According to different specific tasks, it adopts bidirectional, left-to-right, right-to-left, and sequence-to-sequence. Different masking ideas will make the model better at different directions. For example, in text generation, using the left-to-right masking idea can improve the text generation ability. In the field of Chinese language models, Cui et al. used the Chinese Robert pre-training model with full word masking in Chinese. Since a word in Chinese often forms a new complete meaning, masking each token in the word can better capture the boundary relationship between words. The model has achieved the best level of pre-training models on multiple Chinese data sets. However, due to the huge differences in vocabulary composition and semantics in various fields of Chinese, the model cannot achieve good results in various professional fields. Summary of the invention
[0005] The purpose of the present invention is to provide a question-answering system based on the Unilm language model, which improves the generation accuracy of the model in the target domain and generates meaningful questions more efficiently by integrating domain lattice embedding and relative position encoding, and adding domain pre-training and task pre-training.
[0006] The technical solution adopted by the present invention is:
[0007] The unified pre-training method for Chinese question generation based on word lattice and relative position embedding includes the following steps:
[0008] Step 1: Pre-train Robert parameters in the field;
[0009] Step 2: Use a semi-supervised and semi-manual approach to quickly and accurately generate a dictionary for the target domain;
[0010] Step 3: Construct a special mask matrix to improve the generation ability of the model;
[0011] Step 4: Construct a special relative position embedding matrix to incorporate the relative position information of characters and words in the input into the Transformer layer according to the dictionary in step 2.
[0012] Step 5: The newly created Transformer layer inherits the parameters of the 12th layer of the Robert model and performs task pre-training through a large amount of open domain question-answering data;
[0013] Step 6, training and inference of the generation problem.
[0014] The present invention is also characterized in that:
[0015] Step 1 The specific steps are:
[0016] In the domain pre-training, the initial parameters of the Transformer block of the model are taken from Robert, the basis of Wikipedia corpus training, and then the model is pre-trained on the domain information text crawled from the Internet. The pre-training uses Robert's bidirectional masking pre-training mechanism and full-word masking mechanism. The dictionary in the full-word masking uses a public open domain dictionary to meet the needs of pre-training. By using these two mechanisms, we have optimized the pre-processing of the model.
[0017] The specific steps of step 2 are:
[0018] In order to obtain the target domain dictionary faster, the present invention uses a semi-supervised and semi-manual method to speed up the dictionary generation efficiency. First, the electronic documents of the target domain and the large-scale dictionary of the open domain are manually selected, the target domain documents are input into the named entity recognition deep learning model, and the entities recognized by the model are added to the domain dictionary. Then, the words of the large-scale open domain are indexed in the target domain text in a rule-based manner, and the words that exist in the index are added to the target domain dictionary. Finally, the formed domain dictionary is manually reviewed to form a final domain vocabulary dictionary.
[0019] The specific steps of step 3 are:
[0020] During the model training process, the original text and the target question are concatenated and then fed into the model for training. The tokens in the first half of the text can focus on the text in both the front and back directions, while the tokens in the second half can only focus on the first half of the text on the left.
[0021] The specific steps of step 4 are:
[0022] Word lattice and "relative position embedding" can add the positional relationship between each word or vocabulary into the attention calculation, strengthening the attention mechanism in the transformer. Therefore, the present invention uses relative position encoding for each word and vocabulary in the task pre-training stage. At the same time, relative position encoding can clearly express the position information between each vocabulary.
[0023] Step 5 The specific steps are:
[0024] In order to save computing resources and adapt to smaller manually annotated data sets, it is necessary to adopt a migration scheme of pre-trained models to provide sufficient common encyclopedic knowledge and domain information. Therefore, the present invention integrates the Transformer layer that incorporates word lattice and relative position encoding and inherits the last layer of Robert parameters that have been pre-trained in the field in step 1 to migrate encyclopedic knowledge and domain knowledge.
[0025] Since this model has many parameters and there is often little manually labeled question-answering data, task pre-training is added. The model is pre-trained on a large amount of open-domain question-answering data crawled from the Internet to enhance the model's ability in question generation.
[0026] Step 6 The steps are:
[0027] For the question-answering texts in the target domain, the Unilm language model with the last encoder module replaced and task pre-trained is used for training. The model decoding prediction results will be used to calculate the cross entropy with the questions given by the original training data, and the obtained gradient values will be used to optimize the model through the Adam optimizer. The inference idea mainly uses the beam search technology.
[0028] The beneficial effects of the present invention are:
[0029] The present invention proposes a unified pre-training method for Chinese question generation based on lattice and relative position embedding, which is based on Transformer and a domain dictionary of the target domain. The core of the model lies in the embedding of additional information such as lattice Embedding (domain vocabulary embedding) and relative position Embedding (relative position embedding) specially designed for the particularity of question generation. Domain pre-training and task pre-training are also applied to the model to enhance the model's inference ability in specific fields. Since the present invention adds the relative position information of each monad and domain vocabulary to the model input, the model can not only learn more positional relationships but also have better results in generating questions for the target domain input. Based on the same question and answer dataset, the model proposed by the present invention has better results. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 It is a flow chart of a unified pre-training method for generating Chinese questions based on word lattice and relative position embedding of the present invention.
[0031] Figure 2 This is the method for generating the domain dictionary in the present invention.
[0032] Figure 3 This is the method of embedding word grids by relative position coding and domain vocabulary in the present invention.
[0033] Figure 4 It is the Seq2Seq masking matrix M in step 3 of the present invention. DETAILED DESCRIPTION
[0034] The unified pre-training method for generating Chinese questions based on word lattice and relative position embedding of the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0035] like Figure 1 As shown,
[0036] Step 1: Pre-train Robert parameters in the domain
[0037] Specific steps 1.1: Acquisition of domain pre-training data;
[0038] In the domain pre-training, the initial parameters of the Transformer block of the model are taken from Robert, the basis of Wikipedia corpus training, and then the model is pre-trained on the domain information text crawled from the Internet. The pre-training uses Robert's bidirectional masking pre-training mechanism and full-word masking mechanism. The dictionary in the full-word masking uses a public open domain dictionary to meet the needs of pre-training. By using these two mechanisms, we have optimized the pre-processing of the model.
[0039] Specific steps 1.2: Robert's bidirectional masking pre-training mechanism
[0040] The model uses a bidirectional full-word mask prediction training mechanism, allowing the token to pay attention to the bidirectional text content before and after it. In order to adapt to Chinese question generation, full-word mask pre-training is used, because in Chinese, the meaning of a word as a whole and the meaning of two words when split into two words are completely different in some cases. This method can effectively encode contextual information, thereby generating contextual information representation. In specific implementation, the model randomly replaces characters or words with "[MASK]". The model randomly replaces 15% of the words in the sequence. Among them, 80% of the probability is replaced by "[MASK]", 10% of the probability is replaced by other characters or words, and 10% of the probability is not replaced.
[0041] The cross entropy loss function will calculate the loss of the predicted results and the original results, so as to train the optimal model parameters.
[0042] Step 2: Use a semi-supervised and semi-manual approach to quickly and accurately generate a dictionary for the target domain Specific steps 2.1: Named entity recognition to obtain a dictionary
[0043] Reference Figure 2 In order to obtain the target domain dictionary faster, the present invention uses a semi-supervised and semi-manual approach to speed up the dictionary generation efficiency. The target domain documents are manually selected, the target domain documents are input into the named entity recognition deep learning model, and the entities recognized by the model are added to the domain dictionary.
[0044] Specific steps 2.2: Obtaining dictionaries based on rules
[0045] Through a rule-based approach, a large-scale open domain dictionary is selected and indexed in the target domain text, and the words in the index are added to the target domain dictionary. Finally, the formed domain dictionary is manually reviewed to form the final domain vocabulary dictionary.
[0046] Step 3: Construct a special mask matrix to improve the generation ability of the model
[0047] During the training of the model, the original text and the target question are concatenated and then fed into the model for training. The tokens in the first half of the text can pay attention to the text in both the front and back directions, while the tokens in the second half can only pay attention to the text in the first half on the left. For example, given the sequence "[SOS]t1 t2 t3[EOS]t3 t4 t5", the three tokens t1 t2 t3 can only pay attention to the first five tokens, while t3 t4 t5 can pay attention to itself and all the token texts before it.
[0048] Reference Figure 4 The setting method of matrix M is shown. S1 represents the first half of the sentence after the input sequence is concatenated, and all elements are set to "0", which is used to indicate that it can be associated with all token information in the first half. S2 represents the second half of the sentence after the input sequence is concatenated, and the elements are set to "-∞", which is used to indicate that the second half can be associated with the information in the first half. In order to improve the text generation ability of the model, the S1 sequence in the matrix M is set to pay attention to both the previous and following information, and the S2 sequence is set to only pay attention to the previous information including itself. For the submatrix on the lower right, we set the upper triangular elements to "-∞" and the remaining elements to "0" to indicate that the text information after the current token cannot be paid attention to. The specially constructed mask matrix is added to the attention score matrix in the encoder part to enhance the generation ability of the model.
[0049] Step 4: Construct a special relative position embedding matrix to incorporate the relative position information of characters and words in the input into the Transformer layer according to the dictionary in step 2
[0050] Reference Figure 3 In this stage, the input sequence is compared with the instances of the domain dictionary to obtain the words contained in multiple input sequences. The head and tail indexes of these words in the input sequence are recorded separately. The head and tail indexes represent the starting and ending indexes of the word lexicon respectively; for a single word, its starting and ending indexes are the same.
[0051] "Relative position embedding" can add the position relationship between each token or word into the attention calculation, strengthening the attention mechanism in the transformer. Therefore, this model uses relative position encoding for each token and word in the task pre-training stage. At the same time, relative position encoding can clearly express the position information between each word.
[0052] Specifically, head[i] and tail[i] are the sp of the i-th span i The position information of the four relative position matrices is calculated as follows:
[0053]
[0054] in, Both represent the distance between the head entity and the tail entity span. The final relative position information is calculated as follows and activated by the activation function:
[0055]
[0056] where p d The calculation is based on the official absolute position embedding method of Bert. W is a learnable parameter. Represents the concatenation operation of the tensor. The embedding dimension of the calculated positional encoding will become [hiddenSize*hiddenSize], which represents the positional association information between tokens.
[0057] In order to enable the model to fully learn this correlation information, we use the self-attention mechanism in Transformer, which is defined as follows:
[0058]
[0059] Among them, all W represent weight matrices, and u and v are also learnable parameters. The final output represents the embedding tensor that incorporates the relative position information of the token.
[0060] Step 5: Create a new Transformer layer, inherit the parameters of the 12th layer of the Robert model, and perform task pre-training using a large amount of open domain question-answering data
[0061] In order to save computing resources and adapt to smaller data sets, it is necessary to adopt a migration scheme of the pre-trained model to provide sufficient commonly used encyclopedic knowledge information. Therefore, the present invention incorporates the 12th layer of the Transformer layer that inherits the Robert parameters of the encyclopedic knowledge training into the relative position encoding to migrate the encyclopedic knowledge.
[0062] Since this model has many parameters, task pre-training is added. The model is pre-trained on a large amount of open-domain question-answering data crawled from the Internet to enhance the model's ability in question generation.
[0063] All methods of the embodiment are tested on the PyTorch platform, and the GPU used for the test is GTX2080TI. In the pre-training process, the maximum sequence length is defined as 512. The parameters of the Adam optimizer are β1=0.9, β2=0.99, the learning rate is set to 1e-4, the dropout ratio is set to 0.1, the weight decay is set to 1e-3, the batch size is set to 2, and each scheme is trained for 200 epochs with a dynamic learning rate, and the dropout ratio is set to 0.2.
[0064] Step 6: Training and inference for the generation problem
[0065] For the question-answering text in the target domain, the Unilm model with relative position encoding and task pre-training is used for training. The model decoding prediction results will be used to calculate the cross entropy with the questions given by the original training data, and the obtained gradient values will be used to optimize the model through the Adam optimizer. The inference idea mainly adopts the beam search technology.
[0066] The present invention generates a unified pre-training method for Chinese questions based on word lattice and relative position embedding, which is different from the previous absolute position encoding and inputs more position information into the model. When calculating, the model not only knows the position relationship of characters with adjacent positions, but also knows the position relationship between each character and vocabulary. At the same time, domain pre-training and task pre-training are used, which improves the generation ability of the model in the target domain to a certain extent.
Claims
1. A unified pre-training method for Chinese question generation based on word lattice and relative position embedding, characterized in that: Domain pre-training and task pre-training are used, and a semi-supervised and semi-manual approach is used to generate domain dictionaries. In the task pre-training stage, the domain vocabulary index in the input is first recorded at the beginning and end of the position in the input sequence, and the indexed vocabulary is concatenated after the input sequence. Then, the relative position between each word and sub-word is recorded and input into the last self-built Transformer module in the Unilm model. Finally, the generated question is decoded by the decoder, which includes the following steps: Step 1: Perform domain pre-training on Roberta parameters. The specific steps are as follows: In the domain pre-training, the initial parameters of the Transformer block of the model are taken from Roberta, the basis of Wikipedia corpus training. Then the model is pre-trained on the domain information text crawled from the Internet. The pre-training uses Roberta's bidirectional masking pre-training mechanism and full-word masking mechanism. The dictionary in the full-word masking uses a public open domain dictionary to meet the needs of pre-training. By using these two mechanisms, we have optimized the pre-processing of the model; Step 2: Use a semi-supervised and semi-manual approach to quickly and accurately generate a dictionary for the target domain. The specific steps are as follows: In order to obtain the target domain dictionary more quickly, a semi-supervised and semi-manual method is used to speed up the dictionary generation efficiency. First, electronic documents in the target domain and large-scale dictionaries in the open domain are manually selected, and the target domain documents are input into the named entity recognition deep learning model. The entities recognized by the model are added to the domain dictionary. Then, the words in the large-scale open domain are indexed in the target domain text in a rule-based way, and the words in the index are added to the target domain dictionary. Finally, the formed domain dictionary is manually reviewed to form the final domain vocabulary dictionary. Step 3: Construct a special mask matrix to improve the generation ability of the model. The specific steps are: During the training process of the model, the original text and the target question are concatenated and then fed into the model for training. The tokens in the first half of the text can focus on the text in both the front and back directions, while the tokens in the second half can only focus on the first half of the text on the left. Step 4: Construct a special relative position embedding matrix to integrate the relative position information of characters and words in the input into the Transformer layer according to the dictionary in step 2. The specific steps are: "Relative position embedding" can add the position relationship between each word or vocabulary into the attention calculation, strengthening the attention mechanism in the transformer. Therefore, relative position encoding is used for each word and vocabulary in the task pre-training stage. At the same time, relative position encoding can clearly express the position information between each vocabulary. Step 5: The newly created Transformer layer inherits the parameters of the 12th layer of the Roberta model and performs task pre-training using a large amount of open domain question-answering data. The specific steps are as follows: In order to save computing resources and adapt to smaller manually annotated data sets, it is necessary to adopt a migration scheme of pre-trained models to provide sufficient common encyclopedic knowledge and domain information. Therefore, the Transformer layer that incorporates word lattice and relative position encoding inherits the last layer of Roberta parameters pre-trained in the domain in step 1 to migrate encyclopedic knowledge and domain knowledge. Since this model has many parameters and there is often little manually annotated question-answering data, we added task pre-training. We used a large amount of open-domain question-answering data crawled from the Internet to pre-train the model and enhance the model's ability in question generation. Step 6, training and inference of the generation problem.
2. The unified pre-training method for generating Chinese questions based on word lattice and relative position embedding according to claim 1, characterized in that: The specific steps of step 6 are: For the question-and-answer text in the target domain, the Unilm language model with the last layer encoder module replaced and task pre-training is used for training. The results of model decoding prediction will be used to calculate the cross entropy with the questions given by the original training data. The obtained gradient value will be used to optimize the model through the Adam optimizer. The inference idea mainly uses the beam search technology.
Citation Information
Patent Citations
Text classification method for open network questions in specific field
CN111046179A
Language generation method and device, computer equipment and storage medium
CN111274764A
Problem generation model training method, problem generation method and related equipment thereof
CN111639163A
BERT-FLAT-based Chinese named entity recognition method
CN112270193A
Automatic question setting method and device based on text and computer equipment
CN112487139A
