Document question and answer pair generation method and device, question and answer method and device, computer equipment and readable storage medium

By entering the text of the document into the knowledge graph and question-and-answer model, a question-and-answer pair is generated, which solves the problem of time-consuming and low accuracy in creating question-and-answer pairs in the prior art, and achieves more efficient and accurate information extraction and retrieval.

CN119474274APending Publication Date: 2025-02-18CHINA SOUTHERN POWER GRID MATERIALS CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411711576.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

The prior art relies on manual annotation when creating question-and-answer pairs, which is time-consuming and labor-intensive and subjective, affecting the retrieval efficiency of large-scale text data and the accuracy of information extraction when processing large-scale text data.

Method used

Generate a Q&A pair by obtaining multiple text slices of the document and inputting it into the pretrained knowledge graph model and question-answer model. The specific steps include: outputting the target question based on the format features and text type of text slice; inputting the target question multiple times to get the answer to be selected; determining the answer to be selected with the highest probability of occurrence as the target answer; based on the target question and the target answer Generate a Q&A.

Benefits of technology

It improves the matching accuracy of Q&A pairs, and improves the retrieval efficiency and information extraction accuracy of large models when processing large-scale text data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119474274A_ABST
    Figure CN119474274A_ABST
Patent Text Reader

Abstract

The invention relates to a document question-answer pair generation method and device, a question-answer method and device, computer equipment and a readable storage medium, and relates to the technical field of data generation, and the document question-answer pair generation method comprises the steps of obtaining a plurality of text slices of a document; inputting the text slices into a pre-trained knowledge graph model, and indicating the knowledge graph model to output at least one target question corresponding to the text slices based on format features and text types of the text slices; a knowledge graph associated with the knowledge field of the document is embedded in the knowledge graph model; inputting the same target question into a pre-trained question and answer model for multiple times to obtain multiple to-be-selected answers output by the question and answer model for multiple times; determining the to-be-selected answer with the maximum occurrence probability in the plurality of to-be-selected answers as a target answer matched with the corresponding target question; generating a plurality of question and answer pairs of the document based on each matched target question and target answer; and the matching accuracy of each question and answer pair is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of data generation, and in particular to a method, apparatus, computer device, computer-readable storage medium, and computer program product for generating question-answer pairs and answering questions for a document. Background Art

[0002] With the development of artificial intelligence technology, large language models (LLMs) have made significant progress in the field of natural language processing (NLP). Document question answering is an important task in the field of natural language processing, and related document question answering systems are widely used in information retrieval, virtual assistants, knowledge graph construction, etc.

[0003] At present, manual annotation is mainly used to create question-answer pairs, which requires a lot of manpower and time. In addition, due to the different knowledge reserves of different annotators, the creation of question-answer pairs is highly subjective. Using the question-answer pairs created in this way as an evaluation dataset will affect the credibility of the document question-answering system. This will cause the existing large models to still face problems of low retrieval efficiency and inaccurate information extraction when processing large-scale text data.

[0004] Therefore, there is an urgent need to provide a question-answer pair creation method that can improve the retrieval efficiency and accuracy of information extraction of large models when processing large-scale text data. Summary of the invention

[0005] Based on this, it is necessary to provide a document question-and-answer pair generation and question-and-answer method, device, computer equipment, computer-readable storage medium and computer program product that can improve the retrieval efficiency and accuracy of information extraction of large models when processing large-scale text data in order to solve the above-mentioned technical problems.

[0006] In a first aspect, the present application provides a document question-answer pair generation and question-answering method, comprising:

[0007] Get multiple text slices of a document;

[0008] Input the text slice into a pre-trained knowledge graph model, and instruct the knowledge graph model to output at least one target question corresponding to the text slice based on the format features and text type of the text slice; the knowledge graph model is embedded with a knowledge graph related to the knowledge field of the document;

[0009] Inputting the same target question into the pre-trained question-answering model multiple times to obtain multiple answers to be selected that are output by the question-answering model multiple times;

[0010] Determine the answer to be selected with the highest probability of appearing among the multiple answers to be selected as the target answer that matches the corresponding target question;

[0011] Based on the matched target questions and the target answers, a plurality of question-answer pairs of the document are generated.

[0012] In one embodiment, obtaining multiple text slices of a document includes:

[0013] Preprocessing the acquired document to obtain a target document; the preprocessing includes removing stop words, punctuation marks and web page tags in the document, and extracting word segments and stems in the document;

[0014] Convert the target document into a numerical feature and input it into a pre-trained language model to obtain an embedding vector output by the language model;

