Question sentence rewriting method and related device
By using the dynamic attention mechanism guided by intention feature vectors in the financial dialogue system, the questions in the financial dialogue system are rewritten, which solves the problem of fine-grained control of question rewriting in multiple rounds of dialogues, and improves the rewritten questions and knowledge base. matching and accuracy.
Patent Information
- Application Number
- CN202410914040.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-09-27
AI Technical Summary
In financial dialogue systems, it is difficult to accurately control the fine-grainedness of question rewriting in multi-turn dialogue scenarios, resulting in the rewritten question being inconsistent with the intention of the original question, affecting subsequent question answers in the knowledge base.
By obtaining the question to be rewritten and the historical dialogue data in the current question and answer data, the intention feature vector is determined, and input into the pre-trained question rewriting model for rewriting, and the rewritten target question is output, and the intention feature vector is used to guide the dynamics Attention mechanism to improve rewriting accuracy.
It improves the accuracy of question rewriting, matches the rewritten question with the knowledge base, reduces uncertainty in the rewriting process, and provides users with more accurate and efficient dialogue services.
Smart Images

Figure CN118709701A
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to a question rewriting method and related devices. Background Art
[0002] With the rapid development of artificial intelligence technology, financial dialogue systems, as an important part of intelligent customer service, are increasingly attracting attention from the industry. In financial dialogue systems, multi-round dialogues are the key to achieving complex question answers and deep interactions. However, as the number of dialogue rounds increases, questions with unclear references and omitted information need to be rewritten. During the rewriting process, it is difficult to accurately control the granularity of the rewriting, resulting in the rewritten questions being inconsistent with the original questions, affecting the subsequent knowledge base-based question answering. Summary of the invention
[0003] The embodiments of the present application provide a question rewriting method and related devices to improve the accuracy of question rewriting.
[0004] In a first aspect, an embodiment of the present application provides a method for question rewriting, comprising:
[0005] In a multi-round dialogue scenario, obtaining a first question sentence to be rewritten in current question-and-answer data and first historical dialogue data corresponding to the first question sentence to be rewritten;
[0006] Determine an intention feature vector according to the first question to be rewritten;
[0007] The first question to be rewritten, the first historical dialogue data and the intention feature vector are input into a pre-trained question rewriting model, the first question to be rewritten is rewritten, and the rewritten target question is output.
[0008] In a second aspect, an embodiment of the present application provides a question rewriting device, comprising:
[0009] An acquisition unit, configured to acquire, in a multi-round dialogue scenario, a first question sentence to be rewritten in current question-and-answer data and first historical dialogue data corresponding to the first question sentence to be rewritten;
[0010] A determining unit, configured to determine an intention feature vector according to the first question to be rewritten;
[0011] The rewriting unit is used to input the first question to be rewritten, the first historical dialogue data and the intention feature vector into a pre-trained question rewriting model, rewrite the first question to be rewritten, and output the rewritten target question.
[0012] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory storing execution instructions, wherein the memory stores one or more programs; when the processor executes the execution instructions stored in the memory, the processor executes the method described in the first aspect.
[0013] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing an energy data management program, including execution instructions. When a processor of an electronic device executes the execution instructions, the processor executes the method described in the first aspect.
[0014] In a fifth aspect, an embodiment of the present application provides a computer program product, wherein the computer program product includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute some or all of the steps described in the first aspect of the embodiment of the present application. The computer program product may be a software installation package.
[0015] It can be seen that in the embodiment of the present application, first, the first question to be rewritten in the current question-answering data and the first historical dialogue data corresponding to the first question to be rewritten are obtained in a multi-round dialogue scenario; the intention feature vector is determined according to the first question to be rewritten; the first question to be rewritten, the first historical dialogue data and the intention feature vector are input into a pre-trained question rewriting model, the first question to be rewritten is rewritten, and the rewritten target question is output. The present application adds the intention feature vector for the question to the question rewriting process, so that the intention granularity of the question is accurately identified during question rewriting, and the rewritten question matches the knowledge base, thereby improving the accuracy of question rewriting. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0017] Figure 1 It is a flowchart of a question rewriting method provided by an embodiment of the present application;
[0018] Figure 2 It is a schematic diagram of the architecture of a question rewriting model provided by an embodiment of the present application;
[0019] Figure 3 It is a schematic diagram of the architecture of an encoder provided in an embodiment of the present application;
[0020] Figure 4 It is a flow chart of a self-attention model provided in an embodiment of the present application;
[0021] Figure 5 is a flowchart of another question rewriting method provided in an embodiment of the present application;
[0022] Figure 6 It is a block diagram of the functional units of a question rewriting device provided in an embodiment of the present application;
[0023] Figure 7 It is a block diagram of the functional units of another question rewriting device provided by an embodiment of the present application;
[0024] Figure 8 It is a structural schematic diagram of an electronic device proposed in an embodiment of the present application. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0026] The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.
[0027] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0028] Currently, it is difficult to accurately control the granularity of rewriting during question rewriting, which results in the rewritten question being inconsistent with the original question's intent, affecting subsequent knowledge-based question answering.
[0029] In view of the above problems, the embodiments of the present application provide a question rewriting method and related devices, which are described in detail below in conjunction with the accompanying drawings.
[0030] See also Figure 1 , Figure 1 FIG. 1 is a flow chart of a question rewriting method provided by an embodiment of the present application. Figure 1 As shown, the method includes the following steps.
[0031] S110, obtaining a first question sentence to be rewritten in current question and answer data and first historical dialogue data corresponding to the first question sentence to be rewritten in a multi-round dialogue scenario.
[0032] The first question to be rewritten refers to the latest question in the multi-round dialogue between the user and the intelligent customer service, that is, the question in the current round, and the first historical dialogue data refers to the information of the historical rounds related to the question in the multi-round dialogue, which is used to understand the user's intention so as to accurately rewrite the question. Specifically, in the multi-round dialogue, the intelligent customer service provides the source of the answer or information to the user's question based on the data of the knowledge base to answer it. The knowledge base stores and manages knowledge information related to specific fields or topics, including question-answer pairs, similar questions and other information.
[0033] S120: Determine an intention feature vector according to the first question to be rewritten.
[0034] Among them, the intent feature vector can be determined according to the trained intent recognition model. Specifically, all similar questions in the knowledge base question-answer pair set and the intent label pairs corresponding to each question can be used as training data to train the pre-trained language representation model (Bidirectional Encoder Representations from Transformers, BERT), so as to obtain a trained intent recognition model with certain domain knowledge. Furthermore, the training data pairs of the intent recognition model are given as examples, similar questions: what is the current term +, the intent label: current term + introduction; similar questions: current term + what functions does it have, the intent label: current term + introduction, etc. The first question to be rewritten is input into the trained intent recognition model to obtain the intent label of the current question to be rewritten based on the knowledge base, and the intent label is converted into an intent feature vector.
[0035] Specifically, the intent label of each similar question in the training data pair can be first converted into an intent feature vector, and then all similar questions in the knowledge base question-answer pair set and the intent feature vector pairs corresponding to each question can be used as training data to train the BERT model to obtain a trained intent recognition model, and then the first question to be rewritten can be input into the trained intent recognition model to obtain the intent feature vector for the current question.
[0036] Furthermore, as the knowledge base is updated and expanded, new similar questions and their corresponding intent label pairs can be continuously added to the training data to optimize the intent recognition model. Specifically, the intent labels are manually calibrated. Continuous monitoring of the knowledge base data can make full use of the information in the knowledge base and improve the model's ability to understand user intent.
[0037] S130, inputting the first question to be rewritten, the first historical dialogue data and the intention feature vector into a pre-trained question rewriting model, rewriting the first question to be rewritten, and outputting the rewritten target question.
[0038] Specifically, before inputting the first question to be rewritten, the first historical dialogue data and the intention feature vector into a pre-trained question rewriting model, the method further includes: obtaining a training sample data set, the training sample data set including training samples corresponding to a plurality of tasks, the plurality of tasks including a whether to rewrite task, an intention matching task and a question rewriting task, each training sample including a second question to be rewritten in the historical question and answer data and a second historical dialogue data corresponding to the second question to be rewritten, and a label corresponding to each of the plurality of tasks; performing cyclic iterative training on the question rewriting models of the plurality of tasks according to the training samples in the training sample data set, and obtaining the pre-trained question rewriting model when the training is completed; wherein, the following operations are performed during one cyclic iterative training process: obtaining training data; Sample n, the training sample n is any group of training samples in the training sample data set; the second question to be rewritten and the second historical dialogue data in the training sample n are input into the question rewriting model to obtain the processing result corresponding to each task output by the question rewriting model; based on the processing result corresponding to each task and the label corresponding to each task in the training sample n, a loss function corresponding to each task is constructed; according to the loss function corresponding to task m, the relevant parameters of the task m are adjusted in the question rewriting model, and the task m is any task among the multiple tasks; the weight corresponding to each task in the multiple tasks is obtained; the total loss function is determined according to the weight corresponding to each task and the loss function corresponding to each task; the question rewriting model is adjusted based on the total loss function.
[0039] The question rewriting model is a model based on a multi-task framework. The multi-tasks include the following tasks: question rewriting task, intent matching task and question rewriting task. The question rewriting model can be obtained by fine-tuning the pre-trained model based on the self-attention model (Transformer). A dynamic attention mechanism guided by feature vectors is added to the self-attention model, and an output layer is set for each task, namely, the intent matching task layer, the rewriting task layer and the question rewriting task layer. For details, please refer to Figure 2 , Figure 2 Schematic diagram of the architecture of a question rewriting model provided by an embodiment of the present application. Figure 2 As shown, the question rewriting model includes an input layer, an encoding layer, and an output layer. The input layer inputs a processed text sequence, including the context information of the historical round and the current round question. For example, the corresponding concatenated sequence is, that is, what is the demand+[sep] the demand+asset value-added service provided by WeBank to users[sep] what about the demand+plus, where [sep] is used to represent a separator. At the same time, the input layer also receives the input of the intent feature vector. After the input, an embedding layer E1, E2, ..., E N The embedding layer considers the semantics of words, the segmentation of sentences, and the position of words in the sequence for the input sequence, so as to better understand and process natural language text. Specifically, the words are converted into vector representations, that is, each word in the input text is converted into a vector of fixed dimension to form a word vector (TokenEmbedding); the input sentence pairs are distinguished, and the exemplary input is two sentences. A vector can be assigned to all words in the first sentence, and another vector can be assigned to all words belonging to the second sentence to form a segment vector (SegmentEmbedding); and the input sequence is sequentially encoded, and the vector representation of each position in the input sequence is learned through position embedding to form a position vector (Position Embedding), so as to understand the sequential information of the text, and the input of the self-attention model is obtained by adding the word vector, position vector and segment vector.
[0040] Specifically, Figure 2 As shown in Figure 1, the encoding layer in the question rewriting model includes multiple layers of encoders, and multiple Transformer encoders can be used to encode the input text to process the input text sequence, where Trm is the Transformer encoder. Figure 3 , Figure 3 Schematic diagram of the architecture of an encoder provided by an embodiment of the present application, such as Figure 3As shown in the figure, the Transformer encoder is generated by superposition of a multi-head attention layer (Multi-Head Attention), residual connection and layer normalization (Add&Norm) and a position fully connected feedforward network (Feed Forward). Specifically, in the multi-head attention layer, different attention weights are assigned to each word in the sequence to capture the dependency between words, and a dynamic attention bias matrix guided by the intention feature vector is introduced during attention calculation to dynamically adjust the attention weights so that the model can more accurately reflect the user's intention when rewriting questions, thereby improving the quality of rewriting. Residual connection and layer normalization are used to prevent the model from experiencing gradient vanishing or gradient exploding problems during training, thereby improving the training stability of the model. The position fully connected feedforward network adds an extra dimension to each position to process the order information in the sequence. Specifically, when processing sequence data, the feedforward network considers the input vector and position encoding to learn the order relationship of elements in the sequence and predict or generate based on these relationships.
[0041] Among them, Figure 2 As shown, before the output layer in the question rewriting model, there are also pre-fine-tuning layers T1, T2, ..., T N , and make different adjustments according to different task requirements. The output layer in the question rewriting model includes the intent matching task output layer, the whether to rewrite task output layer and the question rewriting task output layer. Specifically, the intent matching task output layer is used to predict the user's query intent, and may include a fully connected layer and a normalized layer including a normalization function softmax, which is used to convert the attention vector into the probability distribution of the intent; the whether to rewrite task output layer is used to determine whether the current round of questions needs to be rewritten, and may include a fully connected layer and a normalized layer including a normalization function sigmoid, which is used to generate a probability value to represent the possibility of rewriting; the question rewriting task output layer is used to generate the rewritten question, and may include a Transformer decoder to implement the rewriting task, where the decoder uses the attention vector and the output of the encoding layer as input to generate a new question.
[0042] Among them, for training the question rewriting model based on the above architecture, training data corresponding to each task in the multiple tasks can be collected, including training data for the question rewriting task, where a set of training data pairs can be the context of the historical conversation and the concatenated sequence of the current round of questions, as well as manually annotated whether to rewrite labels, the whether to rewrite labels indicate whether the current round of questions needs to be rewritten, and an exemplary training sample pair can be: "What is current account + [sep] Current account + asset value-added services provided by WeBank to users [sep] What about current account + plus, it needs to be rewritten"; the training data also includes training data for the intent matching task, where a set of training data pairs can be the context of the historical conversation and the concatenated sequence of the current round of questions, as well as manually annotated intent labels, and the manually annotated intent labels represent The query intention of the user is indicated. Furthermore, the intent recognition model can be used to obtain the recognized intent label, and manual annotation is performed according to the intent label output by the model. An exemplary training sample pair may be: "What is current account + [sep] Current account + asset value-added service provided by WeBank to users [sep] What about current account + plus, current account + plus product introduction"; the training data also includes training data for the question rewriting task, wherein a set of training data pairs may be the context of the historical dialogue and the concatenated sequence of the current round of questions, as well as the manually annotated rewritten questions. An exemplary training sample pair may be: "What is current account + [sep] Current account + asset value-added service provided by WeBank to users [sep] What about current account + plus, what is current account + plus"?
[0043] Among them, the question rewriting model is trained by using the above-collected training data, and the loss function is calculated based on the output results of the model and the manually annotated rewriting labels, manually annotated intent labels, and manually annotated rewritten questions in the training data. Specifically, the prediction results and loss functions can be calculated through forward propagation. The specific process is as follows: The loss function for the intent matching task can use the cross entropy loss to measure the difference between the intent predicted by the model and the true intent. For K intent categories, the loss function L1 of the intent matching task can be expressed as: Among them, I is the label matrix of the true intent, I * is the intention probability distribution matrix predicted by the model, are the probabilities of the kth intent category in the matrix on dimension i. During the training process, by minimizing this loss function, the model can learn how to predict the probability distribution of intent that is as close as possible to the true intent, thereby improving the accuracy of intent recognition. The loss function for the rewrite task can use binary cross entropy loss to measure the accuracy of the model in judging whether to rewrite. The loss function L2 for the rewrite task can be expressed as: L2(y,y * )=-[ylog(y* )+(1-y)log(1-y * )], where y is the label of whether the rewrite is real, and can be 0 or 1, where 0 means no rewrite is needed and 1 means rewrite is needed. * is the rewriting probability predicted by the model, which is between 0 and 1. During the training process, by minimizing this loss function, the model can learn how to accurately determine whether the current question needs to be rewritten. The loss function for the question rewriting task can use the cross entropy loss function to measure the difference between the rewritten question generated by the model and the real rewritten question. For a sequence consisting of t time steps, the loss function L3 of the question rewriting task can be expressed as: Among them, R is the sequence of real rewritten questions, R * is the sequence predicted by the model, R ti , are the actual and predicted probability distributions at the tth time step in the sequence, respectively. By minimizing this loss function, the model can learn how to generate an output sequence that is as close as possible to the actual rewritten question, thereby improving the quality of question rewriting.
[0044] After determining the loss functions of multiple tasks, according to the weights corresponding to the loss functions of each task, the losses of each task are added up according to the weights to obtain the total loss function L total , the specific formula is: L total =αL1+βL2+γL3, where α, β and γ are hyperparameters used to adjust the relative importance of each task loss function. Specifically, hyperparameters are key parameters in machine learning and deep learning models, and they are set before model training. Among them, the introduction of the intent matching task can help the model understand the user's intention more accurately and provide important contextual information for the question rewriting task, thereby providing more fine-grained control in the rewriting task; the introduction of the whether to rewrite task can help the model determine whether the current question needs to be rewritten, thereby reducing unnecessary rewriting and avoiding the introduction of errors or confusion. In the question rewriting model, the intention matching task and the whether to rewrite task are used to assist the question rewriting task, so that the question to be rewritten can be better rewritten. Exemplarily, α and β can be set to 0.1, and γ can be set to 0.8.
[0045] The above steps are repeated for iterative training until the performance of the question rewriting model on the validation set reaches a preset stopping condition, such as the loss no longer decreases, the accuracy no longer increases, or a preset training round is reached.
[0046] It can be seen that in this embodiment, by integrating the question rewriting task, intent matching task and whether to rewrite function into the same model, the in-depth understanding of user intention is enhanced, and the generalization ability of the model is improved through multi-task learning, so that it can flexibly adjust the rewriting strategy to adapt to the needs of different knowledge base granularities.
[0047] Among them, after the first question to be rewritten and the first historical dialogue data are sequenced and spliced, they are input into the trained question rewriting model. An example may be "What is Anyingxiang [sep] Anyingxiang is a financial product [sep] How to buy financial products?"
[0048] Specifically, the rewriting of the first question to be rewritten and outputting the rewritten target question includes: obtaining a first sequence including multiple element vectors, the first sequence is determined according to the first question to be rewritten and the first historical dialogue data; determining a multi-channel feature vector of each element vector in the first sequence, and determining an attention bias matrix according to the intention feature vector, the attention bias matrix is used to adjust the attention of the multi-channel feature vector; determining an attention output result according to the multi-channel feature vector and the attention bias matrix; rewriting the first question to be rewritten according to the attention output result, and outputting the target question.
[0049] Among them, the embedding layer in the question rewriting model considers information such as the semantics of the words in the input concatenated sequence, the segmentation of the sentences, and the position of the words in the sequence, that is, the words in the concatenated sequence are converted into vector representations in turn, the sentence pairs in the concatenated sequence are distinguished, and the input concatenated sequence is sequentially encoded and added to output a first sequence including multiple vectors, which are input into the self-attention model to determine the attention weight.
[0050] Specifically, the determining of the multi-channel feature vector of each element vector in the first sequence, and determining the attention bias matrix according to the intention feature vector, include: obtaining the first feature vector, the second feature vector and the third feature vector based on the first weight matrix, the second weight matrix and the third weight matrix respectively, the element vector i is any element vector in the first sequence, and determining the attention bias matrix according to the intention feature vector and the fourth weight matrix, the first weight matrix, the second weight matrix, the third weight matrix and the fourth weight matrix are different learning parameter matrices.
[0051] The self-attention model includes multiple attention heads, each of which is used to calculate the degree of association between each word in the first input sequence and other words. Each attention head has multiple channels, which are used to project the first sequence into different linear spaces to extract semantic information of element vectors from different dimensions. Further, according to the first weight matrix W q Linearly project the first sequence to obtain the first eigenvector, i.e., the query vector q; according to the second weight matrix W k Linearly project the first sequence to obtain the second eigenvector, namely the key vector k, including k1, k2, ..., k n ; According to the third weight matrix W v Linearly project the first sequence to obtain the third eigenvector, i.e., the value vector v, including v1, v2, ..., v n Among them, the above weight matrices are all learnable weight matrices, which can be adjusted and optimized through training to improve the performance and expression ability of the model.
[0052] Among them, the attention bias matrix M is obtained by multiplying the intention feature vector and the learnable fourth weight matrix. For details, please refer to the formula: M = W intent V intent , where W intent is the fourth learnable weight matrix, V intent is the intent feature vector. The attention bias matrix M is used to dynamically adjust the attention weight to ensure that the self-attention model pays more attention to the information related to the intent of the current question. The input of the exemplary question rewriting model is "What is Anyingxiang [sep] Anyingxiang is a financial product [sep] How to buy financial products?" According to the current attention bias matrix M, the current question rewriting can capture the key information of financial products instead of the specific brand or product name in the context.
[0053] Specifically, determining the attention output result based on the multi-channel eigenvector and the attention bias matrix includes: determining a reference similarity between the first eigenvector and the second eigenvector; correcting the reference similarity according to the attention bias matrix to obtain a target similarity; and determining the attention output result based on the target similarity and the third eigenvector.
[0054] Among them, see Figure 4 , Figure 4 is a flow chart of a self-attention model provided in an embodiment of the present application, such as Figure 4 As shown, the attention output result includes the following steps.
[0055] Step 1: Input the above feature vector into the self-attention model, that is, input q, k, v, V intent ;
[0056] Step 2: For each attention head, calculate the attention weight according to the query vector q and the key vector k1-k n The similarity s is calculated by directly finding the inner product of (q, k) to obtain s1, s2, ..., s n The specific formula is Among them, d k is the dimension of the key vector k. Other methods can also be used to calculate the similarity between the query vector q and the key vector k;
[0057] Step 3: Correct the similarity through the attention bias matrix. The corrected similarity is: s+M;
[0058] Step 4: Normalize the corrected similarity to obtain the attention distribution. An exemplary attention distribution can be: softmax(s+M), determine the weight a corresponding to q, i.e., a1, a2, ..., a n ;
[0059] Step 5: Calculate the weighted sum of attention, perform weighted summation on the value vector v according to the attention score weight a, and obtain the final attention output h, specifically: h = softmax(s+M)v;
[0060] Step 6: Concatenate the weighted sums of the attentions of multiple attention heads, repeat the calculations of steps 1-5 above, obtain the attention outputs of multiple heads, and calculate h1, h2, h3, ..., h n , and then perform the vector concatenation operation concat at the same time bit, and finally output the projection matrix W o A linear transformation is performed on the concatenated result to achieve the purpose of dimensionality reduction and information fusion of each tap, and the final multi-head attention output result MultiHead is obtained. o It is used to integrate and map the attention results of multiple heads to generate the final output representation, W o is an m×n matrix. It is a learnable parameter matrix in the multi-head attention mechanism. The vector concatenation formula is as follows: Among them, the formula for the output result MultiHead of multi-head attention is as follows:
[0061] Among them, after obtaining the final attention output result, it is fine-tuned through residual connection, layer normalization, position fully connected feedforward network, etc., and then input into the question rewriting task to rewrite the question, and then output the rewritten question.
[0062] It can be seen that in this embodiment, a dynamic attention mechanism guided by intent features is added to the self-attention model, and the attention weight of the model is dynamically adjusted through the intent feature vector. This allows the model to more accurately capture the user's intention when rewriting questions, and pay more attention to context and intent-related information, thereby improving the accuracy and efficiency of question rewriting.
[0063] Specifically, after obtaining the pre-trained question rewriting model, the method also includes: obtaining changed data in the knowledge base, the changed data including newly added data, and / or modified data, and / or deleted data; and retraining the question rewriting model according to the changed data and the labels corresponding to the changed data.
[0064] Among them, the knowledge base data and user feedback are continuously monitored and iterated. With the continuous update of the knowledge base and the increase of user questions, new training data is continuously collected, and then screened, annotated, trained and deployed in turn. The specific steps are as follows: When the knowledge base changes, the training data related to these changes will be dynamically screened first, including the newly added intent samples, the modified intent descriptions, and the training data corresponding to the deleted or modified intents, so that the training data is synchronized with the knowledge base. Then the screened data is handed over to the annotators for incremental annotation. Specifically, for the newly added intents, the annotators add corresponding labels and descriptions to them; for the modified intents, they are re-annotated according to the new descriptions; for the deleted intents, the relevant data is removed from the training set, so that the training data has high timeliness and accuracy. Incremental training is performed based on the above-mentioned annotated dynamic data. Specifically, the updated training data is used to perform incremental training on the intent recognition model and the question rewriting model, and the model is adjusted for the changed parts, which reduces unnecessary waste of computing resources, enables the model to quickly adapt to the new knowledge base changes, and improves the recognition ability of new intents. After the incremental training is completed, the model is deployed and verified. When the performance of the incrementally trained model reaches the expected standard, it is redeployed into the system to replace the old model. Furthermore, after the model is deployed, the system will further verify the performance of the model through actual user interaction and collect feedback data for subsequent optimization iterations. At the same time, the performance indicators of the model are continuously monitored, such as the accuracy of intent recognition and the effect of question rewriting. Once performance degradation or poor user feedback is found, the model will enter the optimization and adjustment stage.
[0065] It can be seen that in this embodiment, by adding a dynamic attention mechanism guided by the intent feature vector to the question rewriting model, accurate guidance and optimization of question rewriting by intent features is achieved, thereby improving the matching between the rewritten question and the knowledge base, reducing the uncertainty in the question rewriting process, and providing users with more accurate and efficient dialogue services.
[0066] In a possible embodiment, before rewriting the first question to be rewritten and outputting the rewritten target question, the method further includes: obtaining a reference output result of the question rewriting model, the reference output result including a first output result, a second output result and a third output result, the first output result being used to indicate whether the first question to be rewritten needs to be rewritten, the second output result being used to indicate the intention label of the first question to be rewritten, and the third output result being used to indicate the rewriting result of the first question to be rewritten; obtaining an output result instruction, the output result instruction being used to indicate the output result required by the user in the reference output result; and outputting the rewritten target question including: outputting the target question when the output result instruction includes the third output result.
[0067] Among them, before the model outputs the results, it is necessary to set the output results of the tasks in the multi-tasks according to the user's needs. The output result of the question rewriting task is associated with the output result of the whether to rewrite task. If the output result of the whether to rewrite task is no need to rewrite, the output result of the question rewriting task is the original question, and there is no need to input the intention feature vector. If the output result of the whether to rewrite task is need to rewrite, the question rewriting task rewrites the question to be rewritten according to the intention feature vector, thereby outputting the target question.
[0068] Specifically, the intent matching tasks in the intent recognition model and the question rewriting model are different. The intent recognition model is an independent model that focuses on understanding and identifying the intent of user queries. It improves the model's ability to recognize user intent by training similar questions and intent labels in the knowledge base. The intent matching task is a combined part of the question rewriting model. It is jointly trained with other tasks in the question rewriting model through the concatenated sequence of historical dialogue context and current question and its corresponding intent labels. Through joint training, the question rewriting model can learn the relationship between different tasks and improve the performance of all tasks by sharing information between multiple related tasks. Furthermore, the intent matching task can help the question rewriting model understand the user's intent more accurately, thereby providing more fine-grained control in the question rewriting task.
[0069] Among them, see Figure 5 , Figure 5 is a flow chart of another question rewriting method provided in an embodiment of the present application. Figure 5As shown, the user's current round of questions and the context information of the historical rounds are input into the question rewriting model, and the current round of questions are input into the intention recognition model, and then the intention feature vector converted from the intention label output by the intention recognition model is received. The user's output result instruction is received. If the user chooses to output all, the result of whether to rewrite the task is output first. If the output does not need to be rewritten, the result can be directly output, that is, the first output result is no need to rewrite, the second output result is the intention label, and the third output result is the current round of questions; if the output needs to be rewritten, the intention feature vector is input into the question rewriting model, and the result is output through the context information and intention feature vector of the current round of questions and the historical rounds, that is, the first output result is required to be rewritten, the second output result is the intention label, and the third output result is the rewritten target question. Exemplarily, the context information of the historical round is: User: What is Anyingxiang? Customer service: Anyingxiang is a financial product. Questions in the current round: Current user question: How to buy financial products? That is, "What is Anyingxiang [sep] Anyingxiang is a financial product [sep] How do I buy financial products?" can be input into the question rewriting model, and "How do I buy financial products?" can be input into the intent recognition model. The intent recognition model outputs the intent label "How to buy financial products?", which is converted into an intent feature vector. Then, all the user's output instructions are received, and according to whether the output result of the rewriting task is that rewriting is required, the intent feature vector is input into the question rewriting model, thereby outputting the result: the intent matching task corresponds to "How to buy financial products?", the rewriting task corresponds to "Need to rewrite?", and the question rewriting task corresponds to "How to buy financial products?". Based on the rewritten question and intent label, the knowledge base searches for the purchase method of financial products in the knowledge base and feeds it back to the user.
[0070] It can be seen that in this embodiment, by extracting the intention feature vector, the core intention of the user's question can be identified, thereby focusing on the key information of the user's inquiry and improving the accuracy of question rewriting.
[0071] For the above embodiments, please refer to Figure 6 , Figure 6 is a block diagram of the functional units of a question rewriting device provided in an embodiment of the present application, such as Figure 6 As shown, the question rewriting device 60 includes: an acquisition unit 61, which is used to acquire the first question to be rewritten in the current question and answer data and the first historical dialogue data corresponding to the first question to be rewritten in a multi-round dialogue scenario; a determination unit 62, which is used to determine the intention feature vector according to the first question to be rewritten; and a rewriting unit 63, which is used to input the first question to be rewritten, the first historical dialogue data and the intention feature vector into a pre-trained question rewriting model, rewrite the first question to be rewritten, and output the rewritten target question.
[0072] In a possible embodiment, in terms of rewriting the first question to be rewritten and outputting the rewritten target question, the rewriting unit 63 is specifically used to: obtain a first sequence including multiple element vectors, the first sequence is determined according to the first question to be rewritten and the first historical dialogue data; determine a multi-channel feature vector for each element vector in the first sequence, and determine an attention bias matrix according to the intention feature vector, the attention bias matrix is used to adjust the attention of the multi-channel feature vector; determine an attention output result according to the multi-channel feature vector and the attention bias matrix; rewrite the first question to be rewritten according to the attention output result, and output the target question.
[0073] In a possible embodiment, in determining the multi-channel feature vector of each element vector in the first sequence, and determining the attention bias matrix based on the intention feature vector, the rewriting unit 63 is specifically used to: obtain the first feature vector, the second feature vector and the third feature vector based on the first weight matrix, the second weight matrix and the third weight matrix respectively, the element vector i is any element vector in the first sequence, and determine the attention bias matrix based on the intention feature vector and the fourth weight matrix, the first weight matrix, the second weight matrix, the third weight matrix and the fourth weight matrix are different learning parameter matrices.
[0074] In a possible embodiment, in terms of determining the attention output result based on the multi-channel eigenvector and the attention bias matrix, the rewriting unit 63 is specifically used to: determine a reference similarity between the first eigenvector and the second eigenvector; correct the reference similarity according to the attention bias matrix to obtain a target similarity; and determine the attention output result based on the target similarity and the third eigenvector.
[0075] In a possible embodiment, after inputting the first question to be rewritten, the first historical dialogue data and the intention feature vector into a pre-trained question rewriting model, the question rewriting device 60 is further specifically used to: obtain a training sample data set, the training sample data set includes training samples corresponding to multiple tasks, the multiple tasks include a whether to rewrite task, an intention matching task and a question rewriting task, each training sample includes a second question to be rewritten in the historical question and answer data and a second historical dialogue data corresponding to the second question to be rewritten, and a label corresponding to each of the multiple tasks; perform cyclic iterative training on the multi-task question rewriting model according to the training samples in the training sample data set, and obtain the pre-trained question rewriting model when the training is completed; wherein, the following operations are performed during one cyclic iterative training process: obtain Take training sample n, where training sample n is any group of training samples in the training sample data set; input the second question to be rewritten and the second historical dialogue data in the training sample n into the question rewriting model, and obtain the processing result corresponding to each task output by the question rewriting model; based on the processing result corresponding to each task and the label corresponding to each task in the training sample n, construct a loss function corresponding to each task; according to the loss function corresponding to task m, adjust the relevant parameters of task m in the question rewriting model, where task m is any task among the multiple tasks; obtain the weight corresponding to each task in the multiple tasks; determine the total loss function according to the weight corresponding to each task and the loss function corresponding to each task; and adjust the question rewriting model based on the total loss function.
[0076] In a possible embodiment, after obtaining the pre-trained question rewriting model, the question rewriting device 60 is further specifically used to: obtain changed data in the knowledge base, wherein the changed data includes newly added data, and / or modified data, and / or deleted data; and retrain the question rewriting model according to the changed data and the label corresponding to the changed data.
[0077] In a possible embodiment, before rewriting the first question to be rewritten and outputting the rewritten target question, the question rewriting device 60 is further specifically used to: obtain a reference output result of the question rewriting model, the reference output result includes a first output result, a second output result and a third output result, the first output result is used to indicate whether the first question to be rewritten needs to be rewritten, the second output result is used to indicate the intention label of the first question to be rewritten, and the third output result is used to indicate the rewriting result of the first question to be rewritten; obtain an output result instruction, the output result instruction is used to indicate the output result required by the user in the reference output result; the outputting the rewritten target question includes: when the output result instruction includes the third output result, outputting the target question.
[0078] It can be understood that since the method embodiment and the device embodiment are different presentation forms of the same technical concept, the content of the method embodiment part in this application should be synchronously adapted to the device embodiment part and will not be repeated here.
[0079] In the case of integrated units, see Figure 7 , Figure 7 is a block diagram of the functional units of another question rewriting device provided by an embodiment of the present application, such as Figure 7 As shown, the question rewriting device 60 includes: a processing module 602 and a communication module 601. The processing module 602 is used to control and manage the actions of the question rewriting device 60, for example, to execute the steps of the acquisition unit 61, the determination unit 62 and the rewriting unit 63, and / or to execute other processes of the technology described herein. The communication module 601 is used for the interaction between the question rewriting device 60 and other devices. Figure 7 As shown, the question rewriting device 60 may further include a storage module 603 , and the storage module 603 is used to store program codes and data of the question rewriting device 60 .
[0080] Wherein, the processing module 602 can be a processor or a controller, for example, a central processing unit (CPU), a general processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It can implement or execute various exemplary logic boxes, modules and circuits described in conjunction with the disclosure of this application. The processor can also be a combination that implements a computing function, for example, a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like. The communication module 601 can be a transceiver, an RF circuit or a communication interface, and the like. The storage module 603 can be a memory.
[0081] All relevant contents of each scenario involved in the above method embodiment can be referred to the functional description of the corresponding functional module, which will not be repeated here. Figure 1 The question rewriting method shown.
[0082] See also Figure 8 , Figure 8 is a schematic diagram of the structure of an electronic device proposed in an embodiment of the present application, such as Figure 8 As shown, the electronic device 80 includes a processor 810, a memory 820, a communication interface 830 and one or more programs 821. The one or more programs 821 are stored in the memory and are configured to be executed by the processor. When the program is executed, it includes part or all of the steps of any one of the cruising range estimation methods recorded in the above method embodiments. The processor, memory and communication interface are interconnected and complete communication with each other.
[0083] The memory may be a volatile memory such as a dynamic random access memory (DRAM), or a non-volatile memory such as a mechanical hard disk. The memory is used to store a set of executable program codes, and the processor is used to call the executable program codes stored in the memory, and may execute part or all of the steps of any energy data management method recorded in the above-mentioned question rewriting method embodiment.
[0084] It can be seen that the electronic device 80 described in the embodiment of the present application first obtains the first question to be rewritten in the current question and answer data and the first historical dialogue data corresponding to the first question to be rewritten in a multi-round dialogue scenario; determines the intention feature vector according to the first question to be rewritten; inputs the first question to be rewritten, the first historical dialogue data and the intention feature vector into a pre-trained question rewriting model, rewrites the first question to be rewritten, and outputs the rewritten target question. The present application adds the intention feature vector for the question to the question rewriting process, so that the intention granularity of the question is accurately identified during question rewriting, and the rewritten question matches the knowledge base, thereby improving the accuracy of question rewriting.
[0085] An embodiment of the present application also provides a computer storage medium, wherein the computer storage medium stores a computer program for electronic data exchange, wherein the computer program enables a computer to execute part or all of the steps of any method described in the above method embodiments, and the above computer includes an electronic device.
[0086] The embodiment of the present application also provides a computer program product, the computer program product includes a non-transitory computer-readable storage medium storing a computer program, the computer program is operable to cause a computer to execute some or all of the steps of any method described in the method embodiment. The computer program product may be a software installation package, and the computer includes an electronic device.
[0087] It should be noted that, for the sake of simplicity, the aforementioned method implementations are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the implementations described in the specification are all optional implementations, and the actions and modules involved are not necessarily required by the present application.
[0088] In the above-mentioned embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0089] In the several embodiments provided in this application, it should be understood that the disclosed device can be implemented in other ways. For example, the device implementation described above is only schematic, such as the division of the units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the device or unit can be electrical or other forms.
[0090] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0091] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of a software program module.
[0092] If the integrated unit is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a memory and includes several instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned memory includes: U disk, read-only memory (ROM), random access memory (RAM), mobile hard disk, disk or optical disk, etc., and other media that can store program codes.
[0093] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above-mentioned embodiments can be completed by instructing the relevant hardware through a program, and the program can be stored in a computer-readable memory, which can include: a flash drive, a read-only memory, a random access memory, a magnetic disk or an optical disk, etc.
[0094] The above is a detailed introduction to the implementation methods of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above implementation methods is only used to help understand the method and core idea of the present application. At the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A question rewriting method, characterized in that: include: In a multi-round dialogue scenario, obtaining a first question sentence to be rewritten in current question-and-answer data and first historical dialogue data corresponding to the first question sentence to be rewritten; Determine an intention feature vector according to the first question to be rewritten; The first question to be rewritten, the first historical dialogue data and the intention feature vector are input into a pre-trained question rewriting model, the first question to be rewritten is rewritten, and the rewritten target question is output.
2. The method according to claim 1, characterized in that The step of rewriting the first question sentence to be rewritten and outputting the rewritten target question sentence includes: Acquire a first sequence including a plurality of element vectors, wherein the first sequence is determined according to the first question sentence to be rewritten and the first historical dialogue data; Determine a multi-channel feature vector for each element vector in the first sequence, and determine an attention bias matrix according to the intention feature vector, wherein the attention bias matrix is used to adjust the attention of the multi-channel feature vector; Determining an attention output result according to the multi-channel feature vector and the attention bias matrix; The first question to be rewritten is rewritten according to the attention output result, and the target question is output.
3. The method according to claim 2, characterized in that The step of determining a multi-channel feature vector for each element vector in the first sequence, and determining an attention bias matrix according to the intention feature vector, comprises: The element vector i is respectively based on the first weight matrix, the second weight matrix and the third weight matrix to obtain the first eigenvector, the second eigenvector and the third eigenvector, the element vector i is any element vector in the first sequence, and the attention bias matrix is determined according to the intention feature vector and the fourth weight matrix, and the first weight matrix, the second weight matrix, the third weight matrix and the fourth weight matrix are different learning parameter matrices.
4. The method according to claim 3, characterized in that The determining the attention output result according to the multi-channel feature vector and the attention bias matrix includes: determining a reference similarity between the first feature vector and the second feature vector; Correcting the reference similarity according to the attention bias matrix to obtain a target similarity; An attention output result is determined according to the target similarity and the third eigenvector.
5. The method according to claim 1, characterized in that Before inputting the first question to be rewritten, the first historical dialogue data, and the intention feature vector into a pre-trained question rewriting model, the method further includes: Acquire a training sample data set, the training sample data set including training samples corresponding to a plurality of tasks, the plurality of tasks including a rewrite task, an intent matching task, and a question rewriting task, each training sample including a second question to be rewritten in the historical question-and-answer data and second historical dialogue data corresponding to the second question to be rewritten, and a label corresponding to each task in the plurality of tasks; According to the training samples in the training sample data set, the question rewriting models of multiple tasks are trained in a loop iterative manner, and when the training is completed, the pre-trained question rewriting model is obtained; wherein the following operations are performed during one loop iterative training process: Obtain training sample n, where the training sample n is any group of training samples in the training sample data set; Inputting the second question to be rewritten and the second historical dialogue data in the training sample n into the question rewriting model, and obtaining the processing result corresponding to each task output by the question rewriting model; Based on the processing result corresponding to each task and the label corresponding to each task in the training sample n, construct a loss function corresponding to each task; According to the loss function corresponding to task m, adjusting parameters related to the task m in the question rewriting model, wherein the task m is any one of the multiple tasks; Obtaining a weight corresponding to each of the multiple tasks; Determine a total loss function according to the weight corresponding to each task and the loss function corresponding to each task; The question rewriting model is adjusted based on the total loss function.
6. The method according to claim 5, characterized in that After obtaining the pre-trained question rewriting model, the method further includes: Acquire changed data in the knowledge base, wherein the changed data includes newly added data, and / or modified data, and / or deleted data; The question rewriting model is retrained according to the changed data and the label corresponding to the changed data.
7. The method according to claim 1, characterized in that Before rewriting the first question sentence to be rewritten and outputting the rewritten target question sentence, the method further includes: Obtaining a reference output result of the question rewriting model, the reference output result comprising a first output result, a second output result, and a third output result, the first output result being used to indicate whether the first question to be rewritten needs to be rewritten, the second output result being used to indicate an intention label of the first question to be rewritten, and the third output result being used to indicate a rewriting result of the first question to be rewritten; Obtaining an output result instruction, wherein the output result instruction is used to indicate an output result required by a user in the reference output result; The output rewritten target question sentence includes: When the output result instruction includes the third output result, the target question is output.
8. A question rewriting device, characterized in that: include: An acquisition unit, configured to acquire, in a multi-round dialogue scenario, a first question sentence to be rewritten in current question-and-answer data and first historical dialogue data corresponding to the first question sentence to be rewritten; A determining unit, configured to determine an intention feature vector according to the first question to be rewritten; The rewriting unit is used to input the first question to be rewritten, the first historical dialogue data and the intention feature vector into a pre-trained question rewriting model, rewrite the first question to be rewritten, and output the rewritten target question.
9. An electronic device, characterized in that: The method comprises a processor and a memory storing execution instructions, wherein the memory stores one or more programs; when the processor executes the execution instructions stored in the memory, the processor executes the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: An energy data management program is stored, including execution instructions. When a processor of an electronic device executes the execution instructions, the processor executes the method according to any one of claims 1-7.
Citation Information
Cited By
Training method, system, equipment and product for multi-round dialogue query rewriting task
CN120724162A
Generative question sentence rewriting method and device for improving multi-round dialogues
CN120850958A
