An extractive search question and answer method, device, equipment and medium
By employing a restricted decoding mechanism and a copying mechanism to generate answers in an extractive retrieval question-answering system, the problem of inaccurate answers generated by large models is solved, and a close correlation between answers and reference documents is achieved, thereby improving the accuracy and efficiency of the system.
Patent Information
- Application Number
- CN202510179352.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-18
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2045-02-18
AI Technical Summary
In existing extractive retrieval question answering systems, the accuracy and reliability of large-scale model-generated answers are low, especially in special fields such as law and government affairs, where misinterpretation or tampering is prone to occur, leading to serious consequences.
By using a pre-trained retrieval question answering model, new tokens are generated based on the matching status of the current matching token and the reference document, employing a restricted decoding mechanism or a copying mechanism to ensure that the answer closely revolves around the reference document. The restricted decoding mechanism and the copying mechanism are included to handle multiple or single matching text sequences, and positional information is combined to update the information to ensure accuracy.
It improves the accuracy and reliability of answers, ensures consistency between answers and reference documents, reduces computational resource consumption, and enhances response speed and system efficiency.
Smart Images

Figure CN120030128B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of retrieval question answering and deep learning technology, and in particular to an extraction-based retrieval question answering method, apparatus, device and medium. Background Technology
[0002] In this era of information overload, the ability to quickly and accurately retrieve and extract the information users need from massive amounts of data has become a crucial technological challenge. Retrieval-Augmented Generation (RAG) technology has emerged to address this challenge, demonstrating its powerful application potential in specific domains or highly specialized queries due to its unique advantages.
[0003] Currently, the RAG system mainly consists of two modules: a retrieval module and a question-answering module. In the retrieval phase, the system utilizes advanced recall and ranking techniques to quickly locate document fragments highly relevant to the question within a vast document database. This process is akin to precise fishing in a sea of information, aiming to ensure the quality of the foundational data for the subsequent question-answering phase. Subsequently, the large model references these retrieved relevant document fragments to gain a deep understanding of the question and provide an answer. This design enables the RAG system to provide accurate and timely answers to specific questions.
[0004] It is worth noting that in most retrieval and question-answering scenarios, the answers are directly derived from fragments of the original document, i.e., so-called extractive question-answering systems. Such systems require extremely high fidelity to the large model, especially in specialized fields such as law and government affairs, where any misinterpretation or alteration of clauses or policies can have serious consequences. Therefore, ensuring 100% fidelity of the answers has become a core requirement in the RAG field.
[0005] However, large models are not omnipotent in practical applications. Due to their inherent illusionary nature, large models often fall into the trap of fabrication when faced with unfamiliar or difficult-to-understand problems. This problem seriously impairs the accuracy and reliability of RAG systems and has become a technical challenge that urgently needs to be overcome. Summary of the Invention
[0006] This application provides an extractive retrieval question answering method, apparatus, device, and medium to address the problem in existing extractive retrieval question answering systems that large models are not generated according to reference documents, resulting in low reliability and accuracy.
[0007] Firstly, this application provides an extractive retrieval question-answering method, the method comprising:
[0008] S1: Obtain input data containing questions, instructions, and reference documents;
[0009] S2: Based on the input data, generate the first token in the target answer using a pre-trained retrieval question-answering model;
[0010] S3: Determine the first token as the currently matched token;
[0011] S4: Determine whether the currently matched token is at the end of the sentence.
[0012] S4a: If so, then based on the target answer, determine the new token using the retrieval question-answering model;
[0013] S4b: If not, then determine the token generation mechanism based on the matching situation between the current matching token and the reference document, and use the token generation mechanism to generate the new token;
[0014] The token generation mechanism includes:
[0015] Restricted decoding mechanism: When there are multiple text sequences in the reference document that match the current matching token, for each text sequence, determine the adjacent token after the end position index of the text sequence from the reference document; and determine the new token based on the target answer and each of the adjacent tokens through the retrieval question answering model.
[0016] Copying mechanism: When only one text sequence matching the current matching token exists in the reference document, the text segment between the end position index of the text sequence and the target sentence end position is obtained from the reference document; wherein, the target sentence end position is the position of the first symbol belonging to the preset sentence end matching set after the end position index; based on the target answer with the text segment appended to the end, the next token after the text sequence is determined through the retrieval question answering model; the text segment and the next token are determined as the newly added token;
[0017] S5: Append the newly added token to the end of the target answer to update the target answer;
[0018] S6: Determine whether the updated target answer contains the preset terminator.
[0019] S6a: If yes, then end and output the updated target answer;
[0020] S6b: If not, then update the location information of the current matching token based on the matching situation between the current matching token and the reference document; wherein the location information is initialized to empty;
[0021] S7: Update the current matching token based on the updated target answer and the updated position information, and return to execute S4.
[0022] Secondly, this application also provides an extraction-based retrieval question-answering device, the device comprising:
[0023] The acquisition unit is used to acquire input data carrying questions, instructions, and reference documents;
[0024] The processing unit is used to perform the following steps:
[0025] S2: Based on the input data, generate the first token in the target answer using a pre-trained retrieval question-answering model;
[0026] S3: Determine the first token as the currently matched token;
[0027] S4: Determine whether the currently matched token is at the end of the sentence.
[0028] S4a: If so, then based on the target answer, determine the new token using the retrieval question-answering model;
[0029] S4b: If not, then determine the token generation mechanism based on the matching situation between the current matching token and the reference document, and use the token generation mechanism to generate the new token;
[0030] The token generation mechanism includes:
[0031] Restricted decoding mechanism: When there are multiple text sequences in the reference document that match the current matching token, for each text sequence, determine the adjacent token after the end position index of the text sequence from the reference document; and determine the new token based on the target answer and each of the adjacent tokens through the retrieval question answering model.
[0032] Copying mechanism: When only one text sequence matching the current matching token exists in the reference document, the text segment between the end position index of the text sequence and the target sentence end position is obtained from the reference document; wherein, the target sentence end position is the position of the first symbol belonging to the preset sentence end matching set after the end position index; based on the target answer with the text segment appended to the end, the next token after the text sequence is determined through the retrieval question answering model; the text segment and the next token are determined as the newly added token;
[0033] S5: Append the newly added token to the end of the target answer to update the target answer;
[0034] S6: Determine whether the updated target answer contains the preset terminator.
[0035] S6a: If yes, then end and output the updated target answer;
[0036] S6b: If not, then update the position information of the current matching token based on the matching situation between the current matching token and the reference document;
[0037] S7: Update the current matching token based on the updated target answer and the updated position information, and return to execute S4.
[0038] Thirdly, this application provides a computer device including a processor, which executes a computer program stored in a memory to implement the steps of the extractive retrieval question-answering method described above.
[0039] Fourthly, this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the extractive retrieval question-answering method described above.
[0040] The beneficial effects of this application are as follows:
[0041] 1. By acquiring input data containing reference documents and determining the token generation mechanism based on the matching status between the current matching token and the reference document, the answer generation closely revolves around the reference document. When there is matching information in the reference document, whether a restricted decoding mechanism (multiple matching text sequences) or a copying mechanism (only one matching text sequence) is used, relevant content can be extracted from the reference document as a new token. This ensures that the target answer is as faithful as possible to the reference document and consistent with the given information source, thereby improving the accuracy of the target answer.
[0042] 2. During the answer generation process, the position information of the current matching token is continuously updated based on the matching status between the current matching token and the reference document, and the current matching token is updated accordingly. Then, the process is repeated to determine whether it is at the end of the sentence. This process enables the retrieval question answering model to continuously and accurately obtain information from the reference document and gradually generate accurate answers.
[0043] 3. The token generation mechanism includes a restricted decoding mechanism and a copying mechanism, and also considers the case where the number of matching text sequences in the reference document varies. This diverse generation mechanism allows the model to flexibly choose the appropriate method to generate new tokens based on different input conditions. For example, when there are multiple text sequences in the reference document that match the current matching token, the restricted decoding mechanism can comprehensively consider multiple adjacent tokens to determine the new token, increasing the diversity and rationality of the generated answer; while when there is only one matching text sequence, the copying mechanism can directly extract relevant text fragments and efficiently generate the answer.
[0044] 4. Since the copying mechanism does not require generating tokens step by step, nor does it rely on complex language models to perform a lot of calculations and reasoning to generate text, it can directly copy relevant text fragments from reference documents, which greatly reduces the time and computing resources required to generate multiple tokens. It can quickly provide users with the target answer, improving the response speed and overall operating efficiency of the extractive retrieval question answering system. Attached Figure Description
[0045] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0046] Figure 1 A schematic diagram of an extraction-based retrieval question-and-answer process provided in an embodiment of this application;
[0047] Figure 2 A schematic diagram of a specific extraction-based retrieval question-and-answer process is provided for embodiments of this application;
[0048] Figure 3 This is a schematic diagram of the structure of an extraction-type retrieval question-answering device provided in an embodiment of this application;
[0049] Figure 4 This is a schematic diagram of the structure of a computer device provided in an optional embodiment of this application. Detailed Implementation
[0050] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0051] To improve the fidelity of the target answer generated by the extractive retrieval question answering system to the reference document, thereby avoiding the illusion of fabricated answers by the retrieval question answering model, this application provides an extractive retrieval question answering method, apparatus, device, and medium.
[0052] Example 1:
[0053] This application provides an extractive retrieval question-answering method. Figure 1 This application provides a schematic diagram of an extraction-based retrieval question-answering process, which includes:
[0054] S1: Obtain input data containing questions, instructions, and reference documents.
[0055] In this application, the extractive retrieval question-answering method is applied to a computer device, which can be a smart terminal, such as a computer or a robot, or a server, such as an application server or a business server.
[0056] S1 is the starting point of the entire question-and-answer process, requiring the collection of the user's question, accompanying instructions, and related reference documents. The question is the user's expression of their request for specific information; 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, users can input text-based questions through a graphical user interface (GUI), command-line interface (CLI), or API calls, or they can input voice-based questions through a recording device. The computer device can receive and parse the user input, converting it into an internal representation (such as a text string). Instructions are additional requirements from the user regarding the form or content of the answer, providing specific instructions or requirements on how the model should generate an answer based on the question. These may include the answer's format, length, and content direction. In some cases, instructions can be directly embedded in the question or as part of the system configuration. In more complex scenarios, it can be a separate input, allowing users or system administrators more fine-grained control over the answering process. Reference documents are the source library of answers, containing relevant information that might answer the user's question. These reference documents can be uploaded by the user or retrieved by the computer device from sources such as books, articles, web pages, and database records. Computer devices can search these documents for information relevant to the question to generate an answer. The quality and relevance of the referenced documents are crucial for generating an accurate answer.
[0057] In the extractive retrieval question and answer process, the question, instruction requirements, and reference documents can be concatenated to obtain input data carrying the question, instruction requirements, and information from the reference documents. For example, the input data might include: "Reference document: 21.0 Shenzhen Longhua District Several Measures to Promote the Development of the Integrated Circuit Industry Operation Guidelines Integrated Circuit Public Service Platform Construction Funding Operation Guidelines Chapter 1 Application Conditions Article 1 To apply for funding for the construction of an integrated circuit public service platform, the following conditions must be met:"
[0058] (i) The applicant must be an independent legal entity in the field of integrated circuits (excluding public institutions fully funded by the government) whose registered address, actual business address and tax registration address are all located in Longhua District. If the entity is included in the National Bureau of Statistics’ online direct reporting platform, its statistical relationship must be in Longhua District.
[0059] (ii) The public service platform has a clear development direction and service positioning, and provides technical and information services such as the development of common technologies in the integrated circuit industry, testing and verification, and research and consulting.
[0060] (iii) Possess a professional team that provides public services to the outside world, of which there are no fewer than 15 full-time professional and technical personnel, and the proportion of professionals with bachelor’s degree or above and intermediate or above technical titles is no less than 80%.
[0061] (iv) It has the conditions to provide public services to the public, with a site area of not less than 200 square meters, the site is concentrated and contiguous, and the platform operation site is located in Longhua District, Shenzhen.
[0062] (v) The original value of the software and hardware equipment used for scientific research, testing and technical services in the past two years shall not be less than RMB 10 million;
[0063] (vi) The platform has been providing large-scale integrated circuit technology and information services for more than one year;
[0064] (vii) The platform has provided technical and information services to no fewer than 50 enterprises in the past two years;
[0065] (viii) The platform is not a government-invested construction project;
[0066] (ix) The applicant does not fall under any of the circumstances that would preclude funding as stipulated in the relevant management documents of the Longhua District Special Fiscal Funds.
[0067] Instruction Requirements: You are a policy answer extraction model. Please extract the relevant text snippets from the above document that can answer the questions. Note that the answers must be extracted from the original text. If the answer is not included, please reject the answer.
[0068] Question: What are the eligibility requirements for companies to apply for funding for the construction of integrated circuit public service platforms?
[0069] S2: Based on the input data, generate the first token in the target answer using a pre-trained retrieval question-answering model.
[0070] In this application, a retrieval question-answering model is pre-trained. This model is a machine learning model capable of understanding and processing natural language and retrieving and generating answers from given data. After obtaining input data based on the above embodiments, the input data can be used as input to the retrieval question-answering model, enabling the model to generate the first token of the target answer based on the input information.
[0071] The pre-trained retrieval question-answering model is trained on a large amount of text data and question-answer pairs. It can understand the relationship between the input question, instruction requirements, and reference documents, and then begin to generate answers. A token is a basic unit in text processing and can be a word, a subword, or a character.
[0072] S3: Determine the first token as the current matching token.
[0073] After obtaining the first token based on the above embodiment, this first token can be marked as the current matching token. Subsequent operations will revolve around the matching status of this current matching token with the reference document. The current matching token serves as a starting point in the answer generation process, used to compare with the reference document to determine how to continue generating subsequent answer content.
[0074] S4: Determine whether the currently matched token is at the end of the sentence.
[0075] After obtaining the current matching token, it's crucial to determine whether it signifies the end of a sentence. If it does, it indicates a relatively complete semantic unit has been generated, and a different approach may be needed to determine the next token. If it doesn't, a suitable token generation mechanism must be chosen based on the matching between the current token and the reference document.
[0076] In one possible implementation, step S4: determining whether the currently matched token is at the end of a sentence includes:
[0077] Determine whether the last character of the currently matched token belongs to a preset sentence end symbol set; wherein, the preset sentence end symbol set contains pre-configured symbols representing the end of a sentence;
[0078] If so, then the currently matched token is determined to be the end of the sentence;
[0079] If not, then it is determined that the currently matched token is not at the end of the sentence.
[0080] To facilitate determining whether the current matching token is at the end of a sentence, this application pre-configures a set of sentence-end symbols, including symbols representing the end of a sentence. This set of symbols can accurately identify the end of a sentence. Examples include {"?", ",", ".", "!", "?", ",", "!", "\n"}, etc. In practice, a suitable set of symbols is selected as needed. For instance, the last character of the current matching token is first extracted. For example, if the current matching token is "Apple is a fruit.", then the extracted last character is ".". Next, this extracted character is compared with the symbols in the pre-configured set of sentence-end symbols. If the extracted character exists in the pre-configured set of sentence-end symbols, the current matching token is determined to be at the end of a sentence. For example, in the above example, "." belongs to the pre-configured set of sentence-end symbols, so the current matching token "Apple is a fruit." is determined to be at the end of a sentence. Conversely, if the extracted character is not in the pre-configured set of sentence-end symbols, the current matching token is determined not to be at the end of a sentence. For example, if the current matching token is "apple rich", the last character is "containing", which is not in the preset sentence end symbol set, so it is determined that it is not the end of the sentence.
[0081] It's important to note that configuring the symbols in the preset sentence-ending symbol set requires flexibility based on the specific application scenario and language characteristics. If the preset set contains too few symbols, subsequent text fragments copied from the reference document may be too long, and the target answer may not end at the correct position, resulting in an incorrect target answer. Conversely, if the set contains too many symbols, subsequent text fragments copied from the reference document may be too short, and the target answer may lack semantic coherence, thus reducing the fidelity and efficiency of the target answer generation. Therefore, in practice, an appropriate symbol set can be selected as needed. Furthermore, the preset sentence-ending symbol set is not fixed when processing different texts and can be flexibly configured according to requirements. For example, when processing Chinese text, the preset set might include common symbols indicating sentence endings such as ".", "?", "!", and ";". When processing English text, the set might primarily include ".", "?", and "!". For text in certain specific domains, there may also be some special end markers. For example, in program code comment text, the newline character after " / / " may also be regarded as a sentence end marker and thus added to the preset sentence end marker set.
[0082] In another possible implementation, while matching characters to a preset set of sentence-ending symbols is a simple and direct method, it may have limitations for some complex language structures and contexts. For example, in some literary works, ellipses may indicate the end of a sentence but are not explicitly included in the preset set. In such cases, a language model can be used to assist in the judgment. A language model can more accurately determine whether the currently matched token semantically constitutes a complete sentence from both semantic and contextual perspectives. Even if its last character is not in the preset set, it can still be judged as the end of a sentence, thereby further improving the accuracy of the judgment.
[0083] S4a: If so, then based on the target answer, determine the new token using the retrieval question-answering model.
[0084] When the computer determines that the currently matched token is at the end of a sentence, it can use the already generated target answer as contextual information to call the retrieval question-answering model again to predict the next new token. At this point, the retrieval question-answering model will comprehensively consider the content of the previously generated answers and combine it with the overall information of the reference document to determine the next most likely token in order to continue constructing the answer.
[0085] For example, if the current matching token is “Application for funding for the construction of a public service platform for circuits,”, the last character is “,”. This “,” is included in the preset set of sentence-ending symbols, so the current matching token is determined to be at the end of the sentence. Then, based on the target answer that has been generated, the new token is determined by the retrieval question-answering model.
[0086] S4b: If not, then based on the matching status of the current matching token and the reference document, determine the token generation mechanism, and use the token generation mechanism to generate the new token; wherein, the token generation mechanism includes:
[0087] Restricted decoding mechanism: When there are multiple text sequences in the reference document that match the current matching token, for each text sequence, determine the adjacent token after the end position index of the text sequence from the reference document; and determine the new token based on the target answer and each of the adjacent tokens through the retrieval question answering model.
[0088] Copying mechanism: When only one text sequence matching the current matching token exists in the reference document, the text segment between the end position index of the text sequence and the target sentence end position is obtained from the reference document; wherein, the target sentence end position is the position of the first symbol belonging to the preset sentence end matching set after the end position index; based on the target answer with the text segment appended to the end, the next token after the text sequence is determined through the retrieval question answering model; the text segment and the next token are determined as the newly added token.
[0089] If, based on the above embodiments, it is determined that the current matching token is not at the end of the sentence, a suitable token generation mechanism needs to be selected according to its matching with the reference document. This token generation mechanism includes at least a restricted decoding mechanism and a copying mechanism. These restricted decoding and copying mechanisms ensure that the generated target answer is faithful to the reference question and answer. The following is an explanation of each token generation mechanism:
[0090] I. Restricted Decoding Mechanism
[0091] The constrained decoding mechanism is suitable for situations where the reference document is rich in information and has multiple possible continuations. By considering multiple adjacent tokens to generate new tokens, the accuracy and diversity of the answer can be increased. For example, when there are multiple text sequences in the reference document that match the currently matched token, for each matching text sequence, the adjacent token after the end index of that text sequence is determined from the reference document. The new token is then determined by retrieving the question-answering model based on the currently generated target answer and these adjacent tokens.
[0092] In one possible implementation, under a restricted decoding mechanism, since there are multiple text sequences in the reference document that match the currently matched token, each text sequence has a corresponding adjacent token after its end position index. To select the most suitable adjacent token as the new token to add to the target answer, a retrieval question-answering model is needed to evaluate them; scoring is the quantification method of this evaluation. The retrieval question-answering model treats the target answer as important contextual information, comprehensively considering factors such as the semantic relevance, logical coherence, and reasonableness of each adjacent token within the overall context of the reference document, thus assigning a score to each adjacent token. This score reflects the suitability of the adjacent token as a new token. Finally, the computer device selects the adjacent token with the highest score as the new token.
[0093] For example, when the current matching token is "application", there are three matching text sequences for "application" in the reference document. The adjacent tokens corresponding to these three text sequences are obtained: {"process", "unit", "integration"}. Using a question-answering model, the currently generated target answer and these adjacent tokens are processed to obtain the probability that each of these three adjacent tokens will be the next token, i.e., the score of each of these three adjacent tokens. Based on the probabilities corresponding to these three adjacent tokens, "integration" is determined to have the highest probability among them, and therefore, "integration" is identified as the new token.
[0094] II. Replication Mechanism
[0095] When only one text sequence in the reference document matches the current matching token, the text segment between the end index of that text sequence and the target sentence end position can be obtained from the reference document. Here, the target sentence end position refers to the position of the first symbol belonging to the preset sentence end symbol set after that end index. Then, this text segment is appended to the end of the currently generated target answer to obtain a target answer with this text segment appended to its end. Using this retrieval question-answering model, based on the target answer with this text segment appended to its end, the next token after the text sequence is determined. This text segment and the next token are then identified as the new token.
[0096] For example, when the current matching token is "Application for Integration", the unique matching text sequence for "Application for Integration" in the reference document is identified. This text sequence belongs to the sentence "Application for funding for the construction of an integrated circuit public service platform,". The target sentence ending position is determined to be a comma (,). The text segment between the end index of this text sequence and the target sentence ending position is obtained, resulting in the text segment "Funding for the construction of a circuit public service platform". This text segment is then appended to the end of the currently generated target answer. Using this retrieval question-answering model, based on the target answer with this text segment appended to its end, the next token following the text sequence is determined to be a comma (,). At this point, the new token is "Funding for the construction of a circuit public service platform,".
[0097] In one possible implementation, considering that in real-world question-and-answer scenarios, the information in reference documents often has limitations and cannot cover all possible questions and related content, when a user's question involves new knowledge, new viewpoints, or unique and personalized content not included in the reference document, there may be a situation where the reference document lacks a text sequence that matches the current matching token. Therefore, in the construction of an extractive retrieval question-and-answer system, the token generation mechanism can also include a free generation mechanism. This free generation mechanism includes: if no text sequence matching the current matching token exists in the reference document, then, based on the target answer, determining the new token through the retrieval question-and-answer model. When faced with complex and ever-changing user questions, reference documents cannot cover all possible information. The existence of a free generation mechanism ensures that valuable answers are provided in various situations, greatly improving the practicality and adaptability of the extractive retrieval question-and-answer system and effectively solving the problem of the limitations of reference documents. For example, when a comprehensive search in the reference document determines that no text sequence matching the current matching token exists, the free generation mechanism will be activated. This indicates that it is impossible to directly extract information related to the currently matched token from the reference document to generate a new token. The retrieval question-answering model needs to rely on its own language understanding and generation capabilities to create answer content. The retrieval question-answering model uses the currently generated target answer as a key contextual basis, conducts in-depth analysis to understand its semantics, theme, and logical structure, and, based on its language patterns, knowledge, and semantic understanding learned from extensive text training, attempts to generate a new token that is semantically coherent and logically consistent with the target answer.
[0098] In one possible implementation, before S4b, the prefix tree of the reference document is obtained; in S4b, the matching position of the text sequence that matches the currently matching token is searched in the prefix tree using the AC automaton algorithm.
[0099] To facilitate subsequent determination of whether a text sequence matching the currently matched token exists in the reference document, this application can generate a prefix tree based on the reference document. For example, if the reference document is a single document, the prefix tree is directly generated based on it. Alternatively, if there are multiple reference documents, they can be concatenated, and a prefix tree can be generated based on the concatenated document. For instance, all possible tokens are extracted from the reference document and constructed into a prefix tree. Each node in 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. This prefix tree allows for quick location of any token contained in the reference document. Whenever it is necessary to retrieve the currently matched token in the reference document, the constructed prefix tree can be used for rapid retrieval.
[0100] To improve the efficiency of extractive retrieval question answering, this application uses the Aho-Corasick (AC) automaton algorithm to search for text sequences matching the current matching token in the prefix tree. For example, the AC automaton algorithm can start from the root node of the prefix tree and traverse according to the character order of the current matching token. For each character, if it matches the current node, the AC automaton algorithm attempts to move along the child nodes of the current node. If the current character does not match, the algorithm backtracks along the failure pointers until a matching character is found or the root node is reached. During the traversal, the AC automaton algorithm records a match whenever a node marked as the end of a token is reached. Simultaneously, the AC automaton can also report the matching positions of all text segments that match the current matching token.
[0101] S5: Append the newly added token to the end of the target answer to update the target answer.
[0102] The newly generated tokens through the above token generation mechanism are as faithful as possible to the reference documentation. Adding this new token to the end of the existing target answer updates the target answer, allowing it to continuously expand and improve in each iteration, gradually forming a complete answer that remains faithful to the reference documentation.
[0103] S6: Determine whether the updated target answer contains a preset end character.
[0104] After obtaining the updated target answer based on the above embodiments, it can be checked whether the updated target answer contains a preset end character. The preset end character is used to identify whether the target answer is complete; for example, the preset end character could be "". <eos>(An expression for the end of a sentence), etc.
[0105] It should be noted that the choice of preset terminator can be determined based on specific needs and system design. Besides special markers, it can also be specific keywords or phrases, such as "That's the answer." In practical applications, the definition and usage of preset terminators may need to be flexibly adjusted according to different question-and-answer scenarios and user needs.
[0106] S6a: If yes, then end and output the updated target answer.
[0107] If the updated target answer contains the preset terminator, it means the target answer has been successfully generated and can be output. For example, the updated target answer is:
[0108] To apply for funding for the construction of integrated circuit public service platforms, the following conditions must be met:
[0109] (i) The applicant must be an independent legal entity in the field of integrated circuits (excluding public institutions fully funded by the government) whose registered address, actual business address and tax registration address are all located in Longhua District. If the entity is included in the National Bureau of Statistics’ online direct reporting platform, its statistical relationship must be in Longhua District.
[0110] (ii) The public service platform has a clear development direction and service positioning, and provides technical and information services such as the development of common technologies in the integrated circuit industry, testing and verification, and research and consulting.
[0111] (iii) Possess a professional team that provides public services to the outside world, of which there are no fewer than 15 full-time professional and technical personnel, and the proportion of professionals with bachelor’s degree or above and intermediate or above technical titles is no less than 80%.
[0112] (iv) It has the conditions to provide public services to the public, with a site area of not less than 200 square meters, the site is concentrated and contiguous, and the platform operation site is located in Longhua District, Shenzhen.
[0113] (v) The original value of the software and hardware equipment used for scientific research, testing and technical services in the past two years shall not be less than RMB 10 million;
[0114] (vi) The platform has been providing large-scale integrated circuit technology and information services for more than one year;
[0115] (vii) The platform has provided technical and information services to no fewer than 50 enterprises in the past two years;
[0116] (viii) The platform is not a government-invested construction project;
[0117] (ix) The applicant does not fall under any of the circumstances that would preclude funding as stipulated in the relevant management documents of the Longhua District Special Fiscal Funds. <eos>When the value is "", the updated target answer is determined to contain a preset end character, and the updated target answer is output as the final answer.
[0118] S6b: If not, then update the position information of the current matching token based on the matching situation between the current matching token and the reference document.
[0119] If the updated target answer does not contain the preset end-of-response character, it means the target answer is not yet complete and needs to continue generation. At this point, the position information of the current matching token can be updated based on the matching status between the current matching token and the reference document. This is to record the current progress in the target answer generation process so that information can be accurately retrieved from the reference document later.
[0120] It should be noted that this location information is initialized to empty.
[0121] The method for updating location information can be determined based on the specific matching algorithm and data structure. For example, index values or pointers can be used to mark the position of the current matching token in the reference document. Furthermore, when updating location information, factors such as text continuity and semantic relevance may need to be considered to ensure the logical consistency and coherence of subsequently generated answers.
[0122] In one example, S6b includes:
[0123] If a text sequence matching the current matching token exists in the reference document, the end position index of the current matching token is updated by adding a new value to the end position index of the current matching token; wherein, the new value is the number of characters in the new token;
[0124] If there is no text sequence in the reference document that matches the current matching token, then the position index of the character after the last character in the updated target answer is determined as the start position index of the current matching token, and the end position index of the current matching token is updated to empty.
[0125] In this application, when updating the position information of the current matching token based on the matching status between the current matching token and the reference document, the following two cases are mainly included:
[0126] Case A: The reference document contains a text sequence that matches the currently matched token.
[0127] In scenario A, the end position index of the current matching token can be updated by adding a new value to it. This new value represents the number of characters in the new token. For example, suppose the current matching token is "application integration", there is a matching text sequence in the reference document, and the generated new token is "circuit public service platform construction funding," with 13 characters. The original end position index of "application integration" was assumed to be 4 (this index value is just an example), and after updating, the end position index becomes 4 + 13 = 17. This update method records the change in the position of the current matching token in the reference document as the target answer is generated, providing accurate positional information for subsequent information extraction from the reference document. Thus, when looping back to operations such as determining if the current matching token is at the end of a sentence, the updated positional information allows for more precise searching of relevant content in the reference document, ensuring the consistency and accuracy of the answer generation.
[0128] Case B: There is no text sequence in the reference document that matches the currently matched token.
[0129] During the operation of the entire extractive retrieval question-answering system, when situation B occurs—that is, no text sequence in the reference document matches the current matching token—this phenomenon means that the current matching token has lost its reliable correlation within the knowledge system covered by the reference document, indicating that the current matching token has become invalid. This is because, in normal question-answering logic, the role of the matching token is to guide the extractive retrieval question-answering system to extract relevant information from the reference document, thereby generating a reasonable and accurate answer. However, in this case, since there is no corresponding content in the reference document, continuing to guide the generation of subsequent tokens based on the current matching token will not only fail to obtain valuable information from the reference document to enrich the answer, but may also lead to a deadlock in answer generation, affecting the operational efficiency and answer quality of the entire extractive retrieval question-answering system, thus its significance becomes minimal. In this situation, it is necessary to adjust the strategy in a timely manner to ensure that the extractive retrieval question-answering process can proceed smoothly. For example, the position index of the character after the last character in the updated target answer can be determined as the starting position index of the current matching token, while the ending position index of the current matching token is updated to null. For example, if the updated target answer is "Apply for funding to build an integrated circuit public service platform," with the last character being a comma (,), and assuming the index of the last character is 10, then the starting index of the current matching token would be set to 11. Updating the ending index to empty indicates that, in this case, since there is no matching information in the reference document, the ending position of the current matching token cannot be determined temporarily. The ending position will be determined later as more answers are generated, based on the actual situation. This operational logic ensures that even when the reference document lacks relevant matching information, answers can still be generated by adjusting the position information of the current matching token and utilizing a free generation mechanism, maintaining the smooth progress of the entire question-and-answer process.
[0130] S7: Update the current matching token based on the updated target answer and the updated position information, and return to execute S4.
[0131] Because the next matching and generation process may need to be based on a different starting point as the target answer is generated and the position information of the current matching token is updated, the updated target answer and position information can be used to redetermine the current matching token. Then, return to step S4 to continue determining whether the redetermined current matching token is at the end of the sentence, and repeat this process until a complete answer containing the preset end-of-sentence marker is generated.
[0132] The beneficial effects of this application are as follows:
[0133] 1. By acquiring input data containing reference documents and determining the token generation mechanism based on the matching status between the current matching token and the reference document, the answer generation closely revolves around the reference document. When there is matching information in the reference document, whether a restricted decoding mechanism (multiple matching text sequences) or a copying mechanism (only one matching text sequence) is used, relevant content can be extracted from the reference document as a new token. This ensures that the target answer is as faithful as possible to the reference document and consistent with the given information source, thereby improving the accuracy of the target answer.
[0134] 2. During the answer generation process, the position information of the current matching token is continuously updated based on the matching status between the current matching token and the reference document, and the current matching token is updated accordingly. Then, the process is repeated to determine whether it is at the end of the sentence. This process enables the retrieval question answering model to continuously and accurately obtain information from the reference document and gradually generate accurate answers.
[0135] 3. The token generation mechanism includes a restricted decoding mechanism and a copying mechanism, and also considers the case where the number of matching text sequences in the reference document varies. This diverse generation mechanism allows the model to flexibly choose the appropriate method to generate new tokens based on different input conditions. For example, when there are multiple text sequences in the reference document that match the current matching token, the restricted decoding mechanism can comprehensively consider multiple adjacent tokens to determine the new token, increasing the diversity and rationality of the generated answer; while when there is only one matching text sequence, the copying mechanism can directly extract relevant text fragments and efficiently generate the answer.
[0136] 4. Since the copying mechanism does not require generating tokens step by step, nor does it rely on complex language models to perform a lot of calculations and reasoning to generate text, it can directly copy relevant text fragments from reference documents, which greatly reduces the time and computing resources required to generate multiple tokens. It can quickly provide users with the target answer, improving the response speed and overall operating efficiency of the extractive retrieval question answering system.
[0137] Example 2:
[0138] The extraction-based retrieval question-answering method provided in this application will be described below through specific embodiments. Figure 2 This application provides a specific schematic diagram of an extraction-based retrieval question-answering process, which includes:
[0139] S201: Obtain input data carrying questions, instructions, and reference documents.
[0140] S202: Generate a prefix tree based on the reference document.
[0141] S203: Configure the sentence splitter set and the initialization position information of the currently matched token.
[0142] It should be noted that the initial position information is empty.
[0143] S204: Based on the input data, generate the first token of the target answer by retrieving the question-answering model.
[0144] S205: Determine the first token as the currently matched token.
[0145] S206: Determine if the currently matched token is at the end of the sentence. If yes, execute S207; otherwise, execute S208.
[0146] S207: Based on the target answer, determine the new token by retrieving the question-answering model, and execute S214.
[0147] S208: Using the AC automaton algorithm, search for the matching position of the text sequence that matches the currently matched token in the prefix tree.
[0148] S209: Determine if a matching position is found. If yes, execute S210; otherwise, execute S213.
[0149] S210: Determine if the number of matching positions is greater than 1. If yes, execute S211; otherwise, execute S212.
[0150] S211: For each matching position, determine the adjacent tokens after the end position index of the matching position from the reference document. By retrieving the question-answering model, determine the new token based on the target answer and each adjacent token, and execute S214.
[0151] Specifically, by using a retrieval question-answering model, each adjacent token is scored based on the target answer, and the adjacent token with the highest score is selected as the new token.
[0152] S212: Obtain the text fragment between the end position index of the matching position and the end position of the target sentence from the reference document; determine the next token after the text sequence based on the target answer with the text fragment appended to the end by the retrieval question answering model; determine the text fragment and the next token as the new token, and execute S214.
[0153] The target sentence end position is the position of the first symbol belonging to the preset sentence end matching set after the end position index of the matching position.
[0154] S213: Based on the target answer, determine the new token by retrieving the question-answering model.
[0155] S214: Append the new token to the end of the target answer to update the target answer.
[0156] S215: Determine whether the updated target answer contains a preset end character. If yes, end the process; otherwise, proceed to S216.
[0157] S216: Update the position information of the current matching token based on the matching status between the current matching token and the reference document.
[0158] In one possible implementation, S216 includes: if a text sequence matching the current matching token exists in the reference document, updating the end position index of the current matching token by adding a new value to the end position index of the current matching token; wherein the new value is the number of characters in the new token;
[0159] If no text sequence matching the current matching token exists in the reference document, the index of the character following the last character in the updated target answer is determined as the starting index of the current matching token, and the ending index of the current matching token is updated to null.
[0160] S217: Update the current matching token based on the updated target answer and the updated position information, and execute S206.
[0161] Example 3:
[0162] Based on the same inventive concept, this application also provides an extraction-based retrieval question-answering device. Figure 3 This is a schematic diagram of the structure of an extraction-based retrieval question-answering device provided in an embodiment of this application. The device includes:
[0163] The acquisition unit 31 is used to acquire input data carrying questions, instruction requirements, and reference documents;
[0164] Processing unit 32 is used to perform the following steps:
[0165] S2: Based on the input data, generate the first token in the target answer using a pre-trained retrieval question-answering model;
[0166] S3: Determine the first token as the currently matched token;
[0167] S4: Determine whether the currently matched token is at the end of the sentence.
[0168] S4a: If so, then based on the target answer, determine the new token using the retrieval question-answering model;
[0169] S4b: If not, then determine the token generation mechanism based on the matching situation between the current matching token and the reference document, and use the token generation mechanism to generate the new token;
[0170] The token generation mechanism includes:
[0171] Restricted decoding mechanism: When there are multiple text sequences in the reference document that match the current matching token, for each text sequence, determine the adjacent token after the end position index of the text sequence from the reference document; and determine the new token based on the target answer and each of the adjacent tokens through the retrieval question answering model.
[0172] Copying mechanism: When only one text sequence matching the current matching token exists in the reference document, the text segment between the end position index of the text sequence and the target sentence end position is obtained from the reference document; wherein, the target sentence end position is the position of the first symbol belonging to the preset sentence end matching set after the end position index; based on the target answer with the text segment appended to the end, the next token after the text sequence is determined through the retrieval question answering model; the text segment and the next token are determined as the newly added token;
[0173] S5: Append the newly added token to the end of the target answer to update the target answer;
[0174] S6: Determine whether the updated target answer contains the preset terminator.
[0175] S6a: If yes, then end and output the updated target answer;
[0176] S6b: If not, then update the position information of the current matching token based on the matching situation between the current matching token and the reference document;
[0177] S7: Update the current matching token based on the updated target answer and the updated position information, and return to execute S4.
[0178] In this embodiment, the extractable retrieval question-answering device is presented in the form of functional modules. Here, a module refers to an application-specific integrated circuit (ASIC), a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0179] Further functional descriptions of the above modules and units are the same as those in the corresponding embodiments described above, and will not be repeated here.
[0180] Example 4:
[0181] Please see Figure 4 , Figure 4 This is a schematic diagram of the structure of a computer device provided in an optional embodiment of this application, such as... Figure 4 As shown, the computer device includes one or more processors 10, memory 20, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components communicate with each other via different buses and can be mounted on a common motherboard or otherwise installed as needed. The processors can process instructions executed within the computer device, including instructions stored in or on memory to display graphical information of a GUI on external input / output devices (such as display devices coupled to the interfaces). In some alternative implementations, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple computer devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 4 Take a processor 10 as an example.
[0182] Processor 10 may be a central processing unit, a network processor, or a combination thereof. Processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The programmable logic device may be a complex programmable logic device (CAMP), a field-programmable gate array (FPGA), a general-purpose array logic (GDA), or any combination thereof.
[0183] The memory 20 stores instructions executable by at least one processor 10 to cause at least one processor 10 to perform the method shown in the above embodiments.
[0184] The memory 20 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the computer device as shown by a landing page for an app. Furthermore, the memory 20 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some alternative embodiments, the memory 20 may optionally include memory remotely located relative to the processor 10, which can be connected to the computer device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0185] The memory 20 may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as flash memory, hard disk or solid-state drive; the memory 20 may also include a combination of the above types of memory.
[0186] The computer device also includes an input device 30 and an output device 40. The processor 10, memory 20, input device 30, and output device 40 can be connected via a bus or other means. Figure 4 Taking the example of a connection between China and Israel via a bus.
[0187] Input device 30 can receive input numerical or character information, and generate key signal inputs related to user settings and function control of the computer device, such as a touchscreen, keypad, mouse, trackpad, touchpad, joystick, one or more mouse buttons, trackball, joystick, etc. Output device 40 may include display devices, auxiliary lighting devices (e.g., LEDs), and haptic feedback devices (e.g., vibration motors). The aforementioned display devices include, but are not limited to, liquid crystal displays, light-emitting diodes, displays, and plasma displays. In some alternative embodiments, the display device may be a touchscreen.
[0188] Example 5:
[0189] Based on the above embodiments, this application also provides a computer-readable storage medium storing a computer program executable by a processor. When the program runs on the processor, it causes the processor to perform the following steps:
[0190] S1: Obtain input data containing questions, instructions, and reference documents;
[0191] S2: Based on the input data, generate the first token in the target answer using a pre-trained retrieval question-answering model;
[0192] S3: Determine the first token as the currently matched token;
[0193] S4: Determine whether the currently matched token is at the end of the sentence.
[0194] S4a: If so, then based on the target answer, determine the new token using the retrieval question-answering model;
[0195] S4b: If not, then determine the token generation mechanism based on the matching situation between the current matching token and the reference document, and use the token generation mechanism to generate the new token;
[0196] The token generation mechanism includes:
[0197] Restricted decoding mechanism: When there are multiple text sequences in the reference document that match the current matching token, for each text sequence, determine the adjacent token after the end position index of the text sequence from the reference document; and determine the new token based on the target answer and each of the adjacent tokens through the retrieval question answering model.
[0198] Copying mechanism: When only one text sequence matching the current matching token exists in the reference document, the text segment between the end position index of the text sequence and the target sentence end position is obtained from the reference document; wherein, the target sentence end position is the position of the first symbol belonging to the preset sentence end matching set after the end position index; based on the target answer with the text segment appended to the end, the next token after the text sequence is determined through the retrieval question answering model; the text segment and the next token are determined as the newly added token;
[0199] S5: Append the newly added token to the end of the target answer to update the target answer;
[0200] S6: Determine whether the updated target answer contains the preset terminator.
[0201] S6a: If yes, then end and output the updated target answer;
[0202] S6b: If not, then update the location information of the current matching token based on the matching situation between the current matching token and the reference document; wherein the location information is initialized to empty;
[0203] S7: Update the current matching token based on the updated target answer and the updated position information, and return to execute S4.
[0204] Since the principle of the computer-readable storage medium in solving the problem is similar to that of the extractive retrieval question-answering method, the implementation of the computer-readable storage medium can be found in the embodiments of the method, and repeated details will not be repeated.
[0205] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.< / eos> < / eos>
Claims
1. An extractive retrieval question-answering method, characterized in that, The method includes: S1: Obtain input data containing questions, instructions, and reference documents; S2: Based on the input data, generate the first token in the target answer using a pre-trained retrieval question-answering model; S3: Determine the first token as the currently matched token; S4: Determine whether the currently matched token is at the end of the sentence. S4a: If so, then based on the target answer, determine the new token using the retrieval question-answering model; S4b: If not, then determine the token generation mechanism based on the matching situation between the current matching token and the reference document, and use the token generation mechanism to generate the new token; The token generation mechanism includes: Restricted decoding mechanism: When there are multiple text sequences in the reference document that match the current matching token, for each text sequence, determine the adjacent token after the end position index of the text sequence from the reference document; and determine the new token based on the target answer and each of the adjacent tokens through the retrieval question answering model. Copying mechanism: When only one text sequence matching the current matching token exists in the reference document, the text segment between the end position index of the text sequence and the target sentence end position is obtained from the reference document; wherein, the target sentence end position is the position of the first symbol belonging to the preset sentence end matching set after the end position index; based on the target answer with the text segment appended to the end, the next token after the text sequence is determined through the retrieval question answering model; the text segment and the next token are determined as the newly added token; S5: Append the newly added token to the end of the target answer to update the target answer; S6: Determine whether the updated target answer contains the preset terminator. S6a: If yes, then end and output the updated target answer; S6b: If not, then update the location information of the current matching token based on the matching situation between the current matching token and the reference document; wherein the location information is initialized to empty; S7: Update the current matching token based on the updated target answer and the updated position information, and return to execute S4.
2. The method as described in claim 1, characterized in that, The token generation mechanism also includes a free generation mechanism: if there is no text sequence in the reference document that matches the currently matched token, then the new token is determined based on the target answer through the retrieval question-answering model.
3. The method as described in claim 2, characterized in that, The S6b includes: If a text sequence matching the current matching token exists in the reference document, the end position index of the current matching token is updated by adding a new value to the end position index of the current matching token; wherein, the new value is the number of characters in the new token; If there is no text sequence in the reference document that matches the current matching token, then the position index of the character after the last character in the updated target answer is determined as the start position index of the current matching token, and the end position index of the current matching token is updated to empty.
4. The method as described in claim 1, characterized in that, In the restricted decoding mechanism, based on the target answer, each adjacent token is scored using the retrieval question-answering model, and the adjacent token with the highest score is selected as the new token.
5. The method as described in claim 1, characterized in that, Before S4b, the prefix tree of the reference document is obtained; in S4b, the matching position of the text sequence that matches the current matching token is searched in the prefix tree using the AC automaton algorithm.
6. The method as described in claim 1, characterized in that, S4: Determining whether the currently matched token is at the end of the sentence includes: Determine whether the last character of the currently matched token belongs to a preset sentence end symbol set; wherein, the preset sentence end symbol set contains pre-configured symbols representing the end of a sentence; If so, then the currently matched token is determined to be the end of the sentence; If not, then it is determined that the currently matched token is not at the end of the sentence.
7. A retrieval-based question-and-answer device, characterized in that, The device includes: The acquisition unit is used to acquire input data carrying questions, instructions, and reference documents; The processing unit is used to perform the following steps: S2: Based on the input data, generate the first token in the target answer using a pre-trained retrieval question-answering model; S3: Determine the first token as the currently matched token; S4: Determine whether the currently matched token is at the end of the sentence. S4a: If so, then based on the target answer, determine the new token using the retrieval question-answering model; S4b: If not, then determine the token generation mechanism based on the matching situation between the current matching token and the reference document, and use the token generation mechanism to generate the new token; The token generation mechanism includes: Restricted decoding mechanism: When there are multiple text sequences in the reference document that match the current matching token, for each text sequence, determine the adjacent token after the end position index of the text sequence from the reference document; and determine the new token based on the target answer and each of the adjacent tokens through the retrieval question answering model. Copying mechanism: When only one text sequence matching the current matching token exists in the reference document, the text segment between the end position index of the text sequence and the target sentence end position is obtained from the reference document; wherein, the target sentence end position is the position of the first symbol belonging to the preset sentence end matching set after the end position index; based on the target answer with the text segment appended to the end, the next token after the text sequence is determined through the retrieval question answering model; the text segment and the next token are determined as the newly added token; S5: Append the newly added token to the end of the target answer to update the target answer; S6: Determine whether the updated target answer contains the preset terminator. S6a: If yes, then end and output the updated target answer; S6b: If not, then update the position information of the current matching token based on the matching situation between the current matching token and the reference document; S7: Update the current matching token based on the updated target answer and the updated position information, and return to execute S4.
8. A computer device, characterized in that, The computer device includes a processor that executes a computer program stored in a memory to implement the steps of the extractive retrieval question-answering method as described in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, It stores a computer program executable by a computer device, which, when run on the computer device, causes the computer device to perform the steps of the extractive retrieval question-answering method as described in any one of claims 1-6.
Citation Information
Patent Citations
Retrieval type intelligent question and answer system and method for coal mine safety regulations
CN114020862A
Question-answer processing method and apparatus
WO2024220031A1