[0015] Based on a pre-selected clustering algorithm, grouping the target documents into a plurality of clusters according to the similarities between the embedding vectors;

[0016] Each text slice is generated based on the subtext of the target document included in each of the clusters.

[0017] In one embodiment, the method for determining the pre-selected clustering algorithm includes:

[0018] Based on multiple preset clustering algorithms, the target documents are grouped into multiple clusters according to the similarities between the embedding vectors;

[0019] Based on preset evaluation indicators, quality scores are performed on all the clusters corresponding to each of the preset clustering algorithms, and the preset clustering algorithm corresponding to the maximum value in the quality score is determined as the pre-selected clustering algorithm; the evaluation indicators include at least one of the silhouette coefficient, the variance ratio criterion, and the Davidson-Borgin index.

[0020] In one embodiment, the method for constructing the knowledge graph includes:

[0021] Identify the knowledge domain of the document, and obtain entity names in the document that are associated with the knowledge domain;

[0022] Based on the association relationship between the entity names and the attribute information of the entity names, a knowledge graph corresponding to the document is constructed.

[0023] In one embodiment, each of the to-be-selected answers is one of the multiple text slices.

[0024] In a second aspect, the present application also provides a question-answering method, comprising:

[0025] Obtaining questions to be answered, and converting the questions to be answered into vectors to be answered;

[0026] Searching a vector database based on the to-be-answered vector to obtain a corresponding question vector and an answer vector matching the question vector, and outputting a corresponding target answer based on the answer vector;

[0027] Wherein, the vector database is constructed based on multiple question-answer pairs, the question vector in the vector database is converted based on the target question in the question-answer pair, and the answer vector in the vector database is converted based on the target answer in the question-answer pair; wherein, the question-answer pair is a question-answer pair generated by the document question-answer pair generation method described in the first aspect.

[0028] In a third aspect, the present application further provides a device for generating question-answer pairs of a document, the device comprising:

[0029] A data acquisition module, used to acquire multiple text slices of a document;

[0030] A question generation module, configured to input the text slice into a pre-trained knowledge graph model, and instruct the knowledge graph model to output at least one target question corresponding to the text slice based on the format features and text type of the text slice; the knowledge graph model is embedded with a knowledge graph related to the knowledge field of the document;

[0031] An answer generation module is used to input the same target question into the pre-trained question-answering model multiple times to obtain multiple candidate answers output by the question-answering model multiple times; determine the candidate answer with the highest probability of appearing among the multiple candidate answers as the target answer matched with the corresponding target question;

[0032] A question-answer pair generation module is used to generate multiple question-answer pairs for the document based on the matched target questions and the target answers.

[0033] In a fourth aspect, the present application further provides a question-answering device, the device comprising:

[0034] A question acquisition module, used for acquiring questions to be answered and converting the questions to be answered into vectors to be answered;

[0035] An answer acquisition module is used to search in a vector database based on the to-be-answered vector, obtain a corresponding question vector and an answer vector matching the question vector, and output a corresponding target answer based on the answer vector;

[0036] Wherein, the vector database is constructed based on multiple question-answer pairs, the question vector in the vector database is converted based on the target question in the question-answer pair, and the answer vector in the vector database is converted based on the target answer in the question-answer pair; wherein, the question-answer pair is a question-answer pair generated by the document question-answer pair generation method described in the first aspect.

[0037] In a fifth aspect, the present application further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps in the first aspect or the second aspect when executing the computer program.

[0038] In a sixth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps in the first aspect or the second aspect when executed by a processor.

[0039] In a seventh aspect, the present application further provides a computer program product, comprising a computer program, which implements the steps in the first aspect or the second aspect when executed by a processor.

[0040] In the above-mentioned document question-answer pair generation and question-answering method, apparatus, computer device, computer-readable storage medium and computer program product, the document question-answer pair generation method obtains multiple text slices of the document; inputs the text slices into a pre-trained knowledge graph model, and instructs the knowledge graph model to output at least one target question corresponding to the text slice based on the format features and text type of the text slice; the knowledge graph model is embedded with a knowledge graph related to the knowledge field of the document; the same target question is input into the pre-trained question-answering model multiple times to obtain multiple candidate answers output by the question-answering model multiple times; determines the candidate answer with the highest probability of appearing among the multiple candidate answers as the target answer matched by the corresponding target question; generates multiple question-answer pairs for the document based on each matched target question and target answer; it is beneficial to improve the matching accuracy of each question-answer pair. Furthermore, the question-answering method obtains questions to be answered and converts them into vectors to be answered; based on the vectors to be answered, a search is performed in a vector database to obtain the corresponding question vector and the answer vector matching the question vector, and a corresponding target answer is output based on the answer vector; wherein, the vector database is constructed based on multiple question-answer pairs, the question vectors in the vector database are converted based on the target questions in the question-answer pairs, and the answer vectors in the vector database are converted based on the target answers in the question-answer pairs; therefore, in the process of retrieving the corresponding target answers based on the question vectors corresponding to the questions to be answered, it is only necessary to match the question-answer pairs by similarity, and there is no need to traverse all the vectors in the vector database. Therefore, it can effectively improve the retrieval efficiency and the accuracy of information extraction of large models when processing large-scale text data. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0042] Figure 1 A diagram of an application environment of a question-answer pair generation and a question-answer method for a document in one embodiment;

