Question and answer method and device based on end-to-end language model and readable storage medium
By using an end-to-end language model-based question-answering method, a complete question-answering path is generated through iterative reasoning, which solves the problem of interrupted answer reasoning chains in existing technologies and improves the compliance and auditability of question-answering.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-30
- Publication Date
- 2026-03-27
AI Technical Summary
In existing question-answering methods, the separate design of the retrieval and reading mechanisms leads to interruptions in the answer reasoning chain or logical jumps, making it difficult to quickly verify the source of the answer and reducing work efficiency and the auditability of results in compliance review scenarios.
The question-answering method based on an end-to-end language model is adopted. The pre-trained question-answering model is used to perform T iterations of inference. The first encoder and the second encoder are used to generate feature matrices and perform fusion processing. Combined with the decoder, the inference results are generated and T inference results are output to show the complete question-answering path.
It enhances the compliance, reliability, and inference chain integrity of the question-answering model, and improves work efficiency and result auditability in compliance review scenarios.
Smart Images

Figure CN121745313A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a question-answering method, apparatus, and readable storage medium based on an end-to-end language model. Background Technology
[0002] In the question-answering field, existing technologies typically employ a two-stage architecture of classic retrieval and reading, completing the question-answering task in two independent stages. The first stage is the retrieval enhancement stage, which mainly extracts relevant paragraph blocks from the corpus through information retrieval technology and forms a candidate document set after reranking. The second stage is the answer generation stage, which mainly uses reading comprehension models to generate the final answer based on the retrieved paragraph blocks.
[0003] The cascaded architecture in existing technologies separates the retrieval and reading processes, which means that the paragraphs returned by the retrieval process may not contain the complete chain of evidence necessary for the reader to generate the answer. This can easily cause the answer reasoning chain to break or the logic to jump, making it difficult for reviewers to quickly verify the source of the answer and reducing the efficiency and auditability of the results in compliance review scenarios. Summary of the Invention
[0004] This invention provides a question-answering method, apparatus, and readable storage medium based on an end-to-end language model to address the problem of poor verifiability of results in existing question-answering methods.
[0005] To solve the above-mentioned technical problems, this application is implemented as follows:
[0006] In a first aspect, embodiments of this application provide a question-answering method based on an end-to-end language model, including:
[0007] The user's question is input into a pre-trained question-answering model and iterates T times to obtain T inference results. The question-answering model includes a first encoder, a second encoder, and a decoder, where T is a positive integer.
[0008] Sort the T inference results in order to obtain the question and answer results;
[0009] The T iterations of reasoning include:
[0010] The user question is encoded using the first encoder to obtain a first feature matrix;
[0011] During the t-th iteration of inference, the second feature matrix is generated by the second encoder;
[0012] The first feature matrix and the second feature matrix are fused to obtain a fused feature matrix.
[0013] The fused feature matrix is input into the decoder for decoding to obtain the t-th inference result;
[0014] Specifically, when t equals 1, the input of the second encoder is a preset initial value; when t is greater than 1 and less than T, the input of the second encoder is the set of reasoning results obtained from the previous t-1 reasoning iterations.
[0015] Optionally, before inputting the user's question into the pre-trained question-answering model for T iterations of inference to obtain T inference results, the method further includes:
[0016] The question-answering model is iteratively trained based on multiple training data, each of which includes a query sample and a corresponding answer sample.
[0017] Determine the loss value for the Nth training iteration, the loss value including similarity loss. If the first cosine similarity between the question-answering result and the answer sample is greater than a threshold, the similarity loss is determined based on the first cosine similarity. If the first cosine similarity is less than or equal to the threshold, the similarity loss is determined based on the difference between 1 and the first cosine similarity, where N is a positive integer.
[0018] The parameters of the question-answering model are adjusted based on the loss value;
[0019] If the loss value satisfies the loss convergence condition, the question-answering model trained for the Nth time is determined as the pre-trained question-answering model.
[0020] Optionally, the step of inputting the fused feature matrix into the decoder for decoding processing to obtain the t-th inference result includes:
[0021] The fused feature matrix is input into the decoder for decoding to obtain multiple candidate inference results and a first generation probability corresponding to each candidate inference result;
[0022] Determine whether the candidate inference result exists in the pre-stored text data;
[0023] The first generation probability is updated based on a preset rule to obtain a second generation probability. The preset rule includes reducing the first generation probability corresponding to the candidate inference result when the candidate inference result does not exist in the text data, and maintaining the first generation probability corresponding to the candidate inference result unchanged when the candidate inference result exists in the text data.
[0024] The candidate inference result with the highest generation probability is determined as the t-th inference result.
[0025] Optionally, before inputting the user's question into the pre-trained question-answering model for T iterations of inference to obtain T inference results, the method further includes:
[0026] The text data is processed into structured data to obtain structured data;
[0027] Based on the text data, index data corresponding to the text data is constructed. The index data includes a string, a suffix array, a count array, and an occurrence array. The string is a string obtained by performing a Burrough Wheeler transform on the text data. The suffix array is used to record the starting position of each suffix in the text data in the arrangement after sorting according to a preset sorting rule. The count array is used to record the cumulative number of occurrences of all characters smaller than the character in the preset sorting rule in the text data. The occurrence array is used to record the cumulative number of occurrences of each character up to a preset position in the string.
[0028] Store the structured data and the index data;
[0029] The step of determining whether the candidate inference result exists in the pre-stored text data includes:
[0030] Based on the structured data and the index data, it is determined whether the candidate inference result exists in the text data.
[0031] Optionally, before storing the structured data and the index data, the method further includes at least one of the following:
[0032] Construct and store a clause metadata table, which is used to record the metadata of each clause in the text data, as well as the mapping relationship between the clause and the string position;
[0033] Construct and store a keyword index table, which records preset keywords in the text data and the mapping relationship between the preset keywords and the terms;
[0034] Construct and store a character set mapping table, which is used to map characters in the text data to consecutive integer index values;
[0035] Construct and store a clause association diagram, which is used to record the relationships between the clauses.
[0036] Optionally, the similarity loss for the Nth training iteration is determined, including:
[0037] Calculate the sub-similarity loss for each iteration of the inference;
[0038] The similarity loss for the Nth training iteration is determined by the sum of the sub-similarity losses from the T iterations of the iterative reasoning.
[0039] The answer samples include T sequentially arranged sample reasoning results. The sub-similarity loss for the t-th iteration of reasoning is calculated, including:
[0040] Calculate the second cosine similarity between the t-th inference result and the t-th sample inference result;
[0041] If the second cosine similarity is greater than the threshold, the cosine similarity is determined as the sub-similarity loss; if the second cosine similarity is less than or equal to the threshold, the difference between 1 and the cosine similarity is determined as the sub-similarity loss.
[0042] Optionally, the step of fusing the first feature matrix and the second feature matrix to obtain a fused feature matrix includes:
[0043] Calculate the inner product of the first feature matrix and the second feature matrix to obtain the inner product calculation result;
[0044] The first feature matrix and the second feature matrix are cross-fused based on the cross-attention mechanism to obtain the cross-attention result;
[0045] The inner product calculation result, the cross attention result, the first feature matrix, and the second feature matrix are concatenated to obtain the fused feature matrix.
[0046] Secondly, embodiments of the present invention provide a question-answering device based on an end-to-end language model, comprising:
[0047] The iterative reasoning module is used to input user questions into a pre-trained question-answering model and perform T iterative reasoning to obtain T reasoning results. The question-answering model includes a first encoder, a second encoder, and a decoder, where T is a positive integer.
[0048] The sorting module is used to sort the T inference results sequentially to obtain the question-and-answer results.
[0049] The T iterations of reasoning include:
[0050] The user question is encoded using the first encoder to obtain a first feature matrix;
[0051] During the t-th iteration of inference, the second feature matrix is generated by the second encoder;
[0052] The first feature matrix and the second feature matrix are fused to obtain a fused feature matrix.
[0053] The fused feature matrix is input into the decoder for decoding to obtain the t-th inference result;
[0054] Specifically, when t equals 1, the input of the second encoder is a preset initial value; when t is greater than 1 and less than T, the input of the second encoder is the set of reasoning results obtained from the previous t-1 reasoning iterations.
[0055] Thirdly, embodiments of the present invention provide an electronic device, including: a memory, a processor, and a program stored in the memory and executable on the processor;
[0056] The processor is configured to read a program from memory to implement the steps in the question-answering method based on an end-to-end language model as described in the first aspect.
[0057] Fourthly, embodiments of the present invention provide a readable storage medium for storing a program, which, when executed by a processor, implements the steps of the question-answering method based on an end-to-end language model as described in the first aspect.
[0058] In this embodiment, the user's question is first input into a pre-trained question-answering model for T iterations of reasoning, yielding T reasoning results. These T reasoning results are then sorted sequentially to obtain the question-answering result. On one hand, because the question-answering model provided in this application has an end-to-end structure, it completely connects the retrieval and generation links, avoiding module fragmentation and improving the accuracy, reliability, and completeness of the reasoning chain for compliant question answering. On the other hand, through T iterations of reasoning, the question-answering model outputs T reasoning results, which include the model's complete reasoning path, thereby achieving interpretability and verifiability of the reasoning process. Attached Figure Description
[0059] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0060] Figure 1 A flowchart illustrating the question-answering method based on an end-to-end language model provided in this application embodiment. Figure 1 ;
[0061] Figure 2 A flowchart illustrating the question-answering method based on an end-to-end language model provided in this application embodiment. Figure 2 ;
[0062] Figure 3 A schematic diagram of the structure of a question-answering device based on an end-to-end language model provided in an embodiment of this application;
[0063] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0064] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0065] Unless otherwise defined, the technical or scientific terms used in this application shall have the ordinary meaning understood by one of ordinary skill in the art to which this application pertains. The terms "first," "second," and similar terms used in this application do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Similarly, the terms "a" or "one," and similar terms do not indicate a quantity limitation, but rather indicate the presence of at least one. The terms "connected" or "linked," and similar terms, are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right," etc., are used only to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship also changes accordingly.
[0066] The following description, in conjunction with the accompanying drawings, further illustrates the question-answering method, apparatus, and readable storage medium based on an end-to-end language model proposed in the application embodiments.
[0067] Please see Figure 1 , Figure 1 A flowchart illustrating a question-answering method based on an end-to-end language model, provided for an embodiment of this application, is shown in the figure. The method includes:
[0068] Step 101: Input the user's question into the pre-trained question-answering model and perform T iterations of reasoning to obtain T reasoning results. The question-answering model includes a first encoder, a second encoder, and a decoder, where T is a positive integer.
[0069] The T iterations of reasoning include:
[0070] The user question is encoded using the first encoder to obtain a first feature matrix;
[0071] During the t-th iteration of inference, the second feature matrix is generated by the second encoder;
[0072] The first feature matrix and the second feature matrix are fused to obtain a fused feature matrix.
[0073] The fused feature matrix is input into the decoder for decoding to obtain the t-th inference result;
[0074] Specifically, when t equals 1, the input of the second encoder is a preset initial value; when t is greater than 1 and less than T, the input of the second encoder is the set of reasoning results obtained from the previous t-1 reasoning iterations.
[0075] In this embodiment, an end-to-end architecture with dual encoders and a single decoder is used as the question-answering model. Specifically, the question-answering model includes a first encoder, a second encoder, and a decoder, the specific structure of which is not limited here. The first encoder is used to encode the input user question, the second encoder is used to encode the progressively generated inference results, and the decoder is used to generate the inference result based on the fusion of the outputs of the first and second encoders.
[0076] In the first iteration of inference, the input of the second encoder is a preset initial value. The second feature matrix is obtained through the preset initial value. The decoder is used to decode the fused feature matrix after fusing the first feature matrix and the second feature matrix to obtain the first inference result, which can also be called the first inference step.
[0077] In the second iteration of inference, the input of the second encoder is the set of inference results obtained in the previous inference (i.e., the first inference result). The decoder is used to decode the fused feature matrix after fusing the first feature matrix and the second feature matrix to obtain the second inference result, which can also be called the second inference step.
[0078] In the third iteration of inference, the input of the second encoder is the set of inference results obtained from the first two inferences (i.e., the first inference result and the second inference result). The decoder is used to decode the fused feature matrix after fusing the first feature matrix and the second feature matrix to obtain the third inference result, which can also be called the third inference step.
[0079] By performing T iterations of reasoning in the above manner, T reasoning results can be obtained sequentially. Each reasoning result obtained in each iteration serves as a step in the entire reasoning process. The complete question-and-answer reasoning process can be demonstrated through the T reasoning results, and the final question-and-answer result can be obtained.
[0080] In practical implementation, the user question is usually a natural language question. The user question is represented as a sequence of words or characters Q = [q1, q2, ..., ql], and the Transformer encoder is used as the first encoder to process Q and generate a context-dependent representation, thus obtaining the first feature matrix.
[0081] Specifically, the user question is input into the first encoder (Encoder1) for encoding, and its semantic representation is extracted. The output of the first encoder is a feature matrix containing the semantic information of each input unit. For example, the first feature matrix... as follows:
[0082] ;
[0083] in, Let Q be the length of the character sequence. To hide dimensions, Parameters used to characterize the first encoder.
[0084] For example, for the user question "What is the minimum registered capital requirement for non-bank payment institutions?", the resulting character sequence Q is ["non", "bank", "payment", "institution", "registered", "capital", "minimum", "limit", "is", "how much"]. =10, further assumption Then the output of the first encoder Each word's 512-dimensional vector captures its semantics and context in the user's question (such as the association between "registered capital" and "minimum limit").
[0085] The second encoder (Encoder2) is used to generate and encode the critical path (i.e., a series of intermediate inference results) in the question-answering process, obtaining the inference result predicted at the current step. The input to the second encoder is different in different iterative inference processes, resulting in different second feature matrices.
[0086] First, before the first iteration of inference, a preset initial value needs to be obtained as the input to the second encoder during the first iteration of inference. As one optional implementation, a vector is randomly generated as the preset initial value. As another optional implementation, a vector is generated according to a preset rule as the preset initial value.
[0087] In the first iteration of inference, the input to the second encoder is a preset initial value. Starting from the second iteration, the input to the second encoder is the set of inference results obtained from the previous t-1 iterations. In the t-th iteration, the second encoder generates a second feature matrix; the first feature matrix and the second feature matrix are fused to obtain a fused feature matrix; the fused feature matrix is input to the decoder for decoding to obtain the t-th inference result.
[0088] The following is an example using a specific implementation. First, a vector is randomly generated. and this vector As a preset initial value ;
[0089] During the first iteration of inference (predicting step_0), The first and second feature matrices are used as input to the second encoder to obtain the second feature matrix. The first and second feature matrices are then input to the decoder for decoding to obtain the first inference result. Assuming The specific content is: Then we obtain the set of reasoning results obtained from the previous reasoning. =["Non-bank payment institutions"].
[0090] In the second iteration of inference (prediction step_1), the set of inference results obtained from the previous inference is... Input the second encoder to generate the second feature matrix:
[0091] ;
[0092] The first and second feature matrices are fused to obtain a fused feature matrix; this fused feature matrix is then input into the decoder for decoding to obtain the second inference result. Assuming The specific content is: Then we obtain the set of reasoning results obtained from the first two inferences. =["Non-bank payment institutions","Minimum registered capital"], .
[0093] Following the above method, the set of reasoning results obtained during the reasoning process is dynamically updated. If T inferences are performed, T inference results can be obtained. The set of inference results obtained from T inferences is... This is the final question-and-answer result, which contains the reasoning results obtained from each question-and-answer step, forming a complete reasoning path.
[0094] By employing the above method, a step-by-step reasoning process is simulated through T iterative reasoning iterations, resulting in T reasoning outcomes that visually represent the source of the answer. This enhances the model's ability to model the context of the reasoning path and better adapts to the progressively decomposed requirements of regulatory queries. This approach not only presents the complete reasoning process to users but also allows reviewers to quickly verify the source of the answer, improving work efficiency and the auditability of results in compliance review scenarios.
[0095] In some embodiments, the first feature matrix and the second feature matrix are concatenated to obtain a fused feature matrix. In other embodiments, the first feature matrix and the second feature matrix are fused based on an attention mechanism to obtain a fused feature matrix.
[0096] Optionally, in some embodiments, the step of fusing the first feature matrix and the second feature matrix to obtain a fused feature matrix includes:
[0097] Calculate the inner product of the first feature matrix and the second feature matrix to obtain the inner product calculation result;
[0098] The first feature matrix and the second feature matrix are cross-fused based on the cross-attention mechanism to obtain the cross-attention result;
[0099] The inner product calculation result, the cross attention result, the first feature matrix, and the second feature matrix are concatenated to obtain the fused feature matrix.
[0100] First, calculate the first characteristic matrix. Second characteristic matrix The inner product is obtained by calculating the inner product. :
[0101] ;
[0102] It should be understood that the inner product calculation result can be used to represent the similarity matrix between the first feature matrix and the second feature matrix, that is, the similarity between the user question and the reasoning result.
[0103] Then, based on the cross-attention mechanism, the first feature matrix and the second feature matrix are cross-fused to obtain the cross-attention result. :
[0104] ;
[0105] In this embodiment, As a query, As keys and values, multi-head attention is calculated as follows:
[0106] ;
[0107] ;
[0108] It should be understood that in the above formula, For the query vector, in this embodiment, it corresponds to the first feature matrix output by the first encoder. , and These are the key vector and the value vector, respectively, which in this embodiment correspond to the second feature matrix output by the second encoder. , , and These are the learnable projection matrices corresponding to the i-th attention head, used to map the original query, key, and value to a low-dimensional subspace to achieve multi-view feature interaction; The output projection matrix is used to linearly transform the concatenated multi-head attention results back to the model dimension d for compatibility with subsequent network layers. h represents the number of attention heads. Used to indicate splicing operations.
[0109] The result of the inner product calculation Cross-attention results and the original first feature matrix Second characteristic matrix The features are concatenated to obtain the fused feature matrix. As an optional implementation, the inner product calculation result, the cross-attention result, the first feature matrix, and the second feature matrix are concatenated to obtain a fused feature matrix, including:
[0110] The first feature matrix, the second feature matrix, and the cross-attention result are subjected to average pooling to obtain the average pooled first feature matrix, the average pooled second feature matrix, and the average pooled cross-attention result.
[0111] Flatten the inner product calculation result to obtain the flattened inner product calculation result;
[0112] The first feature matrix after average pooling, the second feature matrix after average pooling, the cross-attention result after average pooling, and the inner product calculation result after flattening are concatenated to obtain the fused feature matrix.
[0113] In some embodiments, to achieve better stitching results, the first feature matrix, the second feature matrix, and the cross-attention result are subjected to average pooling to obtain the average-pooled first feature matrix. The second feature matrix after average pooling and the results of cross-attention after average pooling :
[0114] ;
[0115] ;
[0116] ;
[0117] in, Used to characterize average pooling processing.
[0118] In some embodiments, the inner product calculation result is flattened to obtain a flattened inner product calculation result. :
[0119] ;
[0120] in, This is a flattening function used to convert a multidimensional array into a one-dimensional array, facilitating subsequent feature concatenation.
[0121] Finally, The features are concatenated to obtain the fused feature matrix:
[0122] ;
[0123] in, For example, taking the first iteration of the reasoning process as an example, , Further calculations yielded the inner product results. and cross-attention results During the concatenation process, the feature matrix is subjected to average pooling, and the inner product calculation result is flattened to obtain... , The final fused feature matrix is as follows: .
[0124] The decoder is used to distribute the responses based on the fused feature matrix, resulting in multiple inference results. Its specific structure is not limited here. For example, in some embodiments, a Transformer decoder is used to generate inference results based on an autoregressive approach.
[0125] In some embodiments, the decoder includes a self-attention mechanism and a cross-attention mechanism (focusing on...). Specifically, the self-attention mechanism is used to model the dependencies between positions within the currently generated partial output sequence. By calculating the similarity between query, key, and value vectors, self-attention dynamically assigns attention weights to historical output positions for each output position, thereby capturing long-range dependencies and semantic consistency within the output sequence. Building on this, the cross-attention mechanism is specifically used to interact with the decoder's current state and the fusion feature matrix generated during the encoding stage. In the cross-attention module, the query vector is generated from the decoder's current hidden state, while the key and value vectors are directly derived from the fusion feature matrix. Through this mechanism, the decoder can selectively focus on the local or global semantic information in the fusion feature matrix that is most relevant to the current inference task at each generation step, thereby improving the accuracy and contextual relevance of the generated results.
[0126] In some embodiments, the feature matrix will be fused. Input decoder ( The algorithm performs decoding to obtain multiple candidate inference results and the first generation probability corresponding to each candidate inference result. The candidate inference result with the highest first generation probability is output as the final inference result of this iteration.
[0127] Optionally, in some embodiments, before step 101, the method further includes:
[0128] The question-answering model is iteratively trained based on multiple training data, each of which includes a query sample and a corresponding answer sample.
[0129] Determine the loss value for the Nth training iteration, the loss value including similarity loss. If the first cosine similarity between the question-answering result and the answer sample is greater than a threshold, the similarity loss is determined based on the first cosine similarity. If the first cosine similarity is less than or equal to the threshold, the similarity loss is determined based on the difference between 1 and the first cosine similarity, where N is a positive integer.
[0130] The parameters of the question-answering model are adjusted based on the loss value;
[0131] If the loss value satisfies the loss convergence condition, the question-answering model trained for the Nth time is determined as the pre-trained question-answering model.
[0132] The above method can be used to iteratively train the question-answering model. In this embodiment, similarity loss is introduced to determine the training loss value, thereby quantifying the quality of the obtained reasoning results, guiding the model to generate reasoning results that are closer to the target, and improving semantic accuracy.
[0133] Specifically, in some embodiments, a first cosine similarity is calculated between the predicted question-and-answer result and the actual answer sample, and positive and negative scores are introduced. If the first cosine similarity between the question-and-answer result and the answer sample is greater than a threshold, the similarity loss is determined based on the positive score, which is equal to the first cosine similarity. If the first cosine similarity is less than or equal to the threshold, the similarity loss is determined based on the negative score, which is 1 minus the first cosine similarity.
[0134] In this embodiment, the loss value is determined through similarity loss. When the first cosine similarity between the question-answering result and the answer sample is greater than a threshold, the similarity loss is determined based on the first cosine similarity. When the first cosine similarity is less than or equal to the threshold, the similarity loss is determined based on the difference between 1 and the first cosine similarity. Similarity loss can improve the semantic accuracy of the output reasoning results.
[0135] In some embodiments, the loss value further includes negative log-likelihood loss. The final loss value is determined based on the negative log-likelihood loss and similarity loss. The model parameters are updated by backpropagation, and the parameters of the first encoder, the second encoder, and the decoder are adjusted by gradient descent until the loss convergence condition is met, thus obtaining the pre-trained question-answering model.
[0136] Optionally, in some embodiments, determining the similarity loss for the Nth training iteration includes:
[0137] Calculate the sub-similarity loss for each iteration of the inference;
[0138] The similarity loss for the Nth training iteration is determined by the sum of the sub-similarity losses from the T iterations of the iterative reasoning.
[0139] The answer samples include T sequentially arranged reasoning results. The sub-similarity loss for the t-th iteration of reasoning is calculated, including:
[0140] Calculate the second cosine similarity between the t-th inference result and the t-th sample inference result;
[0141] If the second cosine similarity is greater than the threshold, the cosine similarity is determined as the sub-similarity loss; if the second cosine similarity is less than or equal to the threshold, the difference between 1 and the cosine similarity is determined as the sub-similarity loss.
[0142] In this embodiment, the loss value of each iteration of inference is calculated sequentially. By refining the method of determining the loss value, the accuracy of the loss value is improved, and the accuracy of each inference step in the model inference process is further improved, resulting in a question-answering model with better training effect.
[0143] To facilitate understanding, the following explanation uses the t-th iteration of reasoning as an example to illustrate the calculation of the t-th reasoning result. and the reasoning result of the t-th sample The second cosine similarity is used. If the second cosine similarity is higher than the threshold, it is recorded as a positive score. Otherwise, it will be recorded as a reverse score. .
[0144] Second cosine similarity for:
[0145] ;
[0146] in, This refers to word embedding (such as BERT embedding), but the specifics are not limited here.
[0147] The positive and negative scores are calculated based on the second cosine similarity as follows:
[0148]
[0149]
[0150] in, The threshold is (e.g., 0.7).
[0151] For example, the t-th reasoning result is For "non-bank payment institutions", the inference result of the t-th sample. As a "non-bank payment institution", the calculation yielded... .
[0152] For example, the t-th reasoning result For "banking institutions", the inference result of the t-th sample. For "non-bank payment institutions", Sim is calculated. .
[0153] Optionally, in some embodiments, before inputting the user's question into a pre-trained question-answering model for T iterations of inference to obtain T inference results, the method further includes:
[0154] The text data is processed into structured data to obtain structured data;
[0155] Based on the text data, index data corresponding to the text data is constructed. The index data includes a string, a suffix array, a count array, and an occurrence array. The string is a string obtained by performing a Burrough Wheeler transform on the text data. The suffix array is used to record the starting position of each suffix in the text data in the arrangement after sorting according to a preset sorting rule. The count array is used to record the cumulative number of occurrences of all characters smaller than the character in the preset sorting rule in the text data. The occurrence array is used to record the cumulative number of occurrences of each character up to a preset position in the string.
[0156] Store the structured data and the index data;
[0157] The step of determining whether the candidate inference result exists in the pre-stored text data includes:
[0158] Based on the structured data and the index data, it is determined whether the candidate inference result exists in the text data.
[0159] Text data can be understood as a pre-stored resource library. When a question-answering model performs a question-answering exercise, it typically generates the corresponding answer based on the content of the text data. For example, when this method is applied to the field of payment compliance review question-answering, the text data consists of relevant legal and regulatory texts. The specific content of the pre-stored text data will vary depending on the application of this method to different fields, and will not be limited here.
[0160] In this embodiment, the text data is pre-processed into structured data. Specifically, the collected text data is parsed into JSON format according to pre-designed parsing rules. JSON (JavaScript Object Notation) is a lightweight data-interchange format that is text-based, easy for humans to read and write, and also easy for machines to parse and generate. It should be understood that the parsing rules can usually be predetermined based on the structure of the text data. For example, the text data can be structured according to its chapter or heading structure.
[0161] By constructing corresponding index data based on text data and storing structured data and index data, the efficiency of retrieving text data can be improved. In this embodiment, the constructed index data is an FM-index (Full-textMinute Index) structure. FM-index is an index structure used for efficient searching and compression of full-text data. It is based on the Burrows-Wheeler Transform (BWT) and auxiliary data structures, and can support fast substring search, counting, and positioning operations while compressing storage.
[0162] It should be understood that, in practice, a special character that has the smallest preset sorting rule and does not appear in the original text is usually appended to the end of the original text data T as a terminator (exemplarily denoted as $), thus obtaining a new string, which is then processed as text data. This terminator ensures that all suffixes (or cyclic shifts) are different, thereby guaranteeing the uniqueness of the sorting. For specific implementation details, please refer to the descriptions in related technologies; specific details are not limited here.
[0163] Specifically, the index data includes strings, suffix arrays, count arrays, and occurrence arrays, as detailed below:
[0164] Applying a BWT transformation to the entire text data generates a rearranged string, also known as a BWT string. The specific implementation process of BWT is as follows: First, obtain all the cyclic shifts corresponding to the text data. Then, sort all the cyclic shifts in a preset order (e.g., lexicographical order). Next, take the last character of each cyclic shift to form a string. for:
[0165] ;
[0166] in, It is text data The The last character after a cyclic shift and sorting according to a preset sorting rule.
[0167] For example, given the text data T="First Article", adding the terminator "$" results in the new string T' = "First Article $", generating all four cyclic shifts (each starting from position i and with a length of 4): "First Article $", "One Article $", "Article $ First", "$First Article". Assuming the preset sorting rule is $<1<Article < Article", then after sorting according to the preset sorting rule, it becomes ["$First Article", "One Article $", "First Article $", "Article $ First"], resulting in L = "Article $ First".
[0168] It should be understood that the BWT string is the core of FM-index, supporting fast pattern matching in conjunction with other structures, and is roughly the same length as the original text (approximately n bytes, where n is the number of characters). In some embodiments, the string length can be further compressed through run-length encoding (RLE), but specific methods are not limited here.
[0169] Suffix arrays (SA) are used to record text data. The starting positions of all suffixes are sorted in a predetermined order (e.g., lexicographical order). Given a string S = S[0]S[1]…S[n−1] of length n, any substring S[i..n−1] starting from position i (where 0 ≤ i < n) to the end of the string is called a suffix of S. Denotes the starting position (from 0 to n - 1) of the i-th suffix according to the preset sorting rule.
[0170] ;
[0171] Among them, is the -th suffix with the smallest preset sorting rule in the text data. For example, for the text data "The first article", after adding the terminator, we get "The first article$", then its corresponding all suffixes are "The first article$", "first article$", "article$", and "$". Assuming SA = [3, 1, 0, 2], it means SA[0] = 3, the suffix with the smallest preset sorting rule is "$", starting from position 3; SA[1] = 1, the second smallest suffix is "first article$", starting from position 1, and so on. It should be understood that the above is only for illustration, and due to the different specific sorting of the preset sorting rule, the suffix data may also be different.
[0172] The count array (Count Array, C) is used to record, for each character (or character set) in the text data, the cumulative number of occurrences of all characters that are less than this character in the preset sorting rule, so as to locate the range of this character in the BWT. The type of the count array is an integer array. For the character ( is a character set, such as Chinese characters in UTF - 8), its corresponding count array is as follows: as follows:
[0173] ;
[0174] Among them, represents the total number (cumulative frequency) of occurrences of characters that are less than c in the text data according to the preset sorting rule for the character c ( ), is in the number of occurrences.
[0175] For example, for the character set {"一", "第", "条", …}, , , m is the number of occurrences of the character "一"), , is the number of occurrences of the character "第". Through the counting array, during pattern matching, the starting and ending positions of the character in the BWT can be quickly determined.
[0176] The Occurrence Array (Occ) is used to record the number of occurrences of each character in the BWT string up to a certain position. The type of the occurrence array is a two-dimensional array or a sampling table.
[0177] Exemplarily, for the character and the position :
[0178] ;
[0179] where represents the number of occurrences of the character c in the string [0..i].
[0180] For example, if the string is "条一第…", Occ[条, 0]=1, Occ[条, 1]=1, Occ[一, 1]=1. The occurrence array can support backward search, thus quickly locating the position of the pattern in the text. Among them, 1 is the indicator function.
[0181] In some embodiments, to save space, only the complete Occ values are stored at every k positions:
[0182] ;
[0183] This means that only the at positions {i = 0, k, 2k, 3k…} are saved, while the
[0184] at other positions are not directly stored but are dynamically calculated during query.
[0184] In some embodiments, the text data is data in a specific format, including content such as chapters, clause numbers, titles, and contents. In this embodiment, based on the index data, at least one extended data structure is further added to improve the retrieval efficiency. The extended data structures include: clause metadata table, keyword index table, character set mapping table, and clause association graph.
[0185] Optionally, in some embodiments, before storing the structured data and the index data, the method further includes at least one of the following:
[0186] Construct and store a clause metadata table, which is used to record the metadata of each clause in the text data and the mapping relationship between the clause and the string position;
[0187] Construct and store a keyword index table, which records preset keywords in the text data and the mapping relationship between the preset keywords and the terms;
[0188] Construct and store a character set mapping table, which is used to map characters in the text data to consecutive integer index values;
[0189] Construct and store a clause association diagram, which is used to record the relationships between the clauses.
[0190] In some embodiments, before storing the structured data and the index data, the method further includes constructing and storing a clause metadata table. In this embodiment, the clause metadata table is used to record metadata about each clause in the text data, facilitating the mapping of character positions in the index data to specific clauses in the text data.
[0191] For example, the type of the terms metadata table is a structure array, such as: {id:4,start:500,end:800,title:“Establishment”,chapter:“Second Chapter”}, which is used to convert the query results (character positions) of the index data into terms numbers and context.
[0192] In some embodiments, before storing the structured data and the index data, the method further includes constructing and storing a keyword index table. In this embodiment, high-frequency keywords are pre-extracted from the text data as preset keywords, and the preset keywords are mapped to their corresponding terms to obtain the keyword index table.
[0193] For example, the keyword index table is of type hash table, such as {keyword:[id1,id2,…]}, which is used to speed up common queries, act as a cache, and reduce the number of backward searches.
[0194] ;
[0195] In some embodiments, before storing the structured data and the index data, the method further includes constructing and storing a character set mapping table. The character set mapping table is used to establish mappings for Chinese characters (e.g., UTF-8 encoding), reducing the character set size in the index data. By mapping real Chinese characters to consecutive integer index values, it reduces the storage space and computational overhead of data structures (such as counting arrays and occurrence arrays).
[0196] For example, the character set mapping table is of type hash table or array, represented as {char:index}, mapping each Chinese character to an index from 0 to σ. This reduces the space requirements of the counting array and the occurrence array, thus optimizing Chinese text processing.
[0197] ;
[0198] Among them, , is the character set corresponding to the text data.
[0199] For example, assume that only the following 5 different characters are used in the text data: "one", "article", "clause", "note", "amount". Then: the character set Σ = {"one", "article", "clause", "note", "amount"}, and σ = |Σ| = 5. In this embodiment, the character set mapping table may be: Char_Map = {"one": 0, "article": 1, "clause": 2, "note": 3, "amount": 4}. Through the above character set mapping table, the index data no longer needs to allocate space for the entire Unicode Chinese character set, but only creates a count array and an occurrence array for these 5 characters, saving resources and improving speed.
[0200] The number of Chinese characters in the Chinese character set is huge, and tens of thousands of Chinese characters can be covered under UTF-8 encoding. Directly constructing a count array and an occurrence array on these characters will cause waste of space. In this embodiment, by compressing the actually used character set into continuous indexes from 0 to σ - 1 through the character set mapping table, a smaller array (with a size of σ instead of the entire Unicode encoding space) can be constructed.
[0201] In some embodiments, before storing the structured data and the index data, the method further includes constructing and storing a clause association graph. The clause association graph is used to record the reference or logical relationship between each clause, so as to enable cross-clause analysis.
[0202] Exemplarily, the type of the clause association graph is a directed graph. The nodes in the clause association graph are clause identifiers, which are used to uniquely identify each clause, and the edges represent reference or association (such as Article 7 referring to Article 50, example: {7 -> 50, 7 -> 51} (Article 7 mentions Article 50 and Article 51 of the Regulations). The role of the clause association graph is to support complex queries, such as finding all clauses related to "major illegal and irregular records".
[0203] The clause association graph can be represented as follows:
[0204] .
[0205] The following takes a specific embodiment as an example for illustration. Assume the input text data is as follows: "Article 1... Article 8..., according to Article 8 of the Regulations, the minimum registered capital of non-bank payment institutions...", .
[0206] The following is an example of the metadata section of the terms: "Minimum registered capital for non-bank payment institutions..."
[0207] The keyword index section is shown in the following example: .
[0208] The character set mapping section is shown in the following example: .
[0209] The following is an example of a clause relationship diagram: (Article 8 cites Article 55).
[0210] To facilitate understanding, the following example uses the query for "minimum registered capital" to illustrate the retrieval process based on the aforementioned index data and extended data structure.
[0211] First, a keyword search is performed in the keyword index table based on the keyword "minimum registered capital". If a relevant result is found in the keyword index table, the corresponding clause (e.g., Article 8) is directly returned. If no matching result is found in the keyword index table, a search is performed backwards based on the index data.
[0212] Specifically, a backward search is performed using a counting array and an occurrence array to locate the range of "minimum registered capital" within the string. Then, by sampling the suffix array, it is converted into character positions in the text. Finally, the character positions are mapped to specific clause content using the clause metadata table to extract the full text of the clause. Simultaneously, the query results are stored to accelerate subsequent queries. If expansion is needed, other clauses referenced in Article 8 (such as Article 55) are located based on the clause association diagram.
[0213] In this embodiment, by extending the data structure settings, the efficiency and accuracy of data retrieval can be greatly improved for text data with clear formats and clause codes, such as laws and regulations, enabling rapid retrieval and location in large-scale data.
[0214] By combining auxiliary structures such as clause metadata tables, keyword index tables, and clause reference diagrams during the construction of FM-index, efficient paragraph positioning and legal logic jumps based on keywords can be achieved, providing multi-level background support for model reasoning. At the same time, it supports cross-document and cross-clause correlation analysis, making it more suitable for the complex context of payment regulations.
[0215] Optionally, in some embodiments, during iterative training, the step of inputting the fused feature matrix into the decoder for decoding to obtain the t-th inference result includes:
[0216] The fused feature matrix is input into the decoder for decoding to obtain multiple candidate inference results and a first generation probability corresponding to each candidate inference result;
[0217] Determine whether the candidate inference result exists in the pre-stored text data;
[0218] The first generation probability is updated based on a preset rule to obtain a second generation probability. The preset rule includes reducing the first generation probability corresponding to the candidate inference result when the candidate inference result does not exist in the text data, and maintaining the first generation probability corresponding to the candidate inference result unchanged when the candidate inference result exists in the text data.
[0219] The candidate inference result with the highest generation probability is determined as the t-th inference result.
[0220] In this embodiment, the feature matrix will be fused. Input decoder ( The decoding process is performed to obtain multiple candidate inference results and a first generation probability corresponding to each candidate inference result:
[0221] ;
[0222] in, Parameters used to characterize the decoder.
[0223] Furthermore, for each candidate inference result, it is determined whether the candidate result exists in the pre-stored text data. If the candidate result exists in the text data, its corresponding second generation probability is equal to the original first generation probability; otherwise, its corresponding second generation probability is less than the first generation probability.
[0224] Of course, as another optional implementation, the preset rules include maintaining the first generation probability corresponding to the candidate inference result unchanged when the candidate inference result does not exist in the text data, and increasing the first generation probability corresponding to the candidate inference result when the candidate inference result exists in the text data.
[0225] It should be understood that both different implementation methods aim to increase the probability of candidate inference results existing in the text data becoming the final inference result, and the specific implementation method is not limited here. By using the above method, the existence of "candidate inference results in pre-stored text data" as a constraint condition, the generation probability of candidate inference results not existing in the text data is reduced, and the generation probability of candidate inference results existing in the text data is higher, making them more likely to become the final output inference result, thereby ensuring the plasticity of the source of the inference result.
[0226] It should be understood that, when the candidate inference result does not exist in the text data, the specific method and magnitude of reducing the first generation probability corresponding to the candidate inference result are not limited here, and can be adjusted according to the actual situation. As an optional implementation method, when the candidate inference result does not exist in the text data, the product of the first generation probability corresponding to the candidate inference result and a preset adjustment factor is determined as the second generation probability. The preset adjustment factor has a value range of (0, 1), and for example, the preset adjustment factor is 0.01.
[0227] It should be understood that the specific method for determining whether a candidate inference result exists in pre-stored text data is not limited here. For example, in some embodiments, a search is performed on the text data based on the candidate inference result to determine whether the candidate inference result exists in the pre-stored text data.
[0228] It should be understood that, in some embodiments, during the question-answering reasoning process using the trained question-answering model, the output also needs to satisfy the constraint that "the candidate reasoning result exists in the pre-stored text data". Specifically, during the question-answering reasoning process using the trained question-answering model, multiple candidate reasoning results and a first generation probability corresponding to each candidate reasoning result are obtained; it is determined whether the candidate reasoning result exists in the pre-stored text data; the first generation probability is updated based on a preset rule to obtain a second generation probability. The preset rule includes reducing the first generation probability corresponding to the candidate reasoning result when the candidate reasoning result does not exist in the text data, and maintaining the first generation probability corresponding to the candidate reasoning result unchanged when the candidate reasoning result exists in the text data.
[0229] In some embodiments, text data is data with a defined format. For example, text data typically has a clear chapter and entry structure, with different chapters covering different topics and each entry having specific rules and descriptions. The content of the text data is structured according to certain rules and characteristics, the file is parsed, and chapters, clause numbers, titles, content, etc., are extracted. The full text and metadata are stored in a preset format, while the original text is preserved for the construction of index data.
[0230] In some embodiments, structured data and index data are stored together in a storage unit to support efficient semantic queries and precise matching. For example, when determining whether the candidate inference result exists in pre-stored text data, the following steps are performed:
[0231] First, structured data is used to perform semantic alignment or field matching on candidate inference results to initially screen potentially relevant text fragments.
[0232] Simultaneously, the candidate inference results are used as a query pattern, and a backward search is performed using the index data to determine whether the candidate inference results exist in the pre-stored text data. Backward search is a method that expands character by character from the end of the pattern forward on the FM-index, maintaining matching intervals. An algorithm to efficiently determine the existence of a substring and locate its occurrence position.
[0233] Specifically, the matching intervals of the pattern in the original text are calculated by iterating through the count array and the occurrence array. If the final interval satisfies If the result is true, it indicates that the candidate inference result exists at least once in the text data; otherwise, it does not exist. For example, the specific process of backward search can be described as follows:
[0234] ;
[0235] in, For the t-th candidate reasoning result, initialize .
[0236] for arrive :
[0237] ;
[0238] ;
[0239] like ,but It exists in pre-stored text data.
[0240] Now verify the function:
[0241] ;
[0242] As an optional implementation, the first generation probability is adjusted based on the verification function:
[0243] ;
[0244] As another optional implementation, the first generation probability is adjusted based on the verification function:
[0245] ;
[0246] Among them, the preset adjustment factor (e.g., 0.01), The first generation probability, This represents the second generation probability.
[0247] In this embodiment, the constraint that the candidate reasoning result must exist in the pre-stored text data is introduced to ensure that the decoder can only generate continuous segments that actually exist in the text data, thus ensuring the most core requirement in the compliance field: the answer must be based on evidence and cannot be fabricated, thereby improving the interpretability and accuracy of the answer result.
[0248] Step 102: Sort the T inference results in order to obtain the question and answer results.
[0249] In this embodiment, the T inference results are arranged sequentially according to the order of iterative inference to obtain a sequence of length T, which is the final question-and-answer result. In specific implementation, the Tth inference result can be understood as the answer to the user's question, and the first T inference results can be understood as the inference steps or intermediate inference results that led to the final answer.
[0250] Through the above methods, the final output not only includes the final answer but also the reasoning process, allowing reviewers to intuitively verify the reasoning process and the basis for the answer, which meets the compliance review business's requirements for strong verifiability and transparency.
[0251] In this embodiment, the user's question is first input into a pre-trained question-answering model for T iterations of reasoning, yielding T reasoning results. These T reasoning results are then sorted sequentially to obtain the question-answering result. On one hand, because the question-answering model provided in this application has an end-to-end structure, it completely connects the retrieval and generation links, avoiding module fragmentation and improving the accuracy, reliability, and completeness of the reasoning chain for compliant question answering. On the other hand, through T iterations of reasoning, the question-answering model outputs T reasoning results, which include the model's complete reasoning path, thereby achieving interpretability and verifiability of the reasoning process.
[0252] For ease of understanding, a specific embodiment will be used as an example below. Please refer to... Figure 2 In this embodiment, the question-answering method based on the end-to-end language model provided by the present invention is applied to the payment compliance review business. The pre-stored text data is usually data in specific and clear formats such as legal documents, business rules and historical cases.
[0253] The first step in training a question-answering model is to construct a training dataset.
[0254] First, the relevant sample texts are processed to obtain structured data. Specifically, the collected text samples are parsed into JSON format, containing the full text and clause metadata (such as clause number, title, and location). For example, let the full text of the text be... , length is (Number of characters). The set of terms included in the sample text is defined as follows: ,in, For the number of clauses, the i-th clause Represented as:
[0255] ;
[0256] in, Number the clauses, for example, This refers to Article 8; For the heading of the clause (e.g., "Registered Capital"); For example, "Chapter Two: Establishment, Modification and Termination"; The terms are respectively in The starting and ending character positions in the text; This refers to the text fragment corresponding to the clause.
[0257] The final structured data is as follows:
[0258] ;
[0259] in, The file name.
[0260] Then, based on the BWT string, suffix array, count array, and occurrence array, an FM-index data is constructed corresponding to the text samples, supporting fast searching and compressed storage. To better support the application scenarios of compliant documents (such as clause location, compliance inspection, and cross-clause correlation analysis), a clause metadata table, a keyword index table, a character set mapping table, and a clause correlation diagram need to be added to the FM-index.
[0261] Finally, using keyword search and mapping, multiple training datasets are generated, each including query samples and corresponding answer samples. Specifically, based on the structured data, FM-index data, and pre-built compliance-related question set above, for each question, target keywords are identified, and relevant clauses are located using the FM-index. The relevant clauses are then extracted and answered, resulting in training data containing query samples and answer samples (step-by-step answers with annotations).
[0262] For example, first, the query sample Q and its corresponding target keyword P are determined. Then, a backward search is used to locate P:
[0263] ;
[0264] Finally, map the location to the terms:
[0265]
[0266] And construct the answer sample R:
[0267]
[0268] in, The first reasoning result is usually a keyword or topic. The second reasoning result is usually the context or entity involved. This is the third reasoning result, usually the answer summarized from the Articles.
[0269] By repeating the above steps, you can obtain multiple training data sets, which together form the training dataset.
[0270] ;
[0271] in, For the amount of training data, Let i be the i-th training data.
[0272] For example, if the query sample Q is "What is the minimum registered capital requirement for non-bank payment institutions?", the system first identifies... Backward search yielded SA
[5603] =2005, map the search results to specific clauses (e.g., Article 8), and construct the following answer sample based on the specific content of the clauses: step_0: "Non-bank payment institutions"; step_1: "Minimum registered capital"; answer: "Minimum (RMB 100 million)". Finally, output the training data in JSON format.
[0273] After obtaining the training data, the question-answering model is trained based on multiple training datasets. During the training process, the total loss value is... The loss is determined based on negative log-likelihood loss and similarity loss. Specifically, the negative log-likelihood loss... for:
[0274] ;
[0275] The similarity loss is:
[0276] ;
[0277] The total loss is:
[0278] ;
[0279] in, The weight is set in advance (e.g., 0.5).
[0280] During model training, the loss value for each training iteration is calculated through forward propagation, combined with... Ensure smooth and correct generation. To improve the semantic accuracy of keywords, the model parameters are updated via backpropagation, and the parameters of Encoder1, Encoder2, and Decoder are adjusted using gradient descent. Simultaneously, an FM-index constraint (determining whether the candidate inference result exists in pre-stored text data) is introduced to ensure the generated content is authentic and traceable, preventing illusory content. In this embodiment, the design of the aforementioned loss function and FM-index constraint not only balances generation quality and semantic accuracy but also ensures that the model generates answers that comply with regulations, while optimizing the semantic consistency of keywords.
[0281] After training, the user's question is input into the pre-trained question-answering model for T iterations of inference, resulting in T inference results. These T inference results are then sorted sequentially to obtain the question-answering result. In practical implementation, the inference depth and steps can be automatically adjusted according to different questions (i.e., the value of T can be adjusted) to more flexibly adapt to complex question-answering tasks.
[0282] In this embodiment, a single end-to-end language model is used to simultaneously complete document retrieval, reasoning path construction, and answer generation. The reasoning chain is naturally formed during a single forward propagation, resulting in a stable and consistent structure. Furthermore, the output question-and-answer results include T reasoning results, which contain a complete structure including question keywords, evidence segments, and the final answer, facilitating manual review and decision verification.
[0283] In some embodiments, after the question-answering model has been trained, the output question-answering results can be scored based on pre-determined quality scoring rules. Specifically, BLEU (Bilingual Evaluation Understudy) is used for generative quality scoring, which measures the similarity between the generated critical path (inference result) and the reference inference result based on the overlap rate of the inference results.
[0284] Specifically, the BLEU score is calculated as follows:
[0285] ;
[0286] in, The accuracy of the nth-order inference path segment is calculated by dividing the number of nth-order segments in the generated inference result that match the reference inference result by the total number of nth-order segments in the generated path. For weights, usually BP is a length penalty factor used to prevent the generated inference results from being too short.
[0287] For example, if the reference reasoning result is "non-bank payment institution", the obtained reasoning result is also "non-bank payment institution". The reasoning path fragment is as follows:
[0288] First-order fragment: [“”, “non”, “bank”, “payment”, “institution”, “”].
[0289] Second-order fragments: ["non", "non-bank", "bank payment", "payment institution", "institution"].
[0290] The first-order segment accuracy was calculated. 2nd order fragment accuracy Assuming BP=1.0, BLEU-4 score is 1.0.
[0291] The range and effects of the scores are as follows:
[0292] 0.2-0.4 (20-40) indicates poor generation results, with some segments matching but the overall results being inconsistent.
[0293] 0.4-0.6 (40-60) indicates that the generated result is of medium quality, the generated path is partially correct, but there are omissions or errors.
[0294] 0.6-0.8 (60-80) indicates that the generated result is good, with most segments matching and a small number of errors.
[0295] 0.8-1.0 (80-100) indicates that the generated result is excellent, almost a perfect match, and the generated path highly conforms to the reference path.
[0296] The above methods can be used to score the quality of the question-and-answer results generated by the question-and-answer model. This not only allows for the evaluation of the training effect of the question-and-answer model, but also enables the filtering of the question-and-answer results output by the model, thereby improving the quality of the final model output.
[0297] Please see Figure 3 This invention also provides a question-answering device 300 based on an end-to-end language model. Figure 3 This is a structural diagram of the question-answering device 300 based on an end-to-end language model provided in an embodiment of the present invention. Because the problem-solving principle of the question-answering device 300 based on an end-to-end language model is similar to that in the embodiment of the present invention... Figure 1 The question-answering method based on the end-to-end language model shown is similar, so the implementation of the question-answering device 300 based on the end-to-end language model can be found in the implementation of the method, and the repeated parts will not be described again.
[0298] like Figure 3 As shown, the question-answering device 300 based on an end-to-end language model includes:
[0299] The iterative reasoning module 301 is used to input user questions into a pre-trained question-answering model and perform T iterative reasoning to obtain T reasoning results. The question-answering model includes a first encoder, a second encoder, and a decoder, where T is a positive integer.
[0300] The sorting module 302 is used to sort the T inference results sequentially to obtain the question-and-answer results;
[0301] The T iterations of reasoning include:
[0302] The user question is encoded using the first encoder to obtain a first feature matrix;
[0303] During the t-th iteration of inference, the second feature matrix is generated by the second encoder;
[0304] The first feature matrix and the second feature matrix are fused to obtain a fused feature matrix.
[0305] The fused feature matrix is input into the decoder for decoding to obtain the t-th inference result;
[0306] Specifically, when t equals 1, the input of the second encoder is a preset initial value; when t is greater than 1 and less than T, the input of the second encoder is the set of reasoning results obtained from the previous t-1 reasoning iterations.
[0307] Optionally, the question-answering device 300 based on an end-to-end language model further includes:
[0308] An iterative training module is used to iteratively train the question-answering model based on multiple training data, each of the training data including a query sample and a corresponding answer sample;
[0309] The first determining module is used to determine the loss value of the Nth training iteration. The loss value includes a similarity loss. When the first cosine similarity between the question-answering result and the answer sample is greater than a threshold, the similarity loss is determined based on the first cosine similarity. When the first cosine similarity is less than or equal to the threshold, the similarity loss is determined based on the difference between 1 and the first cosine similarity. N is a positive integer.
[0310] The parameter adjustment module is used to adjust the parameters of the question-answering model based on the loss value;
[0311] The second determining module is used to determine the question-answering model trained in the Nth training iteration as the pre-trained question-answering model if the loss value satisfies the loss convergence condition.
[0312] Optionally, during the iterative training process, the step of inputting the fused feature matrix into the decoder for decoding to obtain the t-th inference result includes:
[0313] The fused feature matrix is input into the decoder for decoding to obtain multiple candidate inference results and a first generation probability corresponding to each candidate inference result;
[0314] Determine whether the candidate inference result exists in the pre-stored text data;
[0315] The first generation probability is updated based on a preset rule to obtain a second generation probability. The preset rule includes reducing the first generation probability corresponding to the candidate inference result when the candidate inference result does not exist in the text data, and maintaining the first generation probability corresponding to the candidate inference result unchanged when the candidate inference result exists in the text data.
[0316] The candidate inference result with the highest generation probability is determined as the t-th inference result.
[0317] Optionally, the question-answering device 300 based on an end-to-end language model further includes:
[0318] The structured processing module is used to perform structured processing on the text data to obtain structured data;
[0319] A construction module is used to construct index data corresponding to the text data based on the text data. The index data includes a string, a suffix array, a count array, and an occurrence array. The string is a string obtained by performing a Burrough Wheeler transform on the text data. The suffix array is used to record the starting position of each suffix in the text data in the arrangement after sorting according to a preset sorting rule. The count array is used to record the cumulative occurrence count of all characters less than the character in the preset sorting rule in the text data. The occurrence array is used to record the cumulative occurrence count of each character up to a preset position in the string.
[0320] A storage module is used to store the structured data and the index data;
[0321] The step of determining whether the candidate inference result exists in the pre-stored text data includes:
[0322] Based on the structured data and the index data, it is determined whether the candidate inference result exists in the text data.
[0323] Optionally, before storing the structured data and the index data, the question-answering device 300 based on the end-to-end language model further includes at least one of the following:
[0324] The first processing module is used to construct and store a clause metadata table, which records the metadata of each clause in the text data, as well as the mapping relationship between the clause and the string position;
[0325] The second processing module is used to construct and store a keyword index table, wherein the keyword index table is used to record preset keywords in the text data, and the mapping relationship between the preset keywords and the terms;
[0326] The third processing module is used to construct and store a character set mapping table, which is used to map characters in the text data to consecutive integer index values.
[0327] The fourth processing module is used to construct and store a clause association diagram, which records the relationships between the clauses.
[0328] Optionally, the similarity loss for the Nth training iteration is determined, including:
[0329] Calculate the sub-similarity loss for each iteration of the inference;
[0330] The similarity loss for the Nth training iteration is determined by the sum of the sub-similarity losses from the T iterations of the iterative reasoning.
[0331] The answer samples include T sequentially arranged sample reasoning results. The sub-similarity loss for the t-th iteration of reasoning is calculated, including:
[0332] Calculate the second cosine similarity between the t-th inference result and the t-th sample inference result;
[0333] If the second cosine similarity is greater than the threshold, the cosine similarity is determined as the sub-similarity loss; if the second cosine similarity is less than or equal to the threshold, the difference between 1 and the cosine similarity is determined as the sub-similarity loss.
[0334] Optionally, the step of fusing the first feature matrix and the second feature matrix to obtain a fused feature matrix includes:
[0335] Calculate the inner product of the first feature matrix and the second feature matrix to obtain the inner product calculation result;
[0336] The first feature matrix and the second feature matrix are cross-fused based on the cross-attention mechanism to obtain the cross-attention result;
[0337] The inner product calculation result, the cross attention result, the first feature matrix, and the second feature matrix are concatenated to obtain the fused feature matrix.
[0338] The question-answering device 300 based on an end-to-end language model provided in this embodiment of the invention can execute the question-answering method embodiment based on the end-to-end language model described above. Its implementation principle and technical effect are similar, and will not be repeated here.
[0339] In the several embodiments provided in this application, it should be understood that the disclosed methods and apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0340] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can be physically comprised separately, or two or more units can be integrated into one unit. The integrated unit described above can be implemented in hardware or in the form of hardware plus software functional units.
[0341] The integrated units implemented as software functional units described above can be stored in a computer-readable storage medium. These software functional units, stored in a storage medium, include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute some steps of the transmission and reception methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0342] like Figure 4 As shown, this embodiment of the invention also provides an electronic device 400, which includes a processor 401, configured to read a program from a memory 402 and execute the following steps:
[0343] The user's question is input into a pre-trained question-answering model and iterates T times to obtain T inference results. The question-answering model includes a first encoder, a second encoder, and a decoder, where T is a positive integer.
[0344] Sort the T inference results in order to obtain the question and answer results;
[0345] The T iterations of reasoning include:
[0346] The user question is encoded using the first encoder to obtain a first feature matrix;
[0347] During the t-th iteration of inference, the second feature matrix is generated by the second encoder;
[0348] The first feature matrix and the second feature matrix are fused to obtain a fused feature matrix.
[0349] The fused feature matrix is input into the decoder for decoding to obtain the t-th inference result;
[0350] Specifically, when t equals 1, the input of the second encoder is a preset initial value; when t is greater than 1 and less than T, the input of the second encoder is the set of reasoning results obtained from the previous t-1 reasoning iterations.
[0351] Optionally, the processor 401 is further configured to read the program in the memory 402 and perform the following steps:
[0352] The question-answering model is iteratively trained based on multiple training data, each of which includes a query sample and a corresponding answer sample.
[0353] Determine the loss value for the Nth training iteration, the loss value including similarity loss. If the first cosine similarity between the question-answering result and the answer sample is greater than a threshold, the similarity loss is determined based on the first cosine similarity. If the first cosine similarity is less than or equal to the threshold, the similarity loss is determined based on the difference between 1 and the first cosine similarity, where N is a positive integer.
[0354] The parameters of the question-answering model are adjusted based on the loss value;
[0355] If the loss value satisfies the loss convergence condition, the question-answering model trained for the Nth time is determined as the pre-trained question-answering model.
[0356] Optionally, the processor 401 is further configured to read the program in the memory 402 and perform the following steps:
[0357] The fused feature matrix is input into the decoder for decoding to obtain multiple candidate inference results and a first generation probability corresponding to each candidate inference result;
[0358] Determine whether the candidate inference result exists in the pre-stored text data;
[0359] The first generation probability is updated based on a preset rule to obtain a second generation probability. The preset rule includes reducing the first generation probability corresponding to the candidate inference result when the candidate inference result does not exist in the text data, and maintaining the first generation probability corresponding to the candidate inference result unchanged when the candidate inference result exists in the text data.
[0360] The candidate inference result with the highest generation probability is determined as the t-th inference result.
[0361] Optionally, the processor 401 is further configured to read the program in the memory 402 and perform the following steps:
[0362] The text data is processed into structured data to obtain structured data;
[0363] Based on the text data, index data corresponding to the text data is constructed. The index data includes a string, a suffix array, a count array, and an occurrence array. The string is a string obtained by performing a Burrough Wheeler transform on the text data. The suffix array is used to record the starting position of each suffix in the text data in the arrangement after sorting according to a preset sorting rule. The count array is used to record the cumulative number of occurrences of all characters smaller than the character in the preset sorting rule in the text data. The occurrence array is used to record the cumulative number of occurrences of each character up to a preset position in the string.
[0364] Store the structured data and the index data;
[0365] The step of determining whether the candidate inference result exists in the pre-stored text data includes:
[0366] Based on the structured data and the index data, it is determined whether the candidate inference result exists in the text data.
[0367] Optionally, the processor 401 is further configured to read the program in the memory 402 and perform at least one of the following steps:
[0368] Construct and store a clause metadata table, which is used to record the metadata of each clause in the text data, as well as the mapping relationship between the clause and the string position;
[0369] Construct and store a keyword index table, which records preset keywords in the text data and the mapping relationship between the preset keywords and the terms;
[0370] Construct and store a character set mapping table, which is used to map characters in the text data to consecutive integer index values;
[0371] Construct and store a clause association diagram, which is used to record the relationships between the clauses.
[0372] Optionally, the processor 401 is further configured to read the program in the memory 402 and perform the following steps:
[0373] Calculate the sub-similarity loss for each iteration of the inference;
[0374] The similarity loss for the Nth training iteration is determined by the sum of the sub-similarity losses from the T iterations of the iterative reasoning.
[0375] The answer samples include T sequentially arranged sample reasoning results. The sub-similarity loss for the t-th iteration of reasoning is calculated, including:
[0376] Calculate the second cosine similarity between the t-th inference result and the t-th sample inference result;
[0377] If the second cosine similarity is greater than the threshold, the cosine similarity is determined as the sub-similarity loss; if the second cosine similarity is less than or equal to the threshold, the difference between 1 and the cosine similarity is determined as the sub-similarity loss.
[0378] Optionally, the processor 401 is further configured to read the program in the memory 402 and perform the following steps:
[0379] Calculate the inner product of the first feature matrix and the second feature matrix to obtain the inner product calculation result;
[0380] The first feature matrix and the second feature matrix are cross-fused based on the cross-attention mechanism to obtain the cross-attention result;
[0381] The inner product calculation result, the cross attention result, the first feature matrix, and the second feature matrix are concatenated to obtain the fused feature matrix.
[0382] The electronic device 400 provided in this embodiment of the invention can execute the above-described question-answering method embodiment based on an end-to-end language model. Its implementation principle and technical effect are similar, and will not be described again here.
[0383] This application also provides a readable storage medium storing a program. When the program is executed by a processor, it implements the various processes of the above-described question-answering method embodiment based on an end-to-end language model and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0384] The readable storage medium can be any available medium or data storage device that the processor can access, including but not limited to magnetic storage (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc.), optical storage (such as compact disks (CD), digital video discs (DVD), Blu-ray discs (BD), high-definition universal discs (HVD), etc.), and semiconductor storage (such as read-only memory (ROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), non-volatile memory (NAND FLASH), solid-state disks (SSD), etc.).
[0385] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0386] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0387] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. An end-to-end language model based question answering method, characterized by, The method comprises the following steps: inputting a user question into a pre-trained question and answer model to perform T times of iterative reasoning to obtain T reasoning results, wherein the question and answer model comprises a first encoder, a second encoder and a decoder, and T is a positive integer; sequentially ranking the T reasoning results to obtain a question and answer result; wherein the T times of iterative reasoning comprises: encoding the user question through the first encoder to obtain a first feature matrix; in the tth time of iterative reasoning, generating a second feature matrix through the second encoder; fusing the first feature matrix and the second feature matrix to obtain a fused feature matrix; inputting the fused feature matrix into the decoder for decoding to obtain the tth reasoning result; wherein, in the case that t is equal to 1, the input of the second encoder is a preset initial value; in the case that t is greater than 1 and less than T, the input of the second encoder is a set of reasoning results obtained in the previous t-1 times of reasoning.
2. The method of claim 1, wherein, Before the step of inputting the user question into the pre-trained question and answer model to perform T times of iterative reasoning to obtain T reasoning results, the method further comprises: iteratively training the question and answer model based on a plurality of training data, each of the training data comprising a query sample and a corresponding answer sample; determining a loss value of the Nth training, wherein the loss value comprises a similarity loss, in the case that a first cosine similarity between the question and answer result and the answer sample is greater than a threshold value, the similarity loss is determined based on the first cosine similarity, in the case that the first cosine similarity is less than or equal to the threshold value, the similarity loss is determined based on the difference between 1 and the first cosine similarity, N is a positive integer; adjusting the parameters of the question and answer model based on the loss value; in the case that the loss value meets a loss convergence condition, determining the question and answer model of the Nth training as the pre-trained question and answer model.
3. The method of claim 2, wherein, In the iterative training process, the step of inputting the fused feature matrix into the decoder for decoding to obtain the tth reasoning result comprises: inputting the fused feature matrix into the decoder for decoding to obtain a plurality of candidate reasoning results and a first generation probability corresponding to each candidate reasoning result; determining whether the candidate reasoning result exists in pre-stored text data; updating the first generation probability based on a preset rule to obtain a second generation probability, wherein the preset rule comprises reducing the first generation probability corresponding to the candidate reasoning result in the case that the candidate reasoning result does not exist in the text data, and maintaining the first generation probability corresponding to the candidate reasoning result unchanged in the case that the candidate reasoning result exists in the text data; determining the candidate reasoning result with the maximum second generation probability as the tth reasoning result.
4. The method of claim 3, wherein, Before the step of iteratively training the question and answer model based on a plurality of training data, the method further comprises: performing structural processing on the text data to obtain structured data; constructing index data corresponding to the text data based on the text data, the index data comprising a string, a suffix array, a count array, and an occurrence array, the string being a string obtained by performing a Burrows Wheeler transform on the text data, the suffix array being used to record a starting position corresponding to each suffix in the text data in an arrangement after sorting according to a preset sorting rule, the count array being used to record a cumulative occurrence number of all characters smaller than a character in the text data, and the occurrence array being used to record a cumulative occurrence number of each character up to a preset position in the string; storing the structured data and the index data; the determining whether the candidate reasoning result exists in the pre-stored text data comprises: determining whether the candidate reasoning result exists in the text data based on the structured data and the index data.
5. The method of claim 4, wherein, Before the storing the structured data and the index data, the method further comprises at least one of the following: constructing and storing a clause metadata table, the clause metadata table being used to record meta-information of each clause in the text data and a mapping relationship between the clause and a string position; constructing and storing a keyword index table, the keyword index table being used to record a preset keyword in the text data and a mapping relationship between the preset keyword and the clause; constructing and storing a character set mapping table, the character set mapping table being used to map characters in the text data to continuous integer index values; constructing and storing a clause association graph, the clause association graph being used to record an association relationship between the clauses.
6. The method of claim 2, wherein, determining a similarity loss of the Nth training comprises: respectively calculating a sub-similarity loss of each of the iterative reasonings; determining the similarity loss of the Nth training based on a sum of the sub-similarity losses of the T iterative reasonings; wherein the answer sample comprises T sample reasoning results arranged in sequence, and the sub-similarity loss of the tth iterative reasoning comprises: calculating a second cosine similarity between the tth reasoning result and the tth sample reasoning result; in a case where the second cosine similarity is greater than the threshold value, determining the cosine similarity as the sub-similarity loss, and in a case where the second cosine similarity is less than or equal to the threshold value, determining a difference between 1 and the cosine similarity as the sub-similarity loss.
7. The method of claim 1, wherein, the fusing the first feature matrix and the second feature matrix to obtain a fused feature matrix comprises: calculating an inner product of the first feature matrix and the second feature matrix to obtain an inner product calculation result; cross-fusing the first feature matrix and the second feature matrix based on a cross-attention mechanism to obtain a cross-attention result; splicing the inner product calculation result, the cross-attention result, the first feature matrix, and the second feature matrix to obtain a fused feature matrix.
8. An apparatus for question answering based on an end-to-end language model, comprising: comprises: An iterative reasoning module is configured to input a user question into a pre-trained question and answer model for T times of iterative reasoning to obtain T reasoning results, the question and answer model comprises a first encoder, a second encoder and a decoder, T is a positive integer; An ordering module is configured to sequentially order the T reasoning results to obtain a question and answer result; The T times of iterative reasoning comprise: The first encoder is configured to encode the user question to obtain a first feature matrix; In the tth time of iterative reasoning, the second encoder is configured to generate a second feature matrix; The first feature matrix and the second feature matrix are fused to obtain a fused feature matrix; The fused feature matrix is input into the decoder for decoding to obtain the tth reasoning result; In a case where t is equal to 1, an input of the second encoder is a preset initial value; in a case where t is greater than 1 and less than T, an input of the second encoder is a set of reasoning results obtained in previous t-1 times of reasoning.
9. An electronic device comprising: A memory, a processor and a program stored in the memory and executable on the processor; characterized in that, The processor is configured to read the program in the memory to implement steps in the question and answer method based on the end-to-end language model in any one of claims 1 to 7.
10. A readable storage medium for storing a program, characterized in that, The program is executed by the processor to implement steps in the question and answer method based on the end-to-end language model in any one of claims 1 to 7.