A question and answer pair generation method and device, electronic equipment and computer storage medium
By extracting document fragments from documents and using a pre-trained model to generate question and answer text, this technology solves the problem of existing technologies relying on manual annotation for question-answer pair generation, and achieves automated generation of high-quality question-answer pairs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-23
- Publication Date
- 2026-03-31
AI Technical Summary
Existing question-answering methods rely on manual annotation and generate disjointed questions with low relevance between answers and questions.
By acquiring document fragments, a pre-trained first model is used to generate question text, and a pre-trained second model is used to extract answer text from the document, establishing a relationship between questions and answers to generate question-answer pairs.
It automates the extraction of large amounts of question text from documents and improves the matching degree between answer text and question text, generating accurate question-answer pairs.
Smart Images

Figure CN115114416B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a question-and-answer pair generation method, apparatus, electronic device, and computer storage medium. Background Technology
[0002] Question-answer pairs are widely used in machine learning, such as machine reading comprehension, intelligent question answering, knowledge base configuration, and data augmentation. However, high-quality question-answer pairs currently rely heavily on manual annotation, which is costly. Existing algorithm-based automatic question-answer pair generation methods often result in incoherent questions and low relevance between the answers and questions.
[0003] Therefore, a more accurate question-answer pair generation scheme is needed. Summary of the Invention
[0004] In view of this, embodiments of the present invention provide a question-answer pair generation scheme to at least partially solve the above-mentioned problems.
[0005] According to a first aspect of the present invention, a question-answer pair generation method is provided, comprising:
[0006] Obtain a document, and extract document fragments from the document;
[0007] Based on the pre-trained first model, the document, and the document fragment, generate question text corresponding to the document fragment;
[0008] Based on the pre-trained second model, the document, and the question text, obtain the answer text corresponding to the question text from the document;
[0009] Establish the association between the question text and the answer text, and generate question-answer pairs corresponding to the document fragments.
[0010] According to a second aspect of the present invention, a question-answer pair generation apparatus is provided, the apparatus comprising:
[0011] The module retrieves a document and extracts document fragments from the document.
[0012] The question text generation module generates question text corresponding to the document fragment based on the pre-trained first model, the document, and the document fragment.
[0013] The answer text generation module obtains the answer text corresponding to the question text from the document based on the pre-trained second model, the document, and the question text;
[0014] The question-answer pair generation module establishes the association between the question text and the answer text, and generates question-answer pairs corresponding to the document fragment.
[0015] According to a third aspect of the present invention, an electronic device is provided, comprising: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other via the communication bus; the memory is used to store at least one executable instruction, wherein the executable instruction causes the processor to perform an operation corresponding to the question-and-answer pair generation method described in the first aspect.
[0016] According to a fourth aspect of the present invention, a computer storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the question-answer pair generation method as described in the first aspect.
[0017] According to the question-answer pair generation scheme provided in the embodiments of the present invention, document fragments are obtained from a document, and then corresponding question texts are obtained from the document based on a pre-trained first model and the document fragments. Then, a pre-trained second model is used to obtain answer texts corresponding to the question texts from the document. In this method of first obtaining the question and then finding the answer, the first model can automatically mine a large amount of question text from the document, while the deep learning-based second model improves the matching degree between the predicted answer text and the generated question text, thereby achieving automated generation of accurately matching question-answer pairs from the document. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings.
[0019] Figure 1a A flowchart illustrating the process involved in generating question-and-answer pairs from documents for the current solution;
[0020] Figure 1b A schematic diagram illustrating the framework of a question-and-answer pair generation method provided in an embodiment of this application;
[0021] Figure 2 A flowchart illustrating a question-and-answer pair generation method provided in an embodiment of this application;
[0022] Figure 3 A schematic diagram illustrating a document segmentation method provided in an embodiment of this application;
[0023] Figure 4A schematic diagram illustrating the encoding and decoding framework in a first model provided in an embodiment of this application;
[0024] Figure 5 This is a schematic diagram illustrating how to generate answer text based on question text and document, as provided in an embodiment of this application.
[0025] Figure 6 This is a schematic diagram of the structure of a question-and-answer pair generation device provided in an embodiment of this application;
[0026] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0027] To enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art should fall within the protection scope of the present invention.
[0028] Currently, methods for obtaining question-answer pairs from documents are either manual extraction or extracting keywords as answers and then using a pre-trained model to find matching questions from the document. Figure 1a As shown, Figure 1a A flowchart illustrating the process involved in generating question-and-answer pairs from documents for the current solution.
[0029] exist Figure 1a In this approach, because the answer is extracted first, it's easy to extract specific details. For example, if the document describes the medicinal value of peony flowers, such as "Peony flower effects: nourishes blood and promotes blood circulation, relieves pain, soothes the liver and spleen, nourishes the liver and improves complexion, removes age spots, regular consumption can improve complexion, has antibacterial properties, can relieve abdominal pain caused by hypermotility, and can treat dysmenorrhea caused by blood stasis. Peony is not only a famous flower, but its roots are also used medicinally. According to analysis, peony roots contain paeoniflorin and benzoic acid, and their uses vary depending on the species," the resulting keywords might include ineffective keywords such as "paeoniflorin" and "benzoic acid." These ineffective keywords are actually not very relevant to the document's purpose (i.e., the question the user might want to ask).
[0030] In other words, in Figure 1aIn this approach, there may be a number of unexpected situations when extracting keywords in the first step, such as (1) failing to extract keywords; (2) extracting keywords that are too broad; (3) extracting keywords that are meaningless. These situations may lead to a low degree of matching between the questions and answers generated later.
[0031] Based on this, embodiments of this application provide a question-and-answer pairing solution. For example... Figure 1b As shown, Figure 1b This is a schematic diagram illustrating the framework of a question-answer pair generation method provided in an embodiment of this application. Specifically, the document is first segmented, and questions are generated based on the document fragments. Then, corresponding answers are generated from the document based on the questions.
[0032] like Figure 2 As shown, Figure 2 The following is a flowchart illustrating a question-and-answer pair generation method provided in an embodiment of this application. The method includes:
[0033] S201, Obtain a document, and obtain a document fragment from the document.
[0034] The document can be any document containing multiple characters.
[0035] A document fragment can be a portion of the content of a document. It should be noted that the content contained in a document fragment should be a continuous string of characters from the document.
[0036] In one implementation, document fragments can be obtained by using a keyword extraction model, which extracts some keywords and / or key sentences from the document, and then identifies the extracted keywords and / or key sentences as document fragments.
[0037] In another implementation, an adjustable sliding window and sliding step can be used to segment the document to obtain multiple document fragments. The sliding window has an adjustable window length. The sliding step is used to indicate the interval between two adjacent document fragments, that is, the length between the first character of one document fragment and the first character of another adjacent document fragment, including but not limited to the number of characters; while the window length is used to indicate the length of any document fragment obtained from the segmentation, that is, the length of a document fragment, such as the number of characters contained in the document fragment.
[0038] like Figure 3 As shown, Figure 3This is a schematic diagram illustrating document segmentation using a sliding window method, as provided in an embodiment of this application. In this segmentation method, the resulting document fragments are of equal length. Each fragment may not be semantically complete (for example, fragment 2 ends with "evergreen," but its original semantic meaning in the document refers to evergreen trees), and may also contain punctuation characters, but this does not affect the subsequent generation of the question text.
[0039] Furthermore, in this segmentation method, the sliding window and sliding step size are adjustable. Therefore, different types of document fragments can be obtained by adjusting the window length and sliding step size. Specifically, if you want longer document fragments, you can increase the window length; if you want to generate more document fragments, you can decrease the sliding step size.
[0040] Furthermore, within the same document, different sliding steps and window lengths can be used to divide it multiple times, resulting in multiple document fragments. This facilitates the generation of more corresponding questions and question-and-answer pairs later on.
[0041] In one implementation, the sliding step size in the sliding window is smaller than the window length, such as... Figure 3 As shown in the diagram. For example, with a sliding step of 30 characters and a window length of 50 characters, this method ensures that the segmented document fragments cover all characters in the document without missing any characters, resulting in more comprehensive question-and-answer pairs.
[0042] You can choose to use keyword / sentence extraction to obtain document fragments and use sliding window to obtain document fragments, or you can use both methods simultaneously.
[0043] By combining documents with document fragments in this way, all possible answer fragments can be input into the first model, such as the question generation model, thereby greatly increasing the number of subsequent question-answer pairs generated.
[0044] S203, Based on the pre-trained first model, the document, and the document fragment, generate question text corresponding to the document fragment.
[0045] The first model can be a pre-trained available model used to generate question text corresponding to document fragments. For example, the first model can be a question generation model, such as an Encoder-Decoder based model, including but not limited to Transformer models, or a BERT (Bidirectional Encoder Representation from Transformers) model.
[0046] Specifically, a first model can be pre-trained using a pre-given training document, a given training document fragment, and the corresponding question text to obtain a usable first model. During the pre-training process, a preset connecting character (e.g., SEP) can be used to connect the given training document and the given training document fragment to obtain training samples in the form of "given document + SEP + given document fragment", and pre-training can be performed based on the training samples.
[0047] During pre-training, the training samples can be encoded using a bidirectional encoder in the first model. This means that after any character in the training sample is converted into a corresponding character vector, the information represented by that character vector is simultaneously influenced by both its preceding and following characters during training. In the model using a bidirectional encoder, when encoding the input text, the encoder can simultaneously obtain the input information of characters at all positions.
[0048] Meanwhile, during pre-training, the first model uses auto-regression transformers to decode character vectors and obtain outputs. Specifically, after encoding the input character vector, the first model produces an encoded character vector. This encoded character vector then needs to be decoded. During decoding, the first model uses the prediction result of one character as the input to the next adjacent character, decoding sequentially to generate the first output. In other words, during decoding, the first model can only obtain the state information of characters preceding it at the current position, and cannot obtain the state information of characters following it.
[0049] After pre-training is complete, the first model already possesses a relatively accurate ability to extract questions. At this point, the document and document fragments can be used as input according to the format corresponding to the training samples during pre-training. That is, the document, preset connecting characters (the same connecting characters used during pre-training), and document fragments are sequentially concatenated to generate a first concatenated text. This first concatenated text is used as the first input to the first model. The pre-trained first model will then encode the first concatenated text using the same bidirectional encoder as during pre-training. Simultaneously, the first output will be sequentially decoded using residual autoregression, as described above, to obtain the question text. Figure 4 As shown, Figure 4This is a schematic diagram of the encoding and decoding framework in a first model provided by an embodiment of this application. In this diagram, the characters in the lower part of the decoding section represent the corresponding character vectors, and the characters in the lower part of the decoding section represent the corresponding character text. During decoding, the encoding and decoding are performed sequentially. <s>(i.e., the start character), A, B, and C were decoded.
[0050] Furthermore, it should be noted that every character contained in the obtained question text exists in the document; in other words, the set of characters in the question text is a subset of the set of characters in the document.
[0051] S205, based on the pre-trained second model, the document, and the question text, obtain the answer text corresponding to the question text from the document.
[0052] The second model can be any suitable model capable of outputting answer text based on the document and the question text. In one feasible approach, the second model can be a BERT model, pre-trained using the given training document, the corresponding question text, and the corresponding answer text. During pre-training of the second model, a preset connecting character (e.g., SEP) can also be used to connect the given question text and the given training document to train the second model.
[0053] It is important to note that when pre-training the first model, the order of characters in the training samples is "training document, connecting characters, document fragments" to find the question text corresponding to the document fragments in the training document. However, when pre-training the second model, it is necessary to find the answer corresponding to the question text in the training document. Therefore, the order of characters in the second training samples is "question text, connecting characters, training document".
[0054] After the second model pre-training is completed, the trained second model can be used to generate answers from the document based on the question text obtained in the previous step S203. Specifically, the question text, preset connecting characters, and the document are sequentially concatenated using the same concatenation method and connecting characters as during pre-training to generate a second concatenated text. This second concatenated text is then used as the second input to the second model to generate a corresponding second output. The answer text corresponding to the question text is then determined based on the second output.
[0055] Because the second model takes different forms, the actual form of the second output can also vary. When the second model is pre-trained for classification training of multiple sentences, the second output may consist of multiple sentences. In this case, most of these sentences can be identified as the answer text corresponding to the question text.
[0056] In one implementation, the second model can be used to determine the start and end positions of the characters corresponding to the second concatenated text from the document; the text within the character interval corresponding to the start and end positions is determined as the second output, that is, the text within the character interval corresponding to the start and end positions is determined as the second output, and then the answer text is determined based on the second output. Figure 5 As shown, Figure 5 This diagram illustrates a method for generating answer text based on question text and document, as provided in an embodiment of this application. In this diagram, a question text of length N and a document of length M are first sequentially concatenated using the concatenation character SEP, and then bidirectionally encoded as described above, resulting in multiple corresponding vectors (i.e., Figure 5 The symbol E in the document represents the corresponding vector, thus predicting the start and end positions of characters from the document.
[0057] Similar to the question text, every character contained in the answer text exists in the document; in other words, the set of characters in the answer text is a subset of the set of characters in the document.
[0058] S207, Establish the association between the question text and the answer text, and generate a question-answer pair corresponding to the document fragment.
[0059] As mentioned earlier, a document fragment may be obtained by dividing the document into multiple segments. In this application, steps S203 to S205 describe processing a document fragment to obtain a corresponding question text and answer text, meaning that the document fragment and answer pair are in one-to-one correspondence. When multiple document fragments exist, there will actually be multiple corresponding question-answer pairs. Therefore, in practice, the sliding step size of the aforementioned sliding window can be adjusted based on experience to control the number of question-answer pairs. For example, it is generally believed that a document of about 500 words may generate about 10 questions. In this case, the sliding step size can be adjusted to 50 characters to generate 10 document fragments (the window length is not affected), thereby generating 10 question-answer pairs, which can then be deployed online for users to query.
[0060] According to the question-answer pair generation scheme provided in the embodiments of the present invention, document fragments are obtained from a document, and then corresponding question texts are obtained from the document based on a pre-trained first model and the document fragments. Then, a pre-trained second model is used to obtain answer texts corresponding to the question texts from the document. In this method of first obtaining the question and then finding the answer, the first model can automatically mine a large amount of question text from the document, while the deep learning-based second model improves the matching degree between the predicted answer text and the generated question text, thereby achieving automated generation of accurately matching question-answer pairs from the document.
[0061] The question-answer pair generation method of this embodiment can be executed by any suitable electronic device with data processing capabilities, including mobile terminals (such as mobile phones, PADs, etc.) and PCs.
[0062] The solution provided in this application can be widely applied in various scenarios. The following are some specific application scenarios to provide a more illustrative explanation of the solution provided in this application.
[0063] For example, in online education scenarios, users (including students, parents, or teachers) often have questions they need to ask. In such scenarios, online education service providers can use the aforementioned solutions to mine and deploy a large number of question-and-answer pairs.
[0064] First, the service provider can prepare a relatively detailed introductory text based on the aspects that users care about (for example, an introduction to teaching resources, which may include the teaching staff, the textbooks used, the teaching methods, etc.). This introductory text may be about 500 characters long.
[0065] Then, the document is segmented using an adjustable sliding window and sliding step size to obtain multiple document fragments. For example, if the window length and sliding step size are both set to 50, then 10 non-overlapping document fragments of length 50 can be obtained. Or, if the window length is set to 100 and the sliding step size is 50, then 10 document fragments of length 100 can be obtained, with each fragment overlapping the previous one by 50 characters. The document fragments obtained in this way cover all the characters of the introductory text.
[0066] Furthermore, based on a pre-trained first model (e.g., an Encoder-Decoder structure model), the document and document fragments are used as the first input according to the format corresponding to the training samples during pre-training. The first model then encodes the first input using the same bidirectional encoder as during pre-training and obtains the first output. When obtaining the first output, a residual autoregression method is used for sequential decoding to obtain the question text. If 10 document fragments are obtained, there will be 10 corresponding first inputs and 10 corresponding question texts. The obtained question texts might be such as "What teachers are in the institution?" or "What materials are used as teaching materials?"
[0067] This allows for the sequential concatenation of the question text, preset connecting characters, and the 500-word introductory document, resulting in a second concatenated text. This second concatenated text is then used as the second input to a pre-trained second model (e.g., using the BERT model) to generate a corresponding second output (one second input may have multiple corresponding second outputs). This second output serves as the answer text. The generated answer text is typically the answer text already mentioned in the introductory document, such as "Our institution's teachers include A, B, etc." or "Our institution uses the People's Education Press version or a customized version as teaching materials," etc., which are already included in the introductory document.
[0068] Then, the relationship between the aforementioned question text and the answer text is established, and the corresponding question-answer pair is generated and deployed online.
[0069] In this way, only the first and second models need to be pre-trained. Then, when the introductory document is obtained, the window length and sliding step size of the sliding window can be changed as needed. This allows for the generation and deployment of a large number of question-and-answer pairs corresponding to the introductory document, eliminating the need for manual data mining and making the process fast and efficient.
[0070] In health protection scenarios, a similar approach can be used to obtain detailed information documents from doctors or relevant personnel regarding diseases, symptoms, medications, and natural herbal remedies. Figure 3 The document shown provides an introduction to the functions of the peony. Then, the window length and sliding step size of the sliding window can be set as needed, thereby obtaining a large number of question-answer pairs about "peony" based on the pre-trained first and second models, which can then be deployed.
[0071] In practical applications, platforms that have pre-trained the first and second models can provide question-and-answer pair generation services to other service providers. Service providers only need to upload their relevant documents to the platform and set the relevant parameters (i.e., the window length and sliding step size of the sliding window). The platform can then call the pre-trained first and second models, generate corresponding question-and-answer pairs for the relevant documents based on the parameters, and provide feedback to the service providers. This provides considerable convenience to the service providers.
[0072] Regarding the second aspect of this application, a question-and-answer pair generation apparatus is provided, such as... Figure 6 As shown, Figure 6 This is a schematic diagram of a question-and-answer pair generation device provided in an embodiment of this application. The question-and-answer pair generation device includes:
[0073] The acquisition module 601 acquires a document and extracts document fragments from the document;
[0074] The question text generation module 603 generates question text corresponding to the document fragment based on the pre-trained first model, the document, and the document fragment;
[0075] The answer text generation module 605 obtains the answer text corresponding to the question text from the document based on the pre-trained second model, the document, and the question text;
[0076] The question-answer pair generation module 607 establishes the association between the question text and the answer text, and generates question-answer pairs corresponding to the document fragment.
[0077] Optionally, the acquisition module 601 extracts keywords and / or key sentences from the document and determines the extracted keywords and / or key sentences as document fragments; and / or performs sliding segmentation processing on the document using an adjustable sliding window and sliding step size to obtain multiple document fragments.
[0078] Optionally, when the acquisition module 601 performs sliding segmentation processing on the document using an adjustable sliding window and sliding step size, the sliding step size is less than the window length of the sliding window.
[0079] Optionally, the question text generation module 603 sequentially concatenates the document, preset connecting characters, and the document fragment to generate a first concatenated text; the first concatenated text is used as the first input of the first model to generate a corresponding first output, and the first output is determined as the question text corresponding to the document fragment; correspondingly, the answer text generation module 605 sequentially concatenates the question text, preset connecting characters, and the document to generate a second concatenated text; the second concatenated text is used as the second input of the second model to generate a corresponding second output, and the second output is determined as the answer text corresponding to the question text.
[0080] Optionally, the answer text generation module 605 inputs the second concatenated text into the second model as the second input; determines the start and end positions of the characters corresponding to the second concatenated text from the document through the second model; and determines the text within the character interval corresponding to the start and end positions as the second output.
[0081] Optionally, the question text generation module 603 inputs the first concatenated text into the first model as the first input; encodes the first concatenated text using a bidirectional encoder through the first model; and sequentially decodes the first text by using the prediction result of one character as the input of the next adjacent character through the first model to generate the corresponding first output.
[0082] The question-and-answer pair generation device of this embodiment is used to implement the corresponding question-and-answer pair generation methods in the foregoing multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here. In addition, the functional implementation of each module in the question-and-answer pair generation device of this embodiment can refer to the description of the corresponding part in the foregoing method embodiments, which will also not be repeated here.
[0083] A third aspect of the embodiments of this application, referring to... Figure 7 , Figure 7 The diagram shows a structural schematic of an electronic device according to an embodiment of the present invention. The specific embodiments of the present invention do not limit the specific implementation of the electronic device.
[0084] like Figure 7 As shown, the electronic device may include: a processor (702), a communications interface (704), a memory (706), and a communications bus (708).
[0085] in:
[0086] The processor 702, communication interface 704, and memory 706 communicate with each other via communication bus 708.
[0087] Communication interface 704 is used to communicate with other electronic devices or servers.
[0088] The processor 702 is used to execute program 710, specifically to perform the relevant steps in the above-described question-and-answer pair generation method embodiment.
[0089] Specifically, program 710 may include program code that includes computer operation instructions.
[0090] The processor 702 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present invention. The smart device includes one or more processors, which may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0091] Memory 706 is used to store program 710. Memory 706 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.
[0092] Specifically, program 710 can be used to cause processor 702 to perform the following operations:
[0093] Obtain a document, and extract document fragments from the document;
[0094] Based on the pre-trained first model, the document, and the document fragment, generate question text corresponding to the document fragment;
[0095] Based on the pre-trained second model, the document, and the question text, obtain the answer text corresponding to the question text from the document;
[0096] Establish the association between the question text and the answer text, and generate question-answer pairs corresponding to the document fragments.
[0097] The specific implementation of each step in program 710 can be found in the corresponding steps and units described in the above Q&A examples of the generation method embodiments, and will not be repeated here. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the devices and modules described above can be referred to the corresponding process descriptions in the aforementioned method embodiments, and will not be repeated here.
[0098] A fourth aspect of the embodiments of this application also provides a computer storage medium having a computer program stored thereon, which, when executed by a processor, implements as follows: Figure 2 The question-and-answer pair generation method refers to the operations corresponding to each step in the process.
[0099] It should be noted that, depending on the implementation needs, the various components / steps described in the embodiments of the present invention can be broken down into more components / steps, or two or more components / steps or parts of the operation of components / steps can be combined into new components / steps to achieve the purpose of the embodiments of the present invention.
[0100] The methods described above according to embodiments of the present invention can be implemented in hardware, firmware, or as software or computer code that can be stored in a recording medium (such as a CD-ROM, RAM, floppy disk, hard disk, or magneto-optical disk), or as computer code originally stored on a remote recording medium or a non-transitory machine-readable medium and subsequently stored on a local recording medium, downloaded via a network. Thus, the methods described herein can be stored as software processing on a recording medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware (such as an ASIC or FPGA). It is understood that the computer, processor, microprocessor controller, or programmable hardware includes storage components (e.g., RAM, ROM, flash memory, etc.) capable of storing or receiving software or computer code that, when accessed and executed by the computer, processor, or hardware, implements the question-and-answer pair generation method described herein. Furthermore, when a general-purpose computer accesses code used to implement the question-and-answer pair generation method shown herein, the execution of the code transforms the general-purpose computer into a dedicated computer for executing the question-and-answer pair generation method shown herein.
[0101] Those skilled in the art will recognize that the units and method steps of the various examples 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 implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of the embodiments of the present invention.
[0102] The above embodiments are only used to illustrate the embodiments of the present invention, and are not intended to limit the embodiments of the present invention. Those skilled in the art can make various changes and modifications without departing from the spirit and scope of the embodiments of the present invention. Therefore, all equivalent technical solutions also fall within the scope of the embodiments of the present invention, and the patent protection scope of the embodiments of the present invention should be defined by the claims.< / s>
Claims
1. A method for generating a question and answer pair, comprising: obtaining a document, and obtaining a document segment from the document; generating, according to a first pre-trained model, the document, and the document segment, a question text corresponding to the document segment; obtaining, according to a second pre-trained model, the document, and the question text, an answer text corresponding to the question text from the document; establishing an association between the question text and the answer text, and generating a question and answer pair corresponding to the document segment; wherein the generating, according to the first pre-trained model, the document, and the document segment, the question text corresponding to the document segment, comprises: sequentially concatenating the document, a preset connection character, and the document segment to generate a first concatenated text; encoding the first concatenated text by using a bidirectional encoder of the first model to obtain an encoded character vector corresponding to the first concatenated text; decoding the encoded character vector corresponding to the first concatenated text by using the first model to obtain a first output corresponding to the first model, and determining the first output as the question text corresponding to the document segment; the obtaining, according to the second pre-trained model, the document, and the question text, the answer text corresponding to the question text from the document, comprises: sequentially concatenating the question text, the preset connection character, and the document to generate a second concatenated text; bidirectionally encoding the second concatenated text to obtain a plurality of vectors corresponding to the second concatenated text; determining, based on the plurality of vectors, a character start position and a character end position corresponding to the second concatenated text from the document; determining, as a second output of the second model, a text in a character interval corresponding to the character start position and the character end position; and determining, according to the second output, the answer text corresponding to the question text.
2. The method of claim 1, wherein, The obtaining of the document segment from the document comprises: extracting keywords and / or key sentences from the document, and determining the extracted keywords and / or key sentences as the document segment; and / or performing sliding segmentation processing on the document by using an adjustable sliding window and a sliding step to obtain a plurality of document segments.
3. The method of claim 2, wherein, When the sliding segmentation processing is performed on the document by using the adjustable sliding window and the sliding step, the sliding step is smaller than a window length of the sliding window.
4. The method of claim 1, wherein, The encoding, by using the bidirectional encoder of the first model, of the first concatenated text to obtain the encoded character vector corresponding to the first concatenated text comprises: inputting the first concatenated text as a first input of the first model; encoding the first input by using the bidirectional encoder of the first model to obtain the encoded character vector corresponding to the first concatenated text.
5. The method of claim 1, wherein, The determining, based on the plurality of vectors, of the character start position and the character end position corresponding to the second concatenated text from the document comprises: inputting the plurality of vectors into the second model as a second input; determining, by using the second model, the character start position and the character end position from the document. 6.The method of claim 4, wherein the first spliced text is inputted into the first model as a first input, including: inputting the first spliced text into the first model as a first input; generating a first output corresponding to the first model, including: sequentially decoding, by the first model, a prediction result of a character corresponding to an encoded character vector as an input of a character corresponding to a next encoded character vector to generate the first output. 7.An apparatus for generating a question and answer pair, the apparatus comprising: an obtaining module, configured to obtain a document, and obtain a document segment from the document; a question text generating module, configured to generate a question text corresponding to the document segment according to a first model pre-trained, the document and the document segment; an answer text generating module, configured to obtain an answer text corresponding to the question text from the document according to a second model pre-trained, the document and the question text; a question and answer pair generating module, configured to establish an association between the question text and the answer text, and generate a question and answer pair corresponding to the document segment; wherein the question text generating module is configured to generate the question text corresponding to the document segment according to the first model pre-trained, the document and the document segment by sequentially splicing the document, a preset connection character and the document segment to generate a first spliced text, encoding the first spliced text by a bidirectional encoder to obtain an encoded character vector corresponding to the first spliced text, and decoding the encoded character vector corresponding to the first spliced text by the first model to obtain a first output corresponding to the first model, and determining the first output as the question text corresponding to the document segment; the answer text generating module is configured to obtain the answer text corresponding to the question text from the document according to the second model pre-trained, the document and the question text by sequentially splicing the question text, the preset connection character and the document to generate a second spliced text, bidirectionally encoding the second spliced text to obtain a plurality of vectors corresponding to the second spliced text, determining a character start position and a character end position corresponding to the second spliced text from the document based on the plurality of vectors, determining a text in a character interval corresponding to the character start position and the character end position as a second output of the second model, and determining the answer text corresponding to the question text according to the second output.
8. An electronic device comprising: a processor, a memory, a communication interface and a communication bus, the processor, the memory and the communication interface complete communication with each other through the communication bus; the memory is configured to store at least one executable instruction, and the executable instruction causes the processor to perform operations corresponding to the question and answer pair generation method in any one of claims 1-6. 9.A computer storage medium having a computer program stored thereon, the program being executed by a processor to implement the question and answer pair generation method in any one of claims 1-6.
Citation Information
Patent Citations
Question-answer pair generation method and device, electronic equipment and readable storage medium
CN112183091A
Long text processing method, related equipment and readable storage medium
CN112527992A