[0043] Figure 2 A schematic diagram of a flow chart of a method for generating question-answer pairs for a document in one embodiment;

[0044] Figure 3 A schematic diagram of a process for processing a document in one embodiment;

[0045] Figure 4 is a schematic diagram of a knowledge graph in one embodiment;

[0046] Figure 5 A schematic diagram of a process for obtaining question-answer pairs in one embodiment;

[0047] Figure 6 A schematic diagram of a flow chart of a question-answering method in one embodiment;

[0048] Figure 7 is a flowchart of a question-answering method in another embodiment;

[0049] Figure 8 is a structural block diagram of a device for generating question-answer pairs for a document in one embodiment;

[0050] Fig. 9 is a structural block diagram of a question-answering device in an embodiment;

[0051] Fig.10 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0052] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0053] The document question-answer pair generation and question-answering method provided in the embodiments of the present application can be applied to Figure 1In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The data storage system can be used to store data such as documents, text slices, question and answer pairs, and vector databases. Among them, the terminal 102 can be but is not limited to various personal computers, laptops, smart phones, tablets, etc. The server 104 can be an independent physical server, or it can be a server cluster or distributed system composed of multiple physical servers, or it can be a cloud server that provides cloud computing services.

[0054] In an exemplary embodiment, Figure 2 As shown, a method for generating question-answer pairs of documents is provided, and the method is applied to Figure 1 The terminal 102 in the example is used as an example to illustrate, including the following steps 202 to 210. Among them:

[0055] Step 202: Acquire multiple text slices of the document.

[0056] Among them, the document can be, for example, all the graphic and text data in a book, or all the graphic and text data involved in a series of books, or all the graphic and text data involved in multiple books in a field; in addition, the document can further include graphic and text data on the Internet, and can further include graphic and text data in text files other than books.

[0057] For example, you can choose to obtain multiple text slices corresponding to the document through the existing document slicing method, each text slice can be, for example, a paragraph or multiple paragraphs of text in the document, or a sentence of text in the document, and this application does not make specific limitations on this. Furthermore, the text slice may also contain some table data or image data.

[0058] Step 204: input the text slice into a pre-trained knowledge graph model, and instruct the knowledge graph model to output at least one target question corresponding to the text slice based on the format features and text type of the text slice; the knowledge graph model is embedded with a knowledge graph related to the knowledge field of the document.

[0059] The format feature may refer to the format of the text slice, for example, it may include question-answer format and narrative format, etc. The text type may include scientific explanation type, story narration type, historical event type, etc. The knowledge graph model may be trained based on sample texts with different format features and text types, and the knowledge graph model is embedded with the knowledge graph of the knowledge field corresponding to the document.

[0060] Exemplarily, each text slice generated by the document is input into a pre-trained knowledge graph model, and the knowledge graph model is guided to identify the format features of each text slice, and then identify the relevant information in the text slice based on the key information related to the determined format features; for example, if the text slice is in a question-and-answer format, the model is prompted to recognize the structure of the question and answer; if it is in a narrative format, the model is prompted to recognize the subject and event of the narrative.

[0061] Then, guide the knowledge graph model to identify the text type of the text slice, and then identify the relevant information in the text slice based on the key information related to the determined text type. For example, if the text slice is about scientific explanation, prompt the model to identify scientific concepts and explanation logic; if it is a story narrative, prompt the model to identify the characters and plot development of the story; if the text slice is about a historical event, prompt the model to identify the key people, time, place and impact of the event.

[0062] Finally, the knowledge graph model can output at least one target question corresponding to each text slice based on the recognition processing of the text slice. The answer to the target question is also the corresponding text slice. The answers to multiple target questions can be the same text slice, which means that there is more than one way to ask questions related to the same text slice.

