Intelligent question and answer method and device, equipment and medium
By iteratively generating tokens, the target answers are gradually constructed using the pre-trained search question-and-answer model, which solves the accuracy and efficiency problems of traditional systems when processing complex queries and massive text data, and achieves more efficient and accurate answer generation.
Patent Information
- Application Number
- CN202411272840.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-11
- Publication Date
- 2025-03-04
AI Technical Summary
When traditional search question-and-answer systems handle complex queries or require in-depth understanding of the document context, the answers are inaccurate and efficient, making it difficult to deal with the efficient retrieval and processing of massive text data.
By iteratively generating tokens, the pre-trained search question and answer model is used to gradually build the target answer based on the query text, question and answer instructions and reference documents. In each iteration, the currently generated target answer is updated and relevant information is retrieved in the reference document to improve the accuracy and relevance of the answer.
Improves the accuracy and relevance of answers, reduces computational complexity and resource consumption, improves the system's response speed and robustness, and can continue to generate target answers without sufficient context information.
Smart Images

Figure CN119557392A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of search question answering and deep learning technology, and in particular to an intelligent question answering method, device, equipment and medium. Background Art
[0002] With the rapid development of information technology, especially the widespread application of big data and artificial intelligence technology, the retrieval-augmented generation (RAG) system, as an emerging natural language processing (NLP) technology, has gradually demonstrated its unique advantages in many professional fields such as medicine, law, and search. By combining retrieval technology with generation models, the RAG system can quickly provide accurate and up-to-date answers to queries in specific fields or highly specialized areas, effectively responding to the challenges of rapid information evolution. In the technical architecture of the RAG system, the retrieval module is responsible for efficiently recalling document fragments that are highly relevant to user questions from a huge document library, while the question-answering module generates answers based on these relevant documents using a pre-trained large model. This model not only ensures the real-time and accuracy of the answers, but also gives the system the ability to handle complex and professional queries.
[0003] However, traditional retrieval question answering systems usually rely on keyword matching or simple semantic similarity calculations to retrieve relevant information from reference documents. This method is incapable of handling complex queries or when in-depth understanding of the document context is required, and it is easy to lead to biased or missed answers, greatly reducing the accuracy of the answers.
[0004] Moreover, with the explosive growth of data volume, how to efficiently retrieve and process relevant information in massive text data has become an urgent problem to be solved. Traditional traversal retrieval methods are not only time-consuming, but also difficult to cope with real-time question-answering needs. In the process of generating answers, if each step relies on complex calculations or reasoning, it will greatly reduce the response speed of the system.
[0005] Based on this, although the RAG system shows great potential in applications in specific fields, it still faces many challenges in terms of answer generation efficiency and accuracy. Summary of the invention
[0006] The present application provides an intelligent question-answering method, apparatus, device and medium for solving the problems of low efficiency and poor accuracy of existing intelligent question-answering solutions.
[0007] In a first aspect, the present application provides an intelligent question-answering method, the method comprising:
[0008] Obtain inquiry text, Q&A instructions, and reference documents;
[0009] By means of a pre-trained retrieval question-answering model, based on the query text, the question-answering instruction, and the reference document, tokens in the target answer are iteratively generated until the end symbol of the target answer is generated;
[0010] During each iteration:
[0011] Through the retrieval question-answering model, based on the query text, the question-answering instruction, the reference document and the currently generated target answer, the currently generated target answer is updated; wherein the content of the currently generated target answer of the first iteration is empty;
[0012] Determine the reference token in the updated target answer;
[0013] Retrieving the reference token in the reference document;
[0014] If it is determined that there is only one first segment matching the reference token in the reference document, a second segment is obtained; wherein the second segment is a segment after the first segment in the reference sentence, and the reference sentence is the sentence to which the first segment belongs in the reference document; through the retrieval question-answering model, a predicted segment is generated based on the query text, the question-answering instruction, the reference document, the updated target answer and the second segment; a valid segment is determined based on the difference between the predicted segment and the second segment; and the target answer currently generated in the next iteration is determined by splicing the valid segment after the updated target answer;
[0015] Otherwise, the updated target answer is determined as the currently generated target answer in the next iteration.
[0016] In a second aspect, the present application further provides an intelligent question-answering device, the device comprising:
[0017] An acquisition unit, used to acquire inquiry text, question and answer instructions, and reference documents;
[0018] A processing unit, configured to iteratively generate a token in a target answer based on the query text, the question-answering instruction, and the reference document by using a pre-trained retrieval question-answering model, until an end symbol of the target answer is generated;
[0019] The processing unit is specifically used to:
[0020] Through the retrieval question-answering model, based on the query text, the question-answering instruction, the reference document and the currently generated target answer, the currently generated target answer is updated; wherein the content of the currently generated target answer of the first iteration is empty;
[0021] Determine the reference token in the updated target answer;
[0022] Retrieving the reference token in the reference document;
[0023] If it is determined that there is only one first segment matching the reference token in the reference document, a second segment is obtained; wherein the second segment is a segment after the first segment in the reference sentence, and the reference sentence is the sentence to which the first segment belongs in the reference document; through the retrieval question-answering model, a predicted segment is generated based on the query text, the question-answering instruction, the reference document, the updated target answer and the second segment; a valid segment is determined based on the difference between the predicted segment and the second segment; and the target answer currently generated in the next iteration is determined by splicing the valid segment after the updated target answer;
[0024] Otherwise, the updated target answer is determined as the currently generated target answer in the next iteration.
[0025] In a third aspect, the present application provides a computer device, which includes a processor, and the processor is used to implement the steps of the intelligent question and answer method as described above when executing a computer program stored in a memory.
[0026] In a fourth aspect, the present application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the intelligent question-answering method as described above.
[0027] The beneficial effects of this application are as follows:
[0028] 1. By iteratively generating tokens, the retrieval question-answering model can gradually build the target answer, avoiding the computational complexity and resource consumption that may be caused by generating the entire answer at one time.
[0029] 2. In each iteration, the retrieval question answering model takes into account the currently generated target answer, query text, question answering instructions, and reference documents, which helps improve the accuracy and relevance of the answer.
[0030] 3. When it is determined that there is only one first segment matching the reference token in the reference document, obtain the second segment after the first segment in the reference document so that the retrieval question-answering model can further combine the second segment, that is, combine the following information of the first segment to generate a predicted segment, thereby improving the relevance of the predicted segment to the query text, and the subsequent valid segment determined based on the predicted segment has stronger traceability.
[0031] 4. When it is determined that there is only one first fragment matching the reference token in the reference document, the retrieval question and answer model can generate a predicted fragment based on the query text, the question and answer instructions, the reference document, the reference token and the second fragment, thereby achieving the generation of multiple tokens in one iteration, greatly improving the efficiency of generating the target answer.
[0032] 5. When there are multiple first fragments matching the reference token in the reference document, or when there is no first fragment matching the reference token, the updated target answer is determined as the currently generated target answer in the next iteration, thereby ensuring that the target answer can continue to be generated even in the absence of sufficient contextual information, thereby improving robustness. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments 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 drawings can be obtained based on these drawings without paying creative labor.
[0034] Figure 1 A schematic diagram of an intelligent question-answering process provided in an embodiment of the present application;
[0035] Figure 2 A schematic diagram of a specific intelligent question-answering process provided in an embodiment of the present application;
[0036] Figure 3 A schematic diagram of the structure of an intelligent question-answering device provided in an embodiment of the present application;
[0037] Figure 4 It is a structural schematic diagram of a computer device provided in an optional embodiment of the present application. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0039] In order to improve the accuracy and efficiency of intelligent question answering, the present application provides an intelligent question answering method, device, equipment and medium.
[0040] Embodiment 1:
[0041] This application provides an intelligent question-answering method. Figure 1 A schematic diagram of an intelligent question-answering process provided in an embodiment of the present application, the process includes:
[0042] S101: Obtain inquiry text, question and answer instructions, and reference documents.
[0043] In the present application, the intelligent question-answering method is applied to a computer device, which may be an intelligent terminal, such as a computer, a robot, etc., or a server, such as an application server, a business server, etc.
[0044] The query text refers to the question or query raised by the user, which is the starting point for generating answers. It can be any form of natural language text, such as "What will the weather be like tomorrow?" or "Please explain the concept of quantum entanglement." For example, the user can enter the question in text form through a graphical user interface (GUI), a command line interface (CLI), or an API call, or enter the question in voice form through a recording device. The system receives and parses the user input and converts it into an internal representation (such as a text string).
[0045] Question-answering instructions are specific instructions or requirements for how the model should generate answers based on questions, which may include the format, length, content direction, etc. of the answer. In some cases, question-answering instructions can be embedded directly in the query text or as part of the system configuration. In some more complex scenarios, it can be an independent input, allowing users or system administrators to have more fine-grained control over the answer process.
[0046] Reference documents refer to text or documents that contain information about possible answers. They are the data source from which the model extracts information to generate answers. The reference documents can be uploaded by users or retrieved by the system from sources such as books, articles, web pages, and database records. The system can search these documents for information related to the query text to generate answers. The quality and relevance of reference documents are critical to generating accurate answers.
[0047] S102: With the help of a pre-trained retrieval question-answering model, based on the query text, the question-answering instructions, and the reference document, iteratively generate tokens in the target answer until the end symbol of the target answer is generated.
[0048] In the present application, a retrieval question-answering model is pre-trained, which is a machine learning model that can understand and process natural language and retrieve and generate answers from given data. After obtaining the query text, question-answering quality, and reference text based on the above embodiment, the query text, question-answering quality, and reference text can be used as input to the retrieval question-answering model, so that the retrieval question-answering model can generate a target answer based on the input information.
[0049] Exemplarily, the retrieval question answering model can gradually generate each token in the answer based on the input of the current state until the end of the answer is encountered. The token predicted in each iteration is added to the generated answer sequence until the predicted token is the preset end. The end can be a predefined special token (such as <eos>), or use specific punctuation marks (such as a period, question mark?) as the end of the answer, or the retrieval question answering model can learn to stop generating when it detects a specific relationship between sentences or semantic changes.
[0050] When the terminator is encountered, the retrieval question answering model stops iterating and outputs the generated token sequence as the target answer.
[0051] Suppose there is a medical retrieval question-answering system. The user enters the query text "What medicine should I take when I have a cold?" The question-answering instruction requires a concise and clear answer. The reference document contains a series of information about cold treatments and medicines. The retrieval question-answering model is called to iteratively generate the target answer based on the query text, question-answering instructions, and reference documents until the end of the target answer is generated.
[0052] During each iteration:
[0053] S102a: Through the retrieval question and answer model, based on the query text, the question and answer instructions, the reference document and the currently generated target answer, the currently generated target answer is updated; wherein the content of the currently generated target answer of the first iteration is empty.
[0054] In each iteration, the retrieval question and answer model can update the currently generated target answer based on the current input information (including the query text, question and answer instructions, reference documents, and the currently generated target answer). In the first iteration, since there is no generated target answer, the currently generated target answer is empty. That is to say, in the first iteration, the retrieval question and answer model is used to update the currently generated target answer based on the query text, question and answer instructions, and reference documents.
[0055] Exemplarily, the query text, question-answering instructions, reference documents, and the currently generated target answer (empty for the first time) are passed as input to the retrieval question-answering model. The retrieval question-answering model may contain multiple components, such as an encoder (processing input information), a retriever (retrieving relevant information from reference documents), and a decoder (generating output based on the retrieved information and input). The retrieval question-answering model updates the currently generated target answer based on the input information through its internal mechanisms (such as attention mechanism, sequence-to-sequence conversion, etc.).
[0056] S102b: Determine the reference token in the updated target answer.
[0057] After obtaining the updated target answer based on the above embodiment, a reference token may be determined from the updated target answer, wherein the reference token may be a word, a phrase or a special mark used to construct a part of the answer.
[0058] For example, a token at a preset position in the updated target answer may be determined as a reference token. For another example, the entire updated target answer may be determined as a reference token.
[0059] In a possible implementation, determining a reference token in the updated target answer includes:
[0060] The reference token is determined from the updated target answer through the saved tracing dictionary; wherein the tracing dictionary saves the second position information of the reference token in the updated target answer, the end position of the second position information is the end position of the updated target answer, and the starting position of the second position information is 0 during the first iteration.
[0061] In the present application, a traceability dictionary is pre-established, through which the position information of the reference token in the updated target answer can be recorded (recorded as the second position information). The second position information may include a starting position and an ending position. Optionally, the second position information may also include a length, so that a specific part can be quickly located from the updated target answer when needed. Among them, the end position of the second position information is the end position of the updated target answer.
[0062] It should be noted that the initialized traceability dictionary is empty.
[0063] In the first iteration, since the entire target answer is newly generated, the starting position in the source dictionary is usually set to 0, or to the starting position of the updated target answer. In each subsequent iteration, the starting position of the reference token in the source dictionary can be flexibly updated according to needs.
[0064] S102c: Retrieve the reference token from the reference document.
[0065] After obtaining the reference token based on the above embodiment, the fragment matching the reference token (recorded as the first fragment) can be retrieved in the reference document to extract the most relevant and useful information fragments from the huge reference document collection. Exemplarily, the generated reference token is used as a query to perform a retrieval operation in the reference document. Among them, the retrieval algorithm may find the document fragments most relevant to the reference token based on text similarity, keyword matching or other advanced NLP techniques. These fragments may contain the information needed to directly answer the query text, or provide context for the retrieval question and answer model to further generate answers.
[0066] In a possible implementation, the method further includes iteratively generating a token in a target answer based on the query text, the question and answer instruction, and the reference document by using a pre-trained retrieval question and answer model until the end of the target answer is generated:
[0067] A prefix tree of the reference document is obtained to retrieve the reference token in the prefix tree.
[0068] In order to facilitate the subsequent retrieval of reference tokens in the reference document, in the present application, a prefix tree of the reference document can be generated based on the reference document. For example, if the reference document is one article, a prefix tree is generated directly based on the reference document. For another example, if the reference document is multiple articles, the multiple reference documents can be spliced, and then a prefix tree is generated based on the spliced reference document. Exemplarily, all possible tokens are extracted from the reference document and constructed into a prefix tree. Each node of this prefix tree represents a character, and the character sequence on the path from the root node to any node constitutes a prefix of a token, so that any token contained in the reference document can be quickly located through the prefix tree. Whenever a reference token needs to be retrieved in a reference document, the constructed prefix tree can be used for quick retrieval.
[0069] In a possible implementation, the retrieving the reference token in the prefix tree includes:
[0070] The matching position of the reference token is searched in the prefix tree by using the AC automaton algorithm.
[0071] In order to improve the efficiency of intelligent question answering, in this application, when the AC automaton algorithm is used to search for a reference token in a prefix tree, the AC automaton algorithm can start from the root node of the prefix tree and traverse in the order of characters in the reference token. For each character, if the character matches the current node, the AC automaton algorithm will try to move along the child nodes of the current node. If the current character does not match, the algorithm will backtrack along the failure pointer until a matching character is found or the root node is reached. During the traversal process, the AC automaton algorithm records a match whenever a node marked as the end of a token is reached. At the same time, the AC automaton can also report the matching positions of all text fragments that match the reference token.
[0072] S102d: If it is determined that there is only one first fragment matching the reference token in the reference document, then obtain a second fragment; wherein the second fragment is the fragment after the first fragment in the reference sentence, and the reference sentence is the sentence to which the first fragment belongs in the reference document; through the retrieval question and answer model, based on the query text, the question and answer instructions, the reference document, the updated target answer and the second fragment, generate a predicted fragment; based on the difference between the predicted fragment and the second fragment, determine a valid fragment; and determine the currently generated target answer in the next iteration by splicing the valid fragment after the updated target answer.
[0073] Based on the method in the above embodiment, a first segment matching the reference token can be determined from the reference document, and a valid segment can be determined based on the first segment. Exemplarily, if it is determined that there is only one first segment matching the reference token in the reference document, the content after the first segment in the reference document (recorded as the second segment) can be further considered, so that a predicted segment can be generated based on the second segment.
[0074] In one example, based on the above embodiment, it is determined that there is only one first segment matching the reference token in the reference document, then the sentence to which the first segment belongs in the reference document (recorded as the reference sentence) can be determined. Then, the content after the first segment in the reference sentence is determined as the second segment. The second segment may include punctuation marks, spaces, and any characters immediately following the first segment until the end of the reference sentence.
[0075] In a possible implementation, obtaining the second segment includes:
[0076] According to the prefix tree, recording the first position information of the matching position; wherein the first position information includes an end position;
[0077] Based on the first position information, determining the reference sentence from the reference document;
[0078] The segment after the end position in the reference sentence is determined as the second segment.
[0079] In the present application, the reference token can be retrieved through a prefix tree, and the position information of the first fragment (recorded as the first position information) can be obtained through the prefix tree. When searching using the prefix tree, if the first fragment matching the reference token is found, the first position information of the matching position can be recorded. Among them, the first position information includes the end position of the first fragment in the reference document. Optionally, the first position information may also include the starting position of the first fragment in the reference document. Based on the first position information, the reference sentence to which the first fragment belongs can be quickly searched from the reference document, and then the second fragment can be determined from the reference sentence. Exemplarily, the fragment after the end position in the reference sentence is determined as the second fragment.
[0080] In a possible implementation, the method further includes iteratively generating a token in a target answer based on the query text, the question and answer instruction, and the reference document by using a pre-trained retrieval question and answer model until the end of the target answer is generated:
[0081] A sentence separator set is obtained to determine the reference sentence through the sentence separator set; wherein the sentence separator set includes a symbol representing the end of a sentence.
[0082] In order to facilitate the determination of the reference sentence to which the first fragment belongs, in the present application, a sentence separator set including symbols representing the end of a sentence is pre-configured, through which the end position of the reference sentence can be accurately determined, thereby accurately extracting the reference sentence from the reference document. For example, {"?",",".","!","?",","!","\n"}, etc., in actual implementation, a suitable punctuation set is selected as needed. Exemplarily, after the first position information is determined based on the above embodiment, a segment of the first position information can be determined in the reference document, and traversal can be continued backward from the segment until any symbol in the sentence separator set is traversed. The second segment is determined based on the content between the first position information and the traversed symbol.
[0083] After the second segment is determined based on the above embodiment, the second segment can be spliced to the updated target answer, and then the predicted segment is generated based on the query text, the question and answer instructions, the reference document and the spliced token by retrieving the question and answer model. That is, the predicted segment is generated based on the query text, the question and answer instructions, the reference document, the updated target answer and the second segment by retrieving the question and answer model.
[0084] After obtaining the predicted segment, the valid segment can be determined based on the predicted segment. For example, the predicted segment can be directly determined as the valid segment. Then, the currently generated target answer in the next iteration is determined by splicing the valid segment after the updated target answer, that is, the spliced target answer is used as the information input to the retrieval question answering model in the next iteration.
[0085] In a possible implementation manner, determining a valid segment based on a difference between the predicted segment and the second segment includes:
[0086] Starting from the first token of the predicted segment, traverse to the token that is inconsistent with the second segment for the first time;
[0087] Deleting the segment after the inconsistent token in the predicted segment;
[0088] The retained segments in the predicted segments are determined as the valid segments.
[0089] Considering that the predicted fragment generated by the retrieval question-answering model may contain content that is irrelevant to the query text, thereby affecting the accuracy of the obtained valid fragment. Based on this, in the present application, by comparing the second fragment and generating the predicted fragment, it is possible to ensure that the valid fragment is the content that the reference document and the model prediction agree on. Exemplarily, after obtaining the predicted fragment based on the above embodiment, it is possible to start from the first token of the predicted fragment and traverse each token in the predicted fragment one by one to see if it is consistent with the token at the corresponding position in the second fragment. If it is found that the token at a certain position in the predicted fragment is inconsistent with the token at that position in the second fragment, it means that there is a difference between the content after that position in the predicted fragment and the content after that position in the second fragment, then the token at this position in the predicted fragment is determined as an inconsistent token, and the fragment after the inconsistent token in the predicted fragment is deleted, so as to achieve the deletion of the fragment predicted incorrectly by the retrieval question-answering model as much as possible, and avoid the fragment predicted incorrectly affecting the token generation in subsequent iterations. Then the fragment retained in the predicted fragment is determined as a valid fragment.
[0090] In a possible implementation, if the reference token is determined by the second position information stored in the source dictionary, then during each iteration, if it is determined that there is no first fragment matching the reference token in the reference document, or there are multiple first fragments matching the reference token in the reference document, the starting position of the second position information in the source dictionary is updated by adding one to the end position of the second position information.
[0091] S102d': Otherwise, the updated target answer is determined as the currently generated target answer in the next iteration.
[0092] When it is determined based on the above embodiment that there is no first fragment matching the reference token in the reference document, indicating that there is no fragment with guiding significance in the reference document, the updated target answer can be determined as the currently generated target answer in the next iteration, that is, the updated target answer is used as the information input into the retrieval question and answer model in the next iteration.
[0093] When retrieving a reference token in a reference document, there may be multiple fragments in the reference document that match the reference token, that is, there may be multiple first fragments. In this case, the multiple first fragments may not be able to uniformly give a unified prompt, and are very likely to provide redundant information that affects the generation of the target answer. Based on this, in this application, if it is determined that there are multiple fragments in the reference document that match the reference token, the updated target answer can be determined as the currently generated target answer in the next iteration, that is, the updated target answer is used as the information input into the retrieval question-answering model in the next iteration.
[0094] In certain possible application scenarios, especially in areas with extremely high requirements for accuracy, authority and traceability, such as legal questions and answers, medical consultation, academic research, etc., it is crucial to ensure that the answers are accurate and attached with clear references to the original text. These scenarios not only require that the content of the answer is basically faithful to the original text, but also emphasize that it must be traced back to the specific source for review and verification by users or auditors. Based on this, in the present application, when there is only one first fragment matching the reference token in the reference document, the traceability of the reference token can be recorded, so as to ensure the accuracy of the answer while significantly improving the traceability and authority of the answer. It is particularly suitable for application scenarios that have extremely high requirements for information accuracy and reliability, and it is also convenient for subsequent rapid indexing of the reference token in the reference document. Exemplarily, the correspondence between the first position information of the first fragment and the second position information of the reference token can be recorded through the traceability dictionary. Specifically, when it is determined that there is only one first segment matching the reference token in the reference document, the correspondence between the first position information of the first segment and the second position information of the reference token can be recorded in the source dictionary, that is, the correspondence is updated. For example, the following data format is used to record the correspondence:
[0095] {t start :{t end :(s start ,s end )}}
[0096] Among them, t start and t end Respectively represent the starting position and ending position in the second position information of the reference token, s start and end Respectively represent the starting position and the ending position in the first position information of the first segment.
[0097] The beneficial effects of this application are as follows:
[0098] 1. By iteratively generating tokens, the retrieval question-answering model can gradually build the target answer, avoiding the computational complexity and resource consumption that may be caused by generating the entire answer at one time.
[0099] 2. In each iteration, the retrieval question answering model takes into account the currently generated target answer, query text, question answering instructions, and reference documents, which helps improve the accuracy and relevance of the answer.
[0100] 3. When it is determined that there is only one first segment matching the reference token in the reference document, obtain the second segment after the first segment in the reference document so that the retrieval question-answering model can further combine the second segment, that is, combine the following information of the first segment to generate a predicted segment, thereby improving the relevance of the predicted segment to the query text, and the subsequent valid segment determined based on the predicted segment has stronger traceability.
[0101] 4. When it is determined that there is only one first fragment matching the reference token in the reference document, the retrieval question and answer model can generate a predicted fragment based on the query text, the question and answer instructions, the reference document, the reference token and the second fragment, thereby achieving the generation of multiple tokens in one iteration, greatly improving the efficiency of generating the target answer.
[0102] 5. When there are multiple first fragments matching the reference token in the reference document, or when there is no first fragment matching the reference token, the updated target answer is determined as the currently generated target answer in the next iteration, thereby ensuring that the target answer can continue to be generated even in the absence of sufficient contextual information, thereby improving robustness.
[0103] Embodiment 2:
[0104] The intelligent question-answering method provided by this application is described below through specific embodiments. Figure 2 A schematic diagram of a specific intelligent question-answering process provided in an embodiment of the present application, the process includes:
[0105] S201: Obtain inquiry text, question and answer instructions, and reference documents.
[0106] For example, the Q&A instruction is: "You are a government official in District B of City A. Please provide professional services according to the following requirements: When answering inquiries from citizens or businesses, you must ensure the professionalism, logic, authenticity and value of the answers. You need to polish the content of [document] to optimize the answers."
[0107] The inquiry text is: "What areas does the enrollment scope of a certain primary school include?" [Monthly Question],
[0108] The reference documents are: Appendix 2: Admissions plan for university district schools in the compulsory education stage in the fall of 2023 in District B of City A - Appendix: - Appendix 1: Table of admissions scope for university district schools in the compulsory education stage in the fall of 2023 in District B - 1. The scope of single-school zoning for university district schools - Primary school of a certain middle school education group - Primary school of a certain middle school education group, the scope of single-school zoning: east of Renmin Road, south of Bulong Road, west of Longhua Avenue, north of Minxing Street, and east of Mintang Road.
[0109] S202: Generate a prefix tree based on the reference document.
[0110] S203: Configure a sentence separator set and initialize a source tracing dictionary.
[0111] The tracing dictionary records the correspondence between the first position information of the first segment and the second position information of the reference token, and the following data format can be used to record the correspondence:
[0112] {t start :{t end :(s start ,s end )}}
[0113] Among them, t start and t end Respectively represent the starting position and ending position in the second position information of the reference token, s start and end Respectively represent the starting position and the ending position in the first position information of the first segment.
[0114] It should be noted that the initialized traceability dictionary is empty.
[0115] Call the pre-trained retrieval question-answering model to iteratively generate tokens in the target answer based on the query text, question-answering instructions, and reference documents until the end of the target answer is generated.
[0116] For each iteration, the following steps are performed:
[0117] S204: By retrieving the question-answering model, based on the query text, question-answering instructions, reference documents and the currently generated target answer, the currently generated target answer is updated.
[0118] Among them, the currently generated target answer content of the first iteration is empty.
[0119] S205: Determine the reference token from the updated target answer through the source dictionary, and search for the matching position of the reference token in the prefix tree through the AC automaton algorithm.
[0120] Among them, during the first iteration, the starting position of the second position information is 0, and the ending position of the reference token is the ending position of the updated target answer.
[0121] S206: Determine whether there is only one first segment matching the reference token in the reference document. If so, execute S207; otherwise, execute S214.
[0122] S207: Record the first position information of the matching position according to the prefix tree.
[0123] S208: Determine a reference sentence from a reference document based on the first position information and the sentence separator set.
[0124] S209: Determine the segment after the end position in the reference sentence as the second segment.
[0125] S210: In the traceability dictionary, the first position information and the second position information of the reference token are stored in correspondence.
[0126] S211: Generate a predicted segment based on the query text, question and answer instructions, reference documents, updated target answers, and the second segment by retrieving the question and answer model.
[0127] S212: Starting from the first token of the predicted segment, traverse to the token that is inconsistent with the second segment for the first time, delete the segment after the inconsistent token in the predicted segment, and then determine the retained segment in the predicted segment as a valid segment.
[0128] For example, when the currently generated target answer is "according to" and the reference token is "City A", the reference sentence that can be uniquely matched by the reference token "City A" in the reference document is determined to be "2023 Fall Compulsory Education Stage University District School Enrollment Plan - Attachment for District B, City A", and the second segment G is obtained from the reference sentence. ideal The prediction segment G is generated by retrieving the question-answering model based on the query text, question-answering instructions, reference documents, the currently generated target answer, the reference token, and the second segment. fact It is the annex to the "B District 2023 Fall Compulsory Education Stage University District School Enrollment Plan". By comparing G fact and G ideal , determine G fact Middle and G ideal The first inconsistency is "》", then in G fact Delete the "Attachment" segment after "》" to get the valid segment G. update The valid segment and G update After splicing it in sequence to the currently generated target answer "according to", we get "according to the "Admissions Plan for University District Schools in the Compulsory Education Stage in the Fall of 2023, District B, City A"".
[0129] S213: Determine the target answer currently generated in the next iteration by splicing the valid fragments to the updated target answer, and execute S215.
[0130] S214: Determine the updated target answer as the currently generated target answer in the next iteration, and update the starting position of the second position information in the source tracing dictionary by adding one to the ending position of the second position information.
[0131] S215: Determine whether the pre-configured end symbol has been generated in the currently generated target answer. If so, end; otherwise, execute S204.
[0132] Embodiment 3:
[0133] Based on the same inventive concept, the present application also provides an intelligent question-answering device, Figure 3 A schematic diagram of the structure of an intelligent question-answering device provided in an embodiment of the present application, the device comprising:
[0134] An acquisition unit 31 is used to acquire the inquiry text, question and answer instructions, and reference documents;
[0135] A processing unit 32, configured to iteratively generate a token in a target answer based on the query text, the question-answering instruction, and the reference document by using a pre-trained retrieval question-answering model, until an end symbol of the target answer is generated;
[0136] The processing unit 32 is specifically configured to:
[0137] Through the retrieval question-answering model, based on the query text, the question-answering instruction, the reference document and the currently generated target answer, the currently generated target answer is updated; wherein the content of the currently generated target answer of the first iteration is empty;
[0138] Determine the reference token in the updated target answer;
[0139] Retrieving the reference token in the reference document;
[0140] If it is determined that there is only one first segment matching the reference token in the reference document, a second segment is obtained; wherein the second segment is a segment after the first segment in the reference sentence, and the reference sentence is the sentence to which the first segment belongs in the reference document; through the retrieval question-answering model, a predicted segment is generated based on the query text, the question-answering instruction, the reference document, the updated target answer and the second segment; a valid segment is determined based on the difference between the predicted segment and the second segment; and the target answer currently generated in the next iteration is determined by splicing the valid segment after the updated target answer;
[0141] Otherwise, the updated target answer is determined as the currently generated target answer in the next iteration.
[0142] The intelligent question-answering device in this embodiment is presented in the form of a functional module, where the module refers to an application-specific integrated circuit (ASIC), a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0143] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0144] Embodiment 4:
[0145] See also Figure 4 , Figure 4 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present application, such as Figure 4 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 4 A processor 10 is taken as an example.
[0146] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0147] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.
[0148] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created by the use of a computer device based on the presentation of a small program landing page, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0149] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0150] The computer device also includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 may be connected via a bus or other means. Figure 4 The example of connecting through bus is taken in the following.
[0151] The input device 30 can receive input digital or character information, and generate key signal input related to the user settings and function control of the computer device, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator bar, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 may include a display device, an auxiliary lighting device (e.g., an LED) and a tactile feedback device (e.g., a vibration motor), etc. The above-mentioned display device includes but is not limited to a liquid crystal display, a light emitting diode, a display and a plasma display. In some optional embodiments, the display device can be a touch screen.
[0152] Embodiment 5:
[0153] On the basis of the above embodiments, an embodiment of the present application further provides a computer-readable storage medium, in which a computer program executable by a processor is stored. When the program runs on the processor, the processor implements the following steps when executing:
[0154] Obtain inquiry text, Q&A instructions, and reference documents;
[0155] By means of a pre-trained retrieval question-answering model, based on the query text, the question-answering instruction, and the reference document, tokens in the target answer are iteratively generated until the end symbol of the target answer is generated;
[0156] During each iteration:
[0157] Through the retrieval question-answering model, based on the query text, the question-answering instruction, the reference document and the currently generated target answer, the currently generated target answer is updated; wherein the content of the currently generated target answer of the first iteration is empty;
[0158] Determine the reference token in the updated target answer;
[0159] Retrieving the reference token in the reference document;
[0160] If it is determined that there is only one first segment matching the reference token in the reference document, a second segment is obtained; wherein the second segment is a segment after the first segment in the reference sentence, and the reference sentence is the sentence to which the first segment belongs in the reference document; through the retrieval question-answering model, a predicted segment is generated based on the query text, the question-answering instruction, the reference document, the updated target answer and the second segment; a valid segment is determined based on the difference between the predicted segment and the second segment; and the target answer currently generated in the next iteration is determined by splicing the valid segment after the updated target answer;
[0161] Otherwise, the updated target answer is determined as the currently generated target answer in the next iteration.
[0162] Since the principle of solving the problem by the above-mentioned computer-readable storage medium is similar to that of the intelligent question-answering method, the implementation of the above-mentioned computer-readable storage medium can refer to the embodiment of the method, and the repeated parts will not be repeated.
[0163] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.< / eos>
Claims
1. An intelligent question-answering method, characterized in that: The method comprises: Obtain inquiry text, Q&A instructions, and reference documents; By means of a pre-trained retrieval question-answering model, based on the query text, the question-answering instruction, and the reference document, tokens in the target answer are iteratively generated until the end symbol of the target answer is generated; During each iteration: Through the retrieval question and answer model, based on the query text, the question and answer instruction, the reference document and the currently generated target answer, the currently generated target answer is updated; wherein the content of the currently generated target answer of the first iteration is empty; Determine the reference token in the updated target answer; Retrieving the reference token in the reference document; If it is determined that there is only one first segment matching the reference token in the reference document, a second segment is obtained; wherein the second segment is a segment after the first segment in the reference sentence, and the reference sentence is the sentence to which the first segment belongs in the reference document; through the retrieval question-answering model, a predicted segment is generated based on the query text, the question-answering instruction, the reference document, the updated target answer and the second segment; a valid segment is determined based on the difference between the predicted segment and the second segment; and the target answer currently generated in the next iteration is determined by splicing the valid segment after the updated target answer; Otherwise, the updated target answer is determined as the currently generated target answer in the next iteration.
2. The method according to claim 1, characterized in that The method further comprises: iteratively generating a token in a target answer based on the query text, the question-answering instruction, and the reference document by using a pre-trained retrieval question-answering model until the end of the target answer is generated: A prefix tree of the reference document is obtained to retrieve the reference token in the prefix tree.
3. The method according to claim 2, characterized in that The retrieving the reference token in the prefix tree includes: The matching position of the reference token is searched in the prefix tree by using the AC automaton algorithm.
4. The method according to claim 3, characterized in that The obtaining of the second fragment comprises: According to the prefix tree, recording the first position information of the matching position; wherein the first position information includes an end position; Based on the first position information, determining the reference sentence from the reference document; The segment after the end position in the reference sentence is determined as the second segment.
5. The method according to claim 1 or 4, characterized in that The method further comprises: iteratively generating a token in a target answer based on the query text, the question-answering instruction, and the reference document by using a pre-trained retrieval question-answering model until the end of the target answer is generated. A sentence separator set is obtained to determine the reference sentence through the sentence separator set; wherein the sentence separator set includes a symbol representing the end of a sentence.
6. The method according to claim 4, characterized in that The step of determining a reference token in the updated target answer includes: The reference token is determined from the updated target answer through the saved tracing dictionary; wherein the tracing dictionary saves the second position information of the reference token in the updated target answer, the end position of the second position information is the end position of the updated target answer, and the starting position of the second position information is 0 during the first iteration.
7. The method according to claim 6, characterized in that During each iteration, the method further comprises: If it is determined that there is no first segment matching the reference token in the reference document, or there are multiple first segments matching the reference token in the reference document, then the starting position of the second position information in the source tracing dictionary is updated by adding one to the ending position of the second position information; If it is determined that there is only one first segment matching the reference token in the reference document, the first position information and the second position information are correspondingly saved in the source tracing dictionary.
8. An intelligent question-answering device, characterized in that: The device comprises: An acquisition unit, used to acquire inquiry text, question and answer instructions, and reference documents; A processing unit, configured to iteratively generate a token in a target answer based on the query text, the question-answering instruction, and the reference document by using a pre-trained retrieval question-answering model, until an end symbol of the target answer is generated; The processing unit is specifically used to: Through the retrieval question and answer model, based on the query text, the question and answer instruction, the reference document and the currently generated target answer, the currently generated target answer is updated; wherein the content of the currently generated target answer of the first iteration is empty; Determine the reference token in the updated target answer; Retrieving the reference token in the reference document; If it is determined that there is only one first segment matching the reference token in the reference document, a second segment is obtained; wherein the second segment is a segment after the first segment in the reference sentence, and the reference sentence is the sentence to which the first segment belongs in the reference document; through the retrieval question-answering model, a predicted segment is generated based on the query text, the question-answering instruction, the reference document, the updated target answer and the second segment; a valid segment is determined based on the difference between the predicted segment and the second segment; and the target answer currently generated in the next iteration is determined by splicing the valid segment after the updated target answer; Otherwise, the updated target answer is determined as the currently generated target answer in the next iteration.
9. A computer device, characterized in that: The computer device includes a processor, and the processor is used to implement the steps of the intelligent question-answering method as described in any one of claims 1 to 7 when executing a computer program stored in a memory.
10. A computer-readable storage medium, characterized in that: It stores a computer program executable by a computer device. When the program is run on the computer device, the computer device executes the steps of the intelligent question-answering method as described in any one of claims 1 to 7.
Citation Information
Cited By
Answer text generation method and device, equipment, storage medium and program product
CN121597795A