Model training method and device and storage medium
By constructing prompt texts corresponding to question words and training the answer selection model and question generation model, the problem in the existing technology that the answer selection model is difficult to capture the value of the question and lacks answer type information is solved, the correlation between the answer and the question is improved, and the Question answer to performance.
Patent Information
- Application Number
- CN202310347623.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-03
- Publication Date
- 2024-10-15
AI Technical Summary
During the training process of the existing question generation system, the answer selection model is difficult to capture the characteristics of the value of the question, and the question generation model lacks answer type information, resulting in insufficient correlation between the selected answer and the generated question.
By constructing the first prompt text and the second prompt text corresponding to the question word, it is used to train the answer selection model and the question generation model, ensuring that the answer selection model outputs a specific type of potential answer, and passing the question word and its interpretation to the question generation model , to improve the relevance of the answer to the question.
Improved correlation between the answers selected by the answer selection model and the questions generated by the question generation model improves the performance of question-answer pairs.
Smart Images

Figure CN118779647A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of machine learning and natural language processing (NLP), and in particular to a model training method, device and storage medium. Background Art
[0002] Question generation technology is an important technology in the field of natural language processing. The goal of question generation is to generate several questions related to a user-specified article and indicate the answers to these questions in the article. Question generation technology is widely used in question-answering systems and search engines to automatically generate a combination of questions and answers, namely, question-answer pairs (sometimes referred to as question-answer pairs in this article). Question-answering systems and search engines require a large number of question-answer pairs. In question-answering systems, one of the automatic question-answering methods is to use a similarity algorithm to match user questions with pre-built question-answer pairs in the database to obtain answers; on the other hand, search engines use machine reading comprehension models to find accurate answers to user questions from retrieved articles, but machine reading comprehension models require a large number of question-answer pairs for training. Building these question-answer pairs requires a lot of time and manpower, and sometimes requires the annotation personnel to have certain field expertise. Question generation technology can greatly reduce the construction cost of question-answering systems and search engines by automatically generating question-answer pairs.
[0003] At present, mainstream question generation systems often include an answer selection model and a question generation model, wherein the answer selection model can select potential answers from the text, and the question generation model can generate relevant questions based on the text and the potential answers selected by the answer selection model. A question generation scheme in the prior art generates several key phrases (potential answers) by training an answer selection model (sequence-to-sequence model). The answer selection model learns to assign higher probabilities to potential answers from the manually selected answers of a large-scale question-answering dataset (SQuAD). In addition, the scheme provides a question generation model, which generates questions based on the selected potential answers. The scheme has the following limitations: during the training process, the answer selection model learns to select all types of potential answers in the article at the same time, which makes it difficult for the model to capture the characteristics of the question value. In addition, after selecting the answer, the question generation model does not obtain any additional information (such as the answer type) from the answer selection model to help generate questions, which may cause the question generation model to generate questions that are not related to the selected answer.
[0004] Therefore, a question generation scheme that can improve the relevance between the selected answers and the generated questions is urgently needed. Summary of the invention
[0005] At least one embodiment of the present application provides a model training method, device and storage medium, which can improve the correlation between the answer selected by the answer selection model and the question generated by the question generation model.
[0006] Improve the accuracy of semantic matching tasks.
[0007] In order to solve the above technical problems, this application is implemented as follows:
[0008] In a first aspect, an embodiment of the present application provides a model training method, comprising:
[0009] According to the interrogative word and its interpretation in the target language, construct a first prompt text and a second prompt text corresponding to the interrogative word, wherein the first prompt text is used to prompt selection of a potential answer to a question containing the interrogative word, and the second prompt text is used to prompt generation of a question containing the interrogative word;
[0010] Acquire multiple original training samples, each of which includes a text sample, a question sample, and an answer sample corresponding to the question sample, wherein the question sample contains a question word;
[0011] For each original training sample, a first training sample is constructed by using the text sample, the answer sample, and the first prompt text corresponding to the question word in the question sample of the original training sample to obtain a first training set including a plurality of the first training samples; and a second training sample is constructed by using the text sample, the question sample, the answer sample, and the second prompt text corresponding to the question word in the question sample of the original training sample to obtain a second training set including a plurality of the second training samples;
[0012] Using the first training set, an answer selection model is trained, and using the second training set, a question generation model is trained.
[0013] Optionally, the first training set further includes at least one third training sample, and the third training sample is constructed in the following manner:
[0014] For a first text sample, determining a first question word that is not included in all question samples corresponding to the first text sample;
[0015] The third training sample is constructed by using the first prompt text corresponding to the first question word, the blank answer and the first text sample.
[0016] Optionally, using the first training set to train an answer selection model, and using the second training set to train a question generation model, includes:
[0017] Inputting the first prompt text and text sample of each training sample in the first training set into the answer selection model, training the answer selection model with the goal of outputting the corresponding answer sample by the answer selection model, and obtaining the trained answer selection model;
[0018] The second prompt text, text sample and answer sample of each training sample in the second training set are input into the question generation model, and the question generation model is trained with the goal of outputting the corresponding question sample from the question generation model to obtain the trained question generation model.
[0019] Optionally, the above method further includes:
[0020] For the target text, selecting a second question word from the question words in the target language;
[0021] Inputting the first prompt text and the target text corresponding to the second question word into the answer selection model to obtain the target answer output by the answer selection model;
[0022] The second prompt text corresponding to the second question word, the target text and the target answer are input into the question generation model to obtain the target question output by the question generation model.
[0023] Optionally, the first prompt text and the second prompt text corresponding to the question word both include the question word and the interpretation of the question word.
[0024] Optionally, the answer selection model is a natural language understanding model, and the question generation model is a natural language generation model.
[0025] In a second aspect, an embodiment of the present application provides a model training device, comprising:
[0026] A first construction module is used to construct a first prompt text and a second prompt text corresponding to the question word according to the question word and its interpretation in the target language, wherein the first prompt text is used to prompt the selection of a potential answer to the question containing the question word, and the second prompt text is used to prompt the generation of the question containing the question word;
[0027] A first acquisition module is used to acquire multiple original training samples, each of which includes a text sample, a question sample, and an answer sample corresponding to the question sample, wherein the question sample contains a question word;
[0028] A second construction module is used to construct a first training sample for each original training sample by using the text sample, the answer sample, and the first prompt text corresponding to the question word in the question sample of the original training sample to obtain a first training set including a plurality of the first training samples; and to construct a second training sample by using the text sample, the question sample, the answer sample, and the second prompt text corresponding to the question word in the question sample of the original training sample to obtain a second training set including a plurality of the second training samples;
[0029] The training module is used to train an answer selection model using the first training set, and to train a question generation model using the second training set.
[0030] Optionally, the first training set further includes at least one third training sample, and the device further includes:
[0031] The third construction module is used to construct the third training sample in the following manner:
[0032] For a first text sample, determining a first question word that is not included in all question samples corresponding to the first text sample;
[0033] The third training sample is constructed by using the first prompt text corresponding to the first question word, the blank answer and the first text sample.
[0034] Optionally, the training module is further used to:
[0035] Inputting the first prompt text and text sample of each training sample in the first training set into the answer selection model, training the answer selection model with the goal of outputting the corresponding answer sample by the answer selection model, and obtaining the trained answer selection model;
[0036] The second prompt text, text sample and answer sample of each training sample in the second training set are input into the question generation model, and the question generation model is trained with the goal of outputting the corresponding question sample from the question generation model to obtain the trained question generation model.
[0037] Optionally, the above device further comprises:
[0038] The model application module is used to select a second question word from the question words in the target language for a target text; input a first prompt text corresponding to the second question word and the target text into the answer selection model to obtain a target answer output by the answer selection model; input a second prompt text corresponding to the second question word, the target text and the target answer into the question generation model to obtain a target question output by the question generation model.
[0039] Optionally, the first prompt text and the second prompt text corresponding to the question word both include the question word and the interpretation of the question word.
[0040] Optionally, the answer selection model is a natural language understanding model, and the question generation model is a natural language generation model.
[0041] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, on which a program is stored. When the program is executed by a processor, the steps of the method described above are implemented.
[0042] Compared with the prior art, the model training method and device provided in the embodiments of the present application use the first prompt text and text sample corresponding to the question word as the input of the answer selection model during the model training process, so that the answer selection model outputs a specific type of potential answer. In addition, the second prompt text, text sample and answer sample corresponding to the question word are used as the input of the question generation model, so that the answer selection model and the question generation model are associated through the prompt text containing the same question word and its interpretation, thereby improving the relevance of the selected answer and the generated question, and thus improving the performance of the question-answer pairs generated by the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0044] Figure 1 A flow chart of the model training method of an embodiment of the present application;
[0045] Figure 2 An example diagram of a construction prompt text in an embodiment of the present application;
[0046] Figure 3 This is an example diagram of using a prompt template;
[0047] Figure 4 An example diagram of constructing a prompt text for a question sample in an embodiment of the present application;
[0048] Figure 5 An example diagram of an answer selection model trained using a first training sample in an embodiment of the present application;
[0049] Figure 6 An example diagram of a model generated by using a second training sample to train a problem in an embodiment of the present application;
[0050] Figure 7 A schematic diagram of the structure of a model training device according to an embodiment of the present application;
[0051] Figure 8 Another structural schematic diagram of the model training device according to an embodiment of the present application. DETAILED DESCRIPTION
[0052] In order to make the technical problems, technical solutions and advantages to be solved by the application clearer, the following will be described in detail in conjunction with the accompanying drawings and specific embodiments. In the following description, specific details such as specific configurations and components are provided only to help fully understand the embodiments of the application. Therefore, it should be clear to those skilled in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the application. In addition, for clarity and brevity, the description of known functions and structures has been omitted.
[0053] It should be understood that the "one embodiment" or "an embodiment" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in one embodiment" appearing throughout the specification may not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described here can be implemented in an order other than those illustrated or described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices. "And / or" in the specification and claims represents at least one of the connected objects.
[0054] In the various embodiments of the present application, it should be understood that the size of the serial numbers of the following processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0055] The question generation system usually includes an answer selection model and a question generation model. Related research attempts to improve the performance of question generation in the following two aspects. One is whether the answer selected by the answer selection model is more valuable to ask questions, and the other is whether the question generated by the question generation model is relevant to the selected answer. For example, a related technical solution uses an external parser to parse out entities (such as time, people, etc.) in the text and the relationship between them, and selects the entity with the largest number of relationships with other entities as potential answers. Next, these potential answers and their entity types are input into the question generation model together to generate questions. In the above scheme, entity types can be used to help the question generation model generate questions that are more relevant to the entity as the answer, but this scheme is highly dependent on the performance of the external parser and cannot select words outside the scope of named entities as potential answers. For example, in English, it is impossible to select "take a nap" as a verb phrase that is not a named entity as a potential answer. There are also some related schemes that select potential answers by training a neural network-based answer selection model. Although these schemes can select phrases as answers, the answer selection model does not pass any additional information to the subsequent question generation model. In addition, it is difficult for question generation models to capture the characteristics of question value from various types of potential answers.
[0056] In order to improve the relevance of the selected answer and the generated question and improve the performance of the generated question-answer pair, the embodiment of the present application provides a model training method, such as Figure 1 As shown, the method includes:
[0057] Step 11, based on the question words and their definitions in the target language, construct a first prompt text and a second prompt text corresponding to the question words, wherein the first prompt text is used to prompt the selection of potential answers for the question containing the question words, and the second prompt text is used to prompt the generation of the question containing the question words.
[0058] Here, the target language can be a natural language such as Chinese, English or Japanese. This article will mainly use English as an example for explanation. In natural languages, there are usually question words. Taking English as an example, question words include "who", "when", "where", "how much", "how long", etc.; taking Chinese as an example, question words include: "who", "when", "where", "why", etc. The interpretation of each question word can be obtained by querying relevant dictionaries (such as the Oxford Dictionary) or encyclopedias (such as Wikipedia), and this embodiment of the application does not specifically limit this.
[0059] Specifically, all the question words in the target language collected manually in advance can be obtained, and all the question words can be matched with the question samples in the original training set including multiple original training samples, and the question words that have appeared in the question samples in the original training set can be retained. Then, for each retained question word, its definition can be obtained by looking up a dictionary or encyclopedia. For example, the definition of "when" is "the time at which something happens".
[0060] For each question word, a first prompt text (answer selection prompt text) and a second prompt text (question generation prompt text) corresponding to the question word can be constructed based on the question word and its definition, wherein the first prompt text is used to prompt the selection of potential answers for the question containing the question word. Specifically, the first prompt text corresponding to the question word contains the question word and the definition of the question word. The second prompt text is used to prompt the generation of a question containing the question word. The second prompt text corresponding to the question word also contains the question word and the definition of the question word. In this way, the embodiment of the present application can generate a first prompt text and a second prompt text corresponding to the same question word for each question word.
[0061] The following uses English as an example to provide a specific example of constructing prompt text.
[0062] In this example, the first prompt template and the second prompt template are pre-built. Herein, the first prompt template is sometimes referred to as an answer selection prompt template, and the second prompt template is sometimes referred to as a question generation prompt template.
[0063] The first prompt template is a prompt text, which has two blank positions corresponding to the interrogative word and the interpretation of the interrogative word. The prompt text is used to prompt the selection of potential answers for the question containing the interrogative word. When generating the first prompt text corresponding to a certain interrogative word, the interrogative word and its interpretation are respectively filled into the corresponding blank positions in the first prompt template, so as to obtain the first prompt text.
[0064] The second prompt template is also a prompt text, which also has two blank positions, corresponding to the interrogative word and the interpretation of the interrogative word. The prompt text is used to prompt the generation of a question containing the interrogative word. When generating the second prompt text corresponding to a certain interrogative word, the interrogative word and its interpretation are respectively filled into the corresponding blank positions in the second prompt template, thereby obtaining the second prompt text.
[0065] For example, the first prompt template (answer selection prompt template) may specifically be:
[0066] Find a text to answer a question which asks about.
[0067] Among them, the blank space corresponding to the first underline is used to fill in the question word, and the blank space corresponding to the second underline is used to fill in the interpretation of the question word.
[0068] The second prompt template (prompt template for generating questions) may specifically be:
[0069] Ask a question which asks about.
[0070] Take the interrogative word "When" as an example. The definition of "When" is "the time at which something happens". Fill "When" and its definition into the above template, and you will get the following: Figure 2 The first prompt text and the second prompt text shown are both prompt texts corresponding to the question word “When”, so there is a one-to-one correspondence between the two prompt texts.
[0071] It should also be noted that the above is only an example of a prompt template / prompt text that can be used in the embodiment of the present application. The embodiment of the present application can also use other forms of prompt templates / prompt texts. For example, the first prompt template can also be any of the following forms:
[0072] Select an answer to question which is about.
[0073] Choose an answer to question which is about.
[0074] The second prompt template can also be any of the following forms:
[0075] Generate a question which is about.
[0076] Provide a question which is about.
[0077] Step 12, obtaining a plurality of original training samples, each of which includes a text sample, a question sample, and an answer sample corresponding to the question sample, wherein the question sample contains a question word.
[0078] Here, an original data set is obtained, and the original data set includes multiple original training samples. Usually, a training sample includes: a text sample, one or more questions, and the answer corresponding to each question. For ease of processing, for a training sample containing multiple questions and answers, it can be split into multiple original training samples, so that each original training sample only includes one question and its answer. In this way, each original training sample includes a text sample, a question sample and an answer sample corresponding to the question sample. The text sample can be an article, the question sample is a question provided for the article, and the answer sample is the answer to the question. Usually, the answer sample is part of the text in the article, that is, a substring of the article text.
[0079] In the embodiments of the present application, the original training sample refers to any machine reading comprehension data set, such as the SQuAD1.1 data set disclosed by Stanford University. Each training data in the data set is manually annotated, and each training data includes: an article, several questions related to the article, and their corresponding answers (the answers are all substrings of the article). An article, a question related to the article, and the answer corresponding to the question can be used as a training sample for the answer selection model and the question generation model. These articles, questions, and answers can be obtained during the training process of the answer selection model and the question generation model, but they are input into the model in different ways: for the training of the answer selection model, the answer is used as the training target, and the article and question are used as input; for the training of the question generation model, the question is used as the training target, and the article and answer are used as input.
[0080] Step 13, for each original training sample, a first training sample is constructed using the text sample, answer sample, and first prompt text corresponding to the question word in the question sample of the original training sample to obtain a first training set including multiple first training samples; and a second training sample is constructed using the text sample, question sample, answer sample, and second prompt text corresponding to the question word in the question sample of the original training sample to obtain a second training set including multiple second training samples.
[0081] Many pre-trained language models, such as the Bidirectional Encoder Representation from Transformer (BERT) model and the T5 model, have excellent performance in most natural language processing tasks and can receive a sentence as a prompt to guide the model to complete the specified task. Figure 3As shown, after the prompt sentence "translate English to German" is connected with the target English sentence to be translated and input into the T5 model, the T5 model can output the German translation of the target English sentence. Based on this, the embodiment of the present application proposes a prompt-driven question generation related model training method, and both the answer selection model and the question generation model use the prompt mechanism. Specifically, by introducing the prompt text (prompt text), a new training sample is reconstructed based on the original training sample to train the related model.
[0082] Specifically, the embodiment of the present application incorporates information about question words and their definitions into the prompt text. The question words and their definitions can reflect the type information of potential answers. For example, for the question word "when", its potential answer is of time type, and for the question word "where", its potential answer is of location type. The embodiment of the present application incorporates the type information of potential answers into the prompt text. On the one hand, the prompt text inputs the answer type information as a prompt into the answer selection model, so that it only outputs a specific type of potential answer each time, which enables the model to better capture the "question value" feature; on the other hand, the prompt text also passes the same answer type information to the question generation model, thereby linking the two models, so that the question generation model can generate questions that are more relevant to the selected potential answer.
[0083] When constructing training samples, the embodiment of the present application can construct a first training sample corresponding to each original training sample. Specifically, a first training sample can be constructed using the text sample, answer sample, and first prompt text corresponding to the interrogative word in the question sample of the original training sample. In this way, multiple first training samples can be obtained for multiple original training samples, thereby obtaining a first training set. Similarly, a second training sample can be constructed for each original training sample. Specifically, a second training sample can be constructed using the text sample, question sample, answer sample, and second prompt text corresponding to the interrogative word in the question sample of the original training sample. In this way, multiple second training samples can be obtained for multiple original training samples, thereby obtaining a second training set.
[0084] Assume that the question sample in an original training sample is "When were the Normans in Normandy?", and the question word is "When", then for the question word "When", we can construct the following Figure 4 The two prompt texts shown in the figure are used to obtain a first training sample and a second training sample, wherein the first training sample includes Figure 4The first prompt text in the original training sample, the text sample and the answer sample, the second training sample includes Figure 4 The second prompt text in , the text sample of the original training sample, the question sample and the answer sample.
[0085] Step 14: using the first training set to train an answer selection model, and using the second training set to train a question generation model.
[0086] In an embodiment of the present application, the answer selection model is a natural language understanding model, which can specifically be any one of the following models: BERT, RoBERTa, ALBERT, ERNIE, ELECTRA and other models. The answer selection model can use a pre-trained language model such as BERT as the basic architecture. For example, a pre-trained language model such as BERT is pre-trained by large-scale corpus based on the Transformer model architecture, and can realize natural language processing tasks such as answer selection. The question generation model is a natural language generation model, which can specifically be any one of the following models: T5 model, GPT, BART and other models. For example, the question generation model can use the T5 model as the basic architecture. The T5 model is pre-trained based on the encoder-decoder architecture of Transformer and has text generation capabilities.
[0087] Here, when training the answer selection model, the first prompt text and text sample of each first training sample in the first training set are input into the answer selection model, the first prompt text contains the question words in the question sample, and the answer selection model is trained with the goal of outputting the corresponding answer sample to obtain the trained answer selection model.
[0088] Figure 5 An example of training an answer selection model using a first training sample is provided, where the input of the answer selection model is a first prompt text and a text sample in the first training sample, and the training target is an answer sample in the first training sample output by the model. Figure 5 The answer generation model in is a pre-trained language model such as BERT, which pairs the first prompt text with the text sample to generate the answer. Figure 5 The input is constructed in the form of and input to the answer selection model, that is, with a special separator " <sep>", the first prompt text is connected with the text sample as the input of the answer selection model. This input method is determined by the input method of the BERT model during pre-training. Figure 5 For example,
[0089] The first prompt is: Find a text to answer a "when" question which asks about the time at which something happens.
[0090] The text sample is: The Normans (Norman: Nourmands; French: Normands; Latin: Normanni) were the people who in the 10th and 11th centuries gave their name to Normandy, a region in France… The distinct cultural and ethnic identity of the Normans emerged initially in the first half of the 10th century, and it continued to evolve over the succeeding centuries.
[0091] Sample answers include: in the first half of the 10th century or in the 10th and 11th centuries.
[0092] That is, during the training of the answer selection model, the first prompt text and the text sample in the first training sample are input into the answer selection model, the answer selection model selects a text from the text sample as the answer text and outputs it, calculates the similarity between the answer text output by the answer selection model and the answer sample in the first training sample, and optimizes the model parameters of the answer selection model based on the similarity, so that the answer text output by the answer selection model is closer to the answer sample. Through the above optimization process, a trained answer selection model is finally obtained.
[0093] When training the question generation model, the second prompt text, text sample and answer sample of each second training sample in the second training set are input into the question generation model, and the question generation model is trained with the goal of outputting the corresponding question sample from the question generation model to obtain the trained question generation model.
[0094] Figure 6 An example of using a second training sample to train a problem generation model is provided. Figure 6 The answer sample, the second prompt text and the text sample are used to form a triplet. Figure 6 The input is constructed in the input method shown and input to the question generation model. This input method is determined by the T5 model as the basic architecture of the question generation model. Among them, "Prompt:" is added to the second prompt text as a prefix, and "Paragraph:" is added to the text sample as a prefix, and then the two are connected. The answer sample is implicitly input, that is, in XML format ( <answer> and< / answer> ) Mark the answer in the text sample (such as the underlined text in Figure 6). Figure 6 For example,
[0095] The second prompt text is: Ask a "when" question which asks about the time at something happens.
[0096] The text sample is: The Normans (Norman: Nourmands; French: Normands; Latin: Normanni) were the people who in the 10th and 11th centuries gave their name to Normandy, a region in France… The distinct cultural and ethnic identity of the Normans emerged initially in the first half of the 10th century, and it continued to evolve over the succeeding centuries.
[0097] Sample answer: in the 10th and 11th centuries.
[0098] A sample question is: When were the Normans in Normandy?
[0099] That is, during the question generation model training process, the second prompt text, text sample and question sample in the second training sample are input into the question generation model, the question generation model generates a text as the question text and outputs it, the similarity between the question text output by the question generation model and the question sample in the second training sample is calculated, and the model parameters of the question generation model are optimized based on the similarity, so that the question text output by the question generation model is closer to the question sample. Through the above optimization process, a trained question generation model is finally obtained.
[0100] Through the above steps, in the model training process, the embodiment of the present application uses the first prompt text and text sample corresponding to the question word as the input of the answer selection model, so that the answer selection model outputs a specific type of potential answer. In addition, the second prompt text, text sample and answer sample corresponding to the question word are used as the input of the question generation model, so that the answer selection model and the question generation model are associated through the prompt text containing the same question word and its interpretation, so that the question generation model can generate questions that are more relevant to the selected potential answer, thereby improving the performance of the question-answer pairs generated by the above model.
[0101] The first training sample generated in the above step 13 is a positive training sample, that is, the answer to the question exists in the text sample. Considering that for some questions with certain question words, the answers to these questions may not exist in the text sample, therefore, when the embodiment of the present application further generates the first training set, at least one third training sample (negative training sample) is added to the first training set. Specifically, for a certain text sample in the original training sample (for the convenience of description, it is referred to as the first text sample here), determine the first question word that is not included in all the question samples corresponding to the first text sample. Here, the first question word can be present in all the question words of the target language, but not in all the question samples corresponding to the first text sample. The first question word can also be present in the question sample of the original training set, but not in all the question samples corresponding to the first text sample. Then, the first prompt text corresponding to the first question word, the blank answer and the first text sample are used to construct a third training sample. For example, the blank answer is "None" (empty, as an answer).
[0102] For example, suppose that there are three original training samples in all original training samples, all of which include the same text sample x, as follows:
[0103] Original training sample a: text sample x, question 1 (including question word 1), answer 1;
[0104] Original training sample b: text sample x, question 2 (including question word 2), answer 2;
[0105] Original training sample c: text sample x, question 3 (including question word 3), answer 3;
[0106] Assuming that there are 5 question words, namely question words 1 to 5, it can be seen that the question words that are not included in all question samples corresponding to the same text sample x are question words 4 and 5. Therefore, the following two third training samples (negative training samples) can be generated:
[0107] The third training sample 1: text sample x, the first prompt text corresponding to question word 4, and the answer (None);
[0108] The third training sample 2: text sample x, the first prompt text corresponding to question word 5, and the answer (None).
[0109] The ratio of positive and negative samples in the first training set can be obtained by training multiple answer selection models using different ratios, and according to the performance of the answer selection model, the ratio used by the answer selection model with the best performance indicator is selected as the final ratio.
[0110] Through the above step 14, the embodiment of the present application can obtain a trained answer selection model and a question generation model. After this, the embodiment of the present application can also use the above model to generate a question-answer pair for the target text. The target text can be a piece of text input by a user. Specifically, the embodiment of the present application can select a question word from the question words in the target language (for the convenience of description, referred to as the second question word). Then, the first prompt text and the target text corresponding to the second question word are input into the answer selection model to obtain the answer output by the answer selection model (for the convenience of description, referred to as the target answer here). Then, the second prompt text, the target text and the target answer corresponding to the second question word are input into the question generation model to obtain the target question output by the question generation model, thereby obtaining a set of question-answer pairs consisting of the target question and the target answer. In the above process, the generation method of the first prompt text and the second prompt text is the same as in the model training process. The above process can also refer to Figure 5-Figure 6 ,at this time Figure 5 and Figure 6 The text sample in is replaced with the target text. In the above manner, one or more question words can be used to obtain one or more question-answer pairs of the target text.
[0111] Based on the above method, the present application also provides a device for implementing the above method. Figure 7 , the embodiment of the present application provides a model training device, comprising:
[0112] A first construction module 71 is used to construct a first prompt text and a second prompt text corresponding to the question word according to the question word and its interpretation in the target language, wherein the first prompt text is used to prompt the selection of a potential answer to the question containing the question word, and the second prompt text is used to prompt the generation of the question containing the question word;
[0113] A first acquisition module 72 is used to acquire a plurality of original training samples, each of which includes a text sample, a question sample, and an answer sample corresponding to the question sample, wherein the question sample contains a question word;
[0114] The second construction module 73 is used to construct a first training sample for each original training sample by using the text sample, the answer sample, and the first prompt text corresponding to the question word in the question sample of the original training sample to obtain a first training set including multiple first training samples; and to construct a second training sample by using the text sample, the question sample, the answer sample, and the second prompt text corresponding to the question word in the question sample of the original training sample to obtain a second training set including multiple second training samples;
[0115] The training module 74 is used to train an answer selection model using the first training set, and to train a question generation model using the second training set.
[0116] Through the above modules, the embodiment of the present application can improve the relevance between the answers selected by the trained model and the generated questions.
[0117] Optionally, the first training set further includes at least one third training sample, and the apparatus further includes:
[0118] The third construction module is used to construct the third training sample in the following manner:
[0119] For a first text sample, determining a first question word that is not included in all question samples corresponding to the first text sample;
[0120] The third training sample is constructed by using the first prompt text corresponding to the first question word, the blank answer and the first text sample.
[0121] Optionally, the training module 74 is further used to:
[0122] Inputting the first prompt text and text sample of each training sample in the first training set into the answer selection model, training the answer selection model with the goal of outputting the corresponding answer sample by the answer selection model, and obtaining the trained answer selection model;
[0123] The second prompt text, text sample and answer sample of each training sample in the second training set are input into the question generation model, and the question generation model is trained with the goal of outputting the corresponding question sample from the question generation model to obtain the trained question generation model.
[0124] Optionally, the above device further comprises:
[0125] The model application module is used to select a second question word from the question words in the target language for a target text; input a first prompt text corresponding to the second question word and the target text into the answer selection model to obtain a target answer output by the answer selection model; input a second prompt text corresponding to the second question word, the target text and the target answer into the question generation model to obtain a target question output by the question generation model.
[0126] Optionally, the first prompt text and the second prompt text corresponding to the question word both include the question word and the interpretation of the question word.
[0127] Optionally, the answer selection model is a natural language understanding model, and the question generation model is a natural language generation model.
[0128] Please refer to Figure 8 , the embodiment of the present application also provides a hardware structure block diagram of the model training device, such as Figure 8 As shown, the model training device 800 includes:
[0129] Processor 802; and
[0130] a memory 804 in which computer program instructions are stored,
[0131] When the computer program instructions are executed by the processor, the processor 802 is caused to perform the following steps:
[0132] According to the interrogative word and its interpretation in the target language, construct a first prompt text and a second prompt text corresponding to the interrogative word, wherein the first prompt text is used to prompt selection of a potential answer to a question containing the interrogative word, and the second prompt text is used to prompt generation of a question containing the interrogative word;
[0133] Acquire multiple original training samples, each of which includes a text sample, a question sample, and an answer sample corresponding to the question sample, wherein the question sample contains a question word;
[0134] For each original training sample, a first training sample is constructed by using the text sample, the answer sample, and the first prompt text corresponding to the question word in the question sample of the original training sample to obtain a first training set including a plurality of the first training samples; and a second training sample is constructed by using the text sample, the question sample, the answer sample, and the second prompt text corresponding to the question word in the question sample of the original training sample to obtain a second training set including a plurality of the second training samples;
[0135] Using the first training set, an answer selection model is trained, and using the second training set, a question generation model is trained.
[0136] Furthermore, if Figure 8 As shown, the model training device 800 also includes a network interface 801, an input device 803, a hard disk 805, and a display device 806.
[0137] The above-mentioned interfaces and devices can be interconnected through a bus architecture. The bus architecture can be a bus and bridge that can include any number of interconnected buses. Specifically, one or more central processing units (CPUs) and / or graphics processing units (GPUs) represented by processor 802, and various circuits of one or more memories represented by memory 804 are connected together. The bus architecture can also connect various other circuits such as peripheral devices, voltage regulators, and power management circuits together. It can be understood that the bus architecture is used to achieve connection and communication between these components. In addition to the data bus, the bus architecture also includes a power bus, a control bus, and a status signal bus, which are all well known in the art, so they are not described in detail herein.
[0138] The network interface 801 can be connected to a network (such as the Internet, a local area network, etc.), receive data such as original training samples from the network, and can save the received data in the hard disk 805.
[0139] The input device 803 can receive various instructions input by the operator and send them to the processor 802 for execution. The input device 803 can include a keyboard or a pointing device (for example, a mouse, a trackball, a touch pad or a touch screen, etc.).
[0140] The display device 806 can display the results obtained by the processor 802 executing instructions, such as displaying the model training progress.
[0141] The memory 804 is used to store programs and data necessary for the operation of the operating system, as well as data such as intermediate results during the calculation process of the processor 802.
[0142] It is understood that the memory 804 in the embodiment of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM) or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. The memory 804 of the apparatus and method described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0143] In some implementations, the memory 804 stores the following elements, executable modules or data structures, or a subset thereof, or an extended set thereof: an operating system 8041 and an application program 8042 .
[0144] The operating system 8041 includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic services and process hardware-based tasks. The application program 8042 includes various application programs, such as a browser, etc., which are used to implement various application services. The program for implementing the method of the embodiment of the present application can be included in the application program 8042.
[0145] The method disclosed in the above embodiment of the present application can be applied to the processor 802, or implemented by the processor 802. The processor 802 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 802. The above processor 802 can be a general processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, and can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application. The general processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to perform, or the hardware and software modules in the decoding processor are combined and performed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 804, and the processor 802 reads the information in the memory 804 and completes the steps of the above method in combination with its hardware.
[0146] It is understood that the embodiments described herein can be implemented in hardware, software, firmware, middleware, microcode or a combination thereof. For hardware implementation, the processing unit can be implemented in one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), general purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described in the present application or a combination thereof.
[0147] For software implementation, the techniques described herein can be implemented by modules (e.g., procedures, functions, etc.) that perform the functions described herein. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.
[0148] Specifically, the first training set further includes at least one third training sample, and when the computer program is executed by the processor 802, the following steps may be further implemented:
[0149] The third training sample is constructed in the following manner:
[0150] For a first text sample, determining a first question word that is not included in all question samples corresponding to the first text sample;
[0151] The third training sample is constructed by using the first prompt text corresponding to the first question word, the blank answer and the first text sample.
[0152] Specifically, when the computer program is executed by the processor 802, the following steps may also be implemented:
[0153] Inputting the first prompt text and text sample of each training sample in the first training set into the answer selection model, training the answer selection model with the goal of outputting the corresponding answer sample by the answer selection model, and obtaining the trained answer selection model;
[0154] The second prompt text, text sample and answer sample of each training sample in the second training set are input into the question generation model, and the question generation model is trained with the goal of outputting the corresponding question sample from the question generation model to obtain the trained question generation model.
[0155] Specifically, when the computer program is executed by the processor 802, the following steps may also be implemented:
[0156] For the target text, selecting a second question word from the question words in the target language;
[0157] Inputting the first prompt text and the target text corresponding to the second question word into the answer selection model to obtain the target answer output by the answer selection model;
[0158] The second prompt text corresponding to the second question word, the target text and the target answer are input into the question generation model to obtain the target question output by the question generation model.
[0159] Optionally, the first prompt text and the second prompt text corresponding to the question word both include the question word and the interpretation of the question word.
[0160] Optionally, the answer selection model is a natural language understanding model, and the question generation model is a natural language generation model.
[0161] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0162] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0163] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0164] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of the present application.
[0165] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0166] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard drives, ROM, RAM, magnetic disks, or optical disks.
[0167] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.< / sep>
Claims
1. A model training method, It is characterized in that include: According to the interrogative word and its interpretation in the target language, construct a first prompt text and a second prompt text corresponding to the interrogative word, wherein the first prompt text is used to prompt selection of a potential answer to a question containing the interrogative word, and the second prompt text is used to prompt generation of a question containing the interrogative word; Acquire multiple original training samples, each of which includes a text sample, a question sample, and an answer sample corresponding to the question sample, wherein the question sample contains a question word; For each original training sample, a first training sample is constructed by using the text sample, the answer sample, and the first prompt text corresponding to the question word in the question sample of the original training sample to obtain a first training set including a plurality of the first training samples; and a second training sample is constructed by using the text sample, the question sample, the answer sample, and the second prompt text corresponding to the question word in the question sample of the original training sample to obtain a second training set including a plurality of the second training samples; Using the first training set, an answer selection model is trained, and using the second training set, a question generation model is trained.
2. The method according to claim 1, It is characterized in that The first training set also includes at least one third training sample, and the third training sample is constructed in the following manner: For a first text sample, determining a first question word that is not included in all question samples corresponding to the first text sample; The third training sample is constructed by using the first prompt text corresponding to the first question word, the blank answer and the first text sample.
3. The method according to claim 1 or 2, It is characterized in that The step of training an answer selection model using the first training set and training a question generation model using the second training set includes: Inputting the first prompt text and text sample of each training sample in the first training set into the answer selection model, training the answer selection model with the goal of outputting the corresponding answer sample by the answer selection model, and obtaining the trained answer selection model; The second prompt text, text sample and answer sample of each training sample in the second training set are input into the question generation model, and the question generation model is trained with the goal of outputting the corresponding question sample from the question generation model to obtain the trained question generation model.
4. The method according to claim 1, It is characterized in that Also includes: For the target text, selecting a second question word from the question words in the target language; Inputting the first prompt text and the target text corresponding to the second question word into the answer selection model to obtain the target answer output by the answer selection model; The second prompt text corresponding to the second question word, the target text and the target answer are input into the question generation model to obtain the target question output by the question generation model.
5. The method according to claim 1, It is characterized in that The first prompt text and the second prompt text corresponding to the question word both contain the question word and the interpretation of the question word.
6. The method according to claim 1, It is characterized in that The answer selection model is a natural language understanding model, and the question generation model is a natural language generation model.
7. A model training device, It is characterized in that include: A first construction module is used to construct a first prompt text and a second prompt text corresponding to the question word according to the question word and its interpretation in the target language, wherein the first prompt text is used to prompt the selection of a potential answer to the question containing the question word, and the second prompt text is used to prompt the generation of the question containing the question word; A first acquisition module is used to acquire multiple original training samples, each of which includes a text sample, a question sample, and an answer sample corresponding to the question sample, wherein the question sample contains a question word; A second construction module is used to construct a first training sample for each original training sample by using the text sample, the answer sample, and the first prompt text corresponding to the question word in the question sample of the original training sample to obtain a first training set including a plurality of the first training samples; and to construct a second training sample by using the text sample, the question sample, the answer sample, and the second prompt text corresponding to the question word in the question sample of the original training sample to obtain a second training set including a plurality of the second training samples; The training module is used to train an answer selection model using the first training set, and to train a question generation model using the second training set.
8. The device according to claim 7, It is characterized in that The first training set further includes at least one third training sample, and the apparatus further includes: The third construction module is used to construct the third training sample in the following manner: For a first text sample, determining a first question word that is not included in all question samples corresponding to the first text sample; The third training sample is constructed by using the first prompt text corresponding to the first question word, the blank answer and the first text sample.
9. The device according to claim 7 or 8, It is characterized in that The training module is also used for: Inputting the first prompt text and text sample of each training sample in the first training set into the answer selection model, training the answer selection model with the goal of outputting the corresponding answer sample by the answer selection model, and obtaining the trained answer selection model; The second prompt text, text sample and answer sample of each training sample in the second training set are input into the question generation model, and the question generation model is trained with the goal of outputting the corresponding question sample from the question generation model to obtain the trained question generation model.
10. The device according to claim 7, It is characterized in that Also includes: A model application module, for selecting a second question word from the question words in the target language for the target text; Inputting the first prompt text and the target text corresponding to the second question word into the answer selection model to obtain the target answer output by the answer selection model; The second prompt text corresponding to the second question word, the target text and the target answer are input into the question generation model to obtain the target question output by the question generation model.
11. The device according to claim 7, It is characterized in that The first prompt text and the second prompt text corresponding to the question word both contain the question word and the interpretation of the question word.
12. The device according to claim 7, It is characterized in that The answer selection model is a natural language understanding model, and the question generation model is a natural language generation model.
13. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program is executed by a processor, the steps of the model training method according to any one of claims 1 to 6 are implemented.
Citation Information
Cited By
Data processing method and device based on large language model
CN120671806A