[0063] It should also be added that the present application introduces a knowledge graph in document-related fields for the knowledge graph model used to receive text slices to output corresponding target questions, which is conducive to enhancing the data processing capabilities and processing accuracy of the knowledge graph model, enabling the knowledge graph model to utilize the relationships and entity information in the knowledge graph to provide more logical and consistent answers, thereby helping to improve the matching degree between the target question and the corresponding text slice.

[0064] Step 206, input the same target question into the pre-trained question-answering model multiple times to obtain multiple answers to be selected that are output by the question-answering model multiple times.

[0065] Among them, the pre-trained question-answering model can be trained based on multiple sample question-answer pairs.

[0066] Exemplarily, multiple target questions outputted by the knowledge graph model are inputted into the pre-trained question-answering model to obtain outputted candidate answers that match the target questions. The same target question can be inputted into the question-answering model multiple times, and the candidate answers outputted by the question-answering model for each received target question may be somewhat different. Therefore, multiple candidate answers that match the same target question will be obtained.

[0067] Step 208, determining the answer with the highest probability of appearing among the multiple answers to be selected as the target answer that matches the corresponding target question.

[0068] Exemplarily, for each target question's multiple potential answers, the number of times the same answer appears in the potential answers is counted to determine the potential answer with the highest probability of appearing among the multiple potential answers for each target question, which is the target answer that best matches the target question.

[0069] Step 210 , generating multiple question-answer pairs for the document based on the matched target questions and target answers.

[0070] Exemplarily, the target answer that best matches each target question is determined, so as to generate multiple question-answer pairs for the document based on the matched target questions and target answers.

[0071] In the method for generating question-answer pairs for the above-mentioned document, multiple text slices of the document are obtained; the text slices are input into a pre-trained knowledge graph model, and the knowledge graph model is instructed to output at least one target question corresponding to the text slice based on the format features and text types of the text slices; a knowledge graph related to the knowledge field of the document is embedded in the knowledge graph model; the same target question is input into the pre-trained question-answer model multiple times to obtain multiple candidate answers output by the question-answer model multiple times; the candidate answer with the highest probability of appearing among the multiple candidate answers is determined as the target answer matched by the corresponding target question; multiple question-answer pairs of the document are generated based on the matched target questions and target answers; this is conducive to improving the matching accuracy of each question-answer pair.

[0072] In an exemplary embodiment, the acquisition of multiple text slices of a document performed in the above step 202 can be achieved by executing steps 221 to 224, wherein:

[0073] Step 221, preprocessing the acquired document to obtain a target document; the preprocessing includes removing stop words, punctuation marks and web page tags in the document, and extracting word segments and stems in the document;

[0074] Step 222, converting the target document into a numerical feature and inputting it into a pre-trained language model to obtain an embedding vector output by the language model;

[0075] Step 223, grouping the target documents into a plurality of clusters based on the similarities between the embedding vectors based on a pre-selected clustering algorithm;

[0076] Step 224: Generate text slices based on the subtexts of the target document included in each cluster.

[0077] Exemplarily, the acquired document is an original document, and the acquired document can be preprocessed, such as removing stop words, punctuation marks and web page tags in the document, and extracting word segments and stems in the document, to obtain a target document corresponding to the original document, so that the processed target document is easier to be recognized and processed by the machine (model). Then, after the target document is converted into numerical features that can be processed by the computer, the numerical features are processed by a pre-trained language model to obtain an embedding vector output by the language model that can capture the semantic information of the text. Then, a pre-selected clustering algorithm can be further used to group the text into different clusters according to the similarity between the embedding vectors, so as to generate each text slice based on the sub-text of the target document included in each cluster; wherein each cluster can include only one text slice; the content of the graphic data included in a text slice is similar.

[0078] In an exemplary embodiment, the method for determining the pre-selected clustering algorithm may include: grouping the target documents into multiple clusters based on the similarity between each embedded vector based on multiple preset clustering algorithms; then, based on preset evaluation indicators, performing quality scores on all clusters corresponding to each preset clustering algorithm, and determining that the preset clustering algorithm corresponding to the maximum value in the quality score is the pre-selected clustering algorithm; the evaluation indicators include at least one of the silhouette coefficient, the variance ratio criterion, and the Davidson-Botting index.

[0079] Based on this, Figure 3 As shown, the present application also provides an optional implementation method for obtaining multiple text slices of a document, which is to use a semantic clustering algorithm to slice the document, including: preprocessing the original text (document), such as removing stop words, punctuation marks, HTML tags (web page tags), extracting word segments and stems, converting the document into a numerical feature that can be processed by a computer through the TF-IDF algorithm, and generating an embedding vector that can capture the semantic information of the text through a pre-trained language model (such as GPT). Use clustering algorithms such as K-Means, hierarchical clustering, DBSCAN, spectral clustering, etc. to group document texts into different clusters according to the similarity between embedded vectors. Use evaluation indicators such as silhouette coefficient, Calinski-Harabasz index (variance ratio criterion), Davies-Bouldin index (Davidson Bouldin index), etc. to evaluate the quality of clustering, compare the advantages and disadvantages of different clustering methods, and find the optimal solution. Thereby, text fragments with similar semantics are combined together to generate slices.

[0080] Among them, HTML is the full spelling of Hyper Text Markup Language, and its Chinese meaning is Hypertext Markup Language. TF-IDF (term frequency–inverse document frequency) is a commonly used weighting technology for information retrieval and text mining. GPT (Generative Pretrained Transformer) is a deep learning model based on the Transformer architecture. K-Means is a K-Means clustering algorithm, which is an iterative clustering analysis algorithm. DBSCAN (Density-Based Spatial Clustering of Applications with Noise) is a density-based clustering algorithm.

[0081] In an exemplary embodiment, a method for constructing a knowledge graph may include: identifying the knowledge domain of a document and obtaining entity names in the document that are associated with the knowledge domain; and constructing a knowledge graph corresponding to the document based on the association relationship between the entity names and the attribute information of the entity names.

[0082] By naming entities in the business domain related to the document, as the basic unit of the knowledge graph, and adding attributes to it. Then, using the business connections between entities, establish relationships between them. Integrating the knowledge graph into the big model enables the resulting knowledge graph model to use the relationships and entity information in the knowledge graph to provide more logical and consistent answers. In other words, introducing the business domain knowledge graph into the model is conducive to enhancing the capabilities of the business domain big model (knowledge graph model).

[0083] Figure 4 A schematic diagram of a knowledge graph in the electric power field is shown for reference, in which transformers, electric power equipment, oil-immersed transformers, dry-type transformers, etc. are all entities in the electric power field.

[0084] In an exemplary embodiment, each answer to be selected is one of a plurality of text slices.

[0085] That is, text slices are input into the knowledge graph model as answers.

[0086] Based on this, the contents of the above steps 204-208 can be selectively executed as follows: inputting the text slice as the candidate answer into the pre-trained knowledge graph model, and instructing the knowledge graph model to output at least one target question corresponding to the candidate answer based on the recognition of the format features and text type of the candidate answer; embedding a knowledge graph of the knowledge domain related to the document in the knowledge graph model; inputting the same target question into the pre-trained question-answering model multiple times to obtain multiple candidate answers output by the question-answering model multiple times; and determining the candidate answer with the highest probability of appearing among the multiple candidate answers as the target answer matched with the corresponding target question.

[0087] For the above steps 204 to 208, an optional embodiment is provided here, which can be referred to Figure 5 , design question-answer pairs based on prompt words, including: taking text slices as answers, first, through chain-of-thought prompting, the format features of text slices are used as the first step of reasoning. For example, if the text slice is in question-answer format, the prompt model (knowledge graph model) identifies the structure of questions and answers; if it is in narrative format, the prompt model (knowledge graph model) identifies the subject and events of the narrative. Then, through reasoning in the intermediate steps, guide the model (knowledge graph model) to understand the type of text slice. For example, if the text slice is about scientific explanation, the prompt model (knowledge graph model) identifies scientific concepts and explanation logic; if it is a story narrative, the prompt model (knowledge graph model) identifies the characters and plot development of the story. If the text slice is about a historical event, the prompt model (knowledge graph model) identifies the key figures, time, place and influence of the event. Then, by adjusting the parameters of the model (knowledge graph model), such as temperature and Top-p, diversified questions are generated while ensuring certainty. For each question, a general large model (question-answering model) without introducing a knowledge graph is used to output multiple answers, and then answers with high frequency are selected from the multiple answers of the general large model to optimize the output answer (target answer).

[0088] Among them, prompt refers to the text or instruction that provides input to the model to guide it to generate a specific output. Top-p is a method in text generation strategy.

[0089] In an exemplary embodiment, Figure 6 As shown, based on the same inventive concept, a question-answering method is provided, which is applied to Figure 1 The terminal 102 in the example is used as an example to illustrate, including the following steps 302 to 304. Among them:

[0090] Step 302, obtaining questions to be answered, and converting the questions to be answered into vectors to be answered;

[0091] Step 304, searching in a vector database based on the vector to be answered, obtaining a corresponding question vector and an answer vector matching the question vector, and outputting a corresponding target answer based on the answer vector;

[0092] Among them, the vector database is constructed based on multiple question-answer pairs, the question vectors in the vector database are converted based on the target questions in the question-answer pairs, and the answer vectors in the vector database are converted based on the target answers in the question-answer pairs; among them, the question-answer pairs are generated by the question-answer pair generation method of the question-answer pair document.

[0093] Figure 7 This is a flowchart of a question-and-answer method in another embodiment, which can be used for reference.

[0094] Based on this, a method for constructing a vector database (vector knowledge base) for documents is provided, including: using a pre-trained language model, such as BERT, GPT, etc., to convert the question-answer pairs generated by the question-answer pair generation method based on the documents provided in this application into high-dimensional vectors, and storing the generated high-dimensional vectors in a vector database, such as FAISS, Annoy or Elasticsearch, etc., to optimize the storage and similarity search operations of the vectors. Among them, BERT (Bidirectional Encoder Representation from Transformers) is a pre-trained model, and FAISS, Annoy, and Elasticsearch are all vector databases.

[0095] Furthermore, a method for retrieving answers to user questions based on a vector database is provided, including building an index for the vector data in the vector database to speed up the retrieval. By using the similarity search function of the vector database and the vectorized result of the user's question, the question-answer pair that best matches the semantics of the question can be quickly found in the vector knowledge base through vector matching technology, thereby improving the retrieval efficiency.

[0096] The document question-answer pair generation and question-answering method provided in this application utilizes a semantic clustering algorithm to convert text into numerical features, captures semantic information through a pre-trained language model, generates an embedding vector in a high-dimensional space, and uses evaluation indicators to obtain high-quality text slices after clustering according to similarity. The knowledge graph is then introduced into the business domain big model to enhance the capabilities of the business domain big model. The text slices are then used as answers, and the model is guided to generate a variety of questions through "thinking chain prompts." For a variety of questions, a general big model is used to output multiple answers, and the one with the highest frequency is selected as the optimal solution, and then a vector knowledge base is constructed, and an index is constructed for the vector data to speed up the retrieval speed. In this way, the traditional method of low efficiency and accuracy when retrieving answers directly from a structured knowledge base is improved.

[0097] It should also be noted that the vector knowledge base of the question-answering system implemented in the related art directly uses a pre-trained language model (such as BERT, GPT, etc.) to convert the text into a vector, stores the generated vector in the vector database, and then uses the similarity search function of the vector database to retrieve the most similar question-answer pairs according to the vectorization results of the user's question. Since all vectors in the knowledge base need to be searched one by one each time the answer to the question is retrieved to generate the answer, there will be a problem that the retrieval efficiency and accuracy decrease as the complexity of the knowledge base increases. The present invention uses semantic clustering to convert long documents into slices with similar semantics, and introduces the business field knowledge graph into the large model to enhance the understanding ability of the large model. Then, the general large model is guided to output and optimize the answer through "thinking chain" and "prompt prompt words". A method for converting question-answer pairs into high-dimensional vectors using pre-trained language models (such as BERT, GPT, etc.), and then constructing a vector knowledge base and indexing it. This means that when searching for user questions, it is only necessary to match question-answer pairs by similarity without traversing all vectors. This can effectively improve the retrieval efficiency and information extraction accuracy of large models when processing large-scale text data.

[0098] In addition, you can also choose the embedded semantic chunking method based on the semantic clustering algorithm to convert the text into an embedded vector. The input text data is divided into multiple slices according to the similarity of the text chunks. Among them, the embedded semantic chunking method based on the semantic clustering algorithm needs to use the embedding model OpenAIEmbedding to obtain the sentence embedding vector, and calculate the semantic relevance between sentences by building a sliding window containing the previous and next sentences, so that adjacent and highly similar sentences are classified into the same semantic chunk.

[0099] The above method of vectorizing the generated question-answer pairs and constructing a vector knowledge base requires vectorizing the questions and answers separately so that they can be represented as points in the vector space and stored in the vector database. When a user asks a question, the question is also converted into a vector, and then a semantic similarity query is performed in the vector database to find the vector most relevant to the question, that is, the most similar question-answer pair.

[0100] It can be seen that this application combines large models, semantic clustering algorithm long document slicing, business domain knowledge graphs, prompt word engineering, thinking chain generation of question and answer pairs and vector knowledge base construction technology, which significantly improves the retrieval efficiency and information extraction accuracy of large models when processing large-scale text data.

[0101] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0102] Based on the same inventive concept, the embodiment of the present application also provides a document question-answer pair generation device 800 for implementing the document question-answer pair generation method involved above. The implementation scheme for solving the problem provided by the device 800 is similar to the implementation scheme recorded in the above method, so the specific limitations of the embodiment of the device 800 for generating question-answer pairs for one or more documents provided below can refer to the limitations of the document question-answer pair generation method above, and will not be repeated here.

[0103] In an exemplary embodiment, Figure 8 As shown, a document question-answer pair generation device 800 is provided, comprising: a data acquisition module 81, a question generation module 82, an answer generation module 83 and a question-answer pair generation module 84, wherein:

[0104] A data acquisition module 81 is used to acquire multiple text slices of a document;

[0105] The question generation module 82 is used to input the text slice into the pre-trained knowledge graph model, and instruct the knowledge graph model to output at least one target question corresponding to the text slice based on the format characteristics and text type of the text slice; the knowledge graph model is embedded with a knowledge graph related to the knowledge field of the document;

[0106] The answer generation module 83 is used to input the same target question into the pre-trained question-answering model multiple times to obtain multiple candidate answers output by the question-answering model multiple times; determine the candidate answer with the highest probability of appearing among the multiple candidate answers as the target answer matched to the corresponding target question;

[0107] The question-answer pair generation module 84 is used to generate multiple question-answer pairs for the document based on each matched target question and target answer.

[0108] In an exemplary embodiment, the data acquisition module 81 is used to acquire multiple text slices of a document, specifically for: preprocessing the acquired document to obtain a target document; the preprocessing includes removing stop words, punctuation marks and web page tags in the document, and extracting word segmentation and stems in the document; converting the target document into numerical features, and inputting them into a pre-trained language model to obtain an embedding vector output by the language model; grouping the target documents into multiple clusters based on a pre-selected clustering algorithm according to the similarity between each embedding vector; and generating each text slice based on the sub-text of the target document included in each cluster.

[0109] In an exemplary embodiment, the method for determining the pre-selected clustering algorithm includes: grouping the target documents into multiple clusters based on the similarity between each embedded vector based on multiple preset clustering algorithms; based on preset evaluation indicators, performing quality scores on all clusters corresponding to each preset clustering algorithm, and determining that the preset clustering algorithm corresponding to the maximum value in the quality score is the pre-selected clustering algorithm; the evaluation indicators include at least one of the silhouette coefficient, the variance ratio criterion, and the Davidson-Botting index.

[0110] In an exemplary embodiment, a method for constructing a knowledge graph includes: identifying the knowledge domain of a document and obtaining entity names in the document that are associated with the knowledge domain; and constructing a knowledge graph corresponding to the document based on the association relationship between the entity names and the attribute information of the entity names.

[0111] In an exemplary embodiment, each answer to be selected is one of a plurality of text slices.

[0112] Based on the same inventive concept, the embodiment of the present application also provides a question-answering device for implementing the question-answering method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more embodiments of the question-answering device provided below can refer to the limitations on the question-answering method above, and will not be repeated here.

[0113] In an exemplary embodiment, Fig. 9 As shown, a question-answering device 900 is provided, including: a question acquisition module 91 and an answer acquisition module 92, wherein:

[0114] A question acquisition module 91 is used to acquire questions to be answered and convert the questions to be answered into vectors to be answered;

[0115] The answer acquisition module 92 is used to search the vector database based on the vector to be answered, obtain the corresponding question vector and the answer vector matching the question vector, and output the corresponding target answer based on the answer vector;

[0116] Among them, the vector database is constructed based on multiple question-answer pairs, the question vectors in the vector database are converted based on the target questions in the question-answer pairs, and the answer vectors in the vector database are converted based on the target answers in the question-answer pairs; among them, the question-answer pairs are question-answer pairs generated by the question-answer pair generation method of the document provided in this application.

[0117] The question-answer pair generating device and each module in the question-answering device of the above document can be implemented in whole or in part by software, hardware and a combination thereof. The above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0118] In an exemplary embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as shown in FIG. Fig.10 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, near field communication (NFC) or other technologies. When the computer program is executed by the processor, a document question-answer pair generation and question-answering method is implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.

[0119] Those skilled in the art will understand that Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0120] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the steps of a method for generating question-answer pairs for a document or the steps of a question-answering method are implemented.

[0121] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of a method for generating question-answer pairs for a document or the steps of a question-answering method are implemented.

[0122] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the steps of a method for generating question-answer pairs for a document, or implements the steps of a question-answering method.

[0123] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0124] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.

[0125] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0126] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for generating question-answer pairs of a document, characterized in that: The method comprises: Get multiple text slices of a document; Input the text slice into a pre-trained knowledge graph model, and instruct the knowledge graph model to output at least one target question corresponding to the text slice based on the format features and text type of the text slice; the knowledge graph model is embedded with a knowledge graph related to the knowledge field of the document; Inputting the same target question into the pre-trained question-answering model multiple times to obtain multiple answers to be selected that are output by the question-answering model multiple times; Determine the answer to be selected with the highest probability of appearing among the multiple answers to be selected as the target answer that matches the corresponding target question; Based on the matched target questions and the target answers, a plurality of question-answer pairs of the document are generated.

2. The method according to claim 1, characterized in that The step of obtaining multiple text slices of a document includes: Preprocessing the acquired document to obtain a target document; the preprocessing includes removing stop words, punctuation marks and web page tags in the document, and extracting word segments and stems in the document; Convert the target document into a numerical feature and input it into a pre-trained language model to obtain an embedding vector output by the language model; Based on a pre-selected clustering algorithm, grouping the target documents into a plurality of clusters according to the similarities between the embedding vectors; Each text slice is generated based on the subtext of the target document included in each of the clusters.

3. The method according to claim 2, characterized in that The method for determining the pre-selected clustering algorithm includes: Based on multiple preset clustering algorithms, the target documents are grouped into multiple clusters according to the similarities between the embedding vectors; Based on preset evaluation indicators, quality scores are performed on all the clusters corresponding to each of the preset clustering algorithms, and the preset clustering algorithm corresponding to the maximum value in the quality score is determined as the pre-selected clustering algorithm; the evaluation indicators include at least one of the silhouette coefficient, the variance ratio criterion, and the Davidson-Borgin index.

4. The method according to claim 1, characterized in that: The method for constructing the knowledge graph includes: Identify the knowledge domain of the document, and obtain entity names in the document that are associated with the knowledge domain; Based on the association relationship between the entity names and the attribute information of the entity names, a knowledge graph corresponding to the document is constructed.

5. The method according to claim 1, characterized in that Each of the to-be-selected answers is one of the multiple text slices.

6. A question-answering method, characterized in that: The method comprises: Obtaining questions to be answered, and converting the questions to be answered into vectors to be answered; Searching a vector database based on the to-be-answered vector to obtain a corresponding question vector and an answer vector matching the question vector, and outputting a corresponding target answer based on the answer vector; Wherein, the vector database is constructed based on multiple question-answer pairs, the question vector in the vector database is converted based on the target question in the question-answer pair, and the answer vector in the vector database is converted based on the target answer in the question-answer pair; wherein, the question-answer pair is a question-answer pair generated by the document question-answer pair generation method described in any one of claims 1-5.

7. A device for generating question-answer pairs for a document, characterized in that: The device comprises: A data acquisition module, used to acquire multiple text slices of a document; A question generation module, configured to input the text slice into a pre-trained knowledge graph model, and instruct the knowledge graph model to output at least one target question corresponding to the text slice based on the format features and text type of the text slice; the knowledge graph model is embedded with a knowledge graph related to the knowledge field of the document; An answer generation module is used to input the same target question into the pre-trained question-answering model multiple times to obtain multiple candidate answers output by the question-answering model multiple times; determine the candidate answer with the highest probability of appearing among the multiple candidate answers as the target answer matched with the corresponding target question; A question-answer pair generation module is used to generate multiple question-answer pairs for the document based on the matched target questions and the target answers.

8. A question-answering device, characterized in that: The device comprises: A question acquisition module, used for acquiring questions to be answered and converting the questions to be answered into vectors to be answered; An answer acquisition module is used to search in a vector database based on the to-be-answered vector, obtain a corresponding question vector and an answer vector matching the question vector, and output a corresponding target answer based on the answer vector; Wherein, the vector database is constructed based on multiple question-answer pairs, the question vector in the vector database is converted based on the target question in the question-answer pair, and the answer vector in the vector database is converted based on the target answer in the question-answer pair; wherein, the question-answer pair is a question-answer pair generated by the document question-answer pair generation method described in any one of claims 1-5.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the processor implements the steps of the method according to any one of claims 1 to 5, or implements the steps of the method according to claim 6.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the computer program implements the steps of the method according to any one of claims 1 to 5, or implements the steps of the method according to claim 6.

Citation Information

Cited By

  • Question and answer pair generation method and system

    CN120258146A

  • Question and answer data generation method, question and answer method, computer equipment and storage medium

    CN121434370A