A question and answer processing method and device, electronic equipment and computer readable storage medium
By using a jointly trained neural network model to calculate the similarity and relevance between questions and answers, the problem of inaccurate answer matching in synonym problems is solved, and more efficient answer matching and output are achieved.
Patent Information
- Application Number
- CN202180000970.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-29
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2041-04-29
AI Technical Summary
Existing technologies cannot effectively handle synonym issues when searching for answers in knowledge bases, resulting in inaccurate answer matching.
A jointly trained neural network model is used to generate corresponding text vectors by calculating the similarity between the input question vector and the candidate question vector, and the correlation between the input question vector and the candidate answer vector. The model combines the BERT model and the LSTM model, calculates the matching degree using a formula, and outputs the candidate answer with a high matching degree.
It improves the accuracy of answer matching, reduces the number of model parameters, lowers computational complexity, simplifies the processing, and can provide users with the answers they need more quickly and accurately.
Smart Images

Figure CN115552393B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more particularly to a question-and-answer processing method, apparatus, electronic device, and computer-readable storage medium. Background Technology
[0002] Intelligent question answering refers to providing answers that match the user's questions by matching them with existing questions and answers. It can provide corresponding answers based on the user's questions and can be applied to various fields to reduce the need for human intervention and improve the convenience of users obtaining information. Summary of the Invention
[0003] This disclosure provides a question-and-answer processing method with some embodiments, including the following steps:
[0004] Obtain input question and candidate question-answer pairs, wherein the candidate question-answer pairs include candidate questions and candidate answers that match the candidate questions;
[0005] The input question is input into the first model to obtain the input question vector;
[0006] Calculate the similarity between the input question vector and the candidate question vector, and calculate the correlation between the input question vector and the candidate answer vector;
[0007] The degree of matching between the candidate answer and the input question is determined based on the similarity and the relevance.
[0008] In some implementations, calculating the similarity between the input question vector and the candidate question vector includes:
[0009] The similarity between the input question vector and the candidate question vector is calculated using Formula 1, where Formula 1 is:
[0010]
[0011] sim(vq, vq1) represents the similarity, where vq is the input question vector, vq1 is the candidate question vector, and vq... T ·vq1 is the dot product of the transpose of the input problem vector and the candidate problem vector, |vq| is the length of the input problem vector, and |vq1| is the length of the candidate problem vector.
[0012] In some implementations, calculating the correlation between the input question vector and the candidate answer vector includes:
[0013] The correlation between the input question vector and the candidate answer vector is calculated using Formula 2, where Formula 2 is:
[0014]
[0015] rel(vq, va) represents the relevance, where vq is the input question vector, va is the candidate answer vector, and vq... T ·va is the dot product of the transpose of the input question vector and the candidate answer vector, |vq| is the length of the input question vector, and |va| is the length of the candidate answer vector.
[0016] In some implementations, before calculating the similarity between the input question vector and the candidate question vector, and before calculating the relevance between the input question vector and the candidate answer vector, the method further includes:
[0017] The candidate questions are input into the second model to obtain a candidate question vector, and the candidate answers are input into the third model to obtain a candidate answer vector. The first, second, and third models are obtained through joint training.
[0018] In some implementations, after obtaining the input question and candidate question answer pairs, the process further includes:
[0019] The input question, the candidate question, and the candidate answer are respectively input into a shared language model to obtain text vectors corresponding to the input question, the candidate question, and the candidate answer, respectively.
[0020] The step of inputting the input question into the first model includes:
[0021] Input the text vector corresponding to the input question into the first model;
[0022] The step of inputting the candidate problem into the second model includes:
[0023] Input the text vector corresponding to the candidate question into the second model;
[0024] The step of inputting the candidate answer into the third model includes:
[0025] The text vectors corresponding to the candidate answers are input into the third model.
[0026] In some implementations, at least one of the first model, the second model, and the third model is a neural network model.
[0027] In some implementations, the shared language model is the BERT model.
[0028] In some embodiments, the method further includes:
[0029] The first model, the second model, and the third model are obtained through joint training.
[0030] The loss function for the joint training is:
[0031] loss=(y rel -rel(vq, va)) 2 +(y sim -sim(vq, vq1)) 2 ;
[0032] Where loss is the loss value, y rel For the preset relevance labels, y sim The preset similarity labels are rel(vq, va), which is the relevance between the input question vector and the candidate answer vector, and sim(vq, vq1), which is the similarity between the input question vector and the candidate question vector.
[0033] In some implementations, determining the matching degree between the candidate answer and the input question based on the similarity and the relevance includes:
[0034] The matching degree between the candidate answer and the input question is calculated using Formula 3, where Formula 3 is: score=λ×sim+(1-λ)×rel; score is the matching degree, sim is the similarity, rel is the relevance, and λ is a preset coefficient greater than 0 and less than 1.
[0035] In some implementations, after determining the matching degree between the candidate answer and the input question based on the similarity and the relevance, the method further includes:
[0036] Output candidate answers that match the input question to a degree greater than a preset matching threshold.
[0037] This disclosure provides a question-and-answer processing apparatus in some embodiments, including:
[0038] The acquisition module acquires input questions and candidate question-answer pairs, wherein the candidate question-answer pairs include candidate questions and candidate answers that match the candidate questions;
[0039] The input module is used to input the input question into a first model to obtain an input question vector, input the candidate question into a second model to obtain a candidate question vector, and input the candidate answer into a third model to obtain a candidate answer vector, wherein the first model, the second model, and the third model are obtained through joint training;
[0040] The calculation module is used to calculate the similarity between the input question vector and the candidate question vector, and to calculate the correlation between the input question vector and the candidate answer vector;
[0041] The matching degree determination module is used to determine the degree of matching between the candidate answer and the input question based on the similarity and the relevance.
[0042] Some embodiments of this disclosure provide an electronic device including a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the question-and-answer processing method as described in some aspects of this disclosure.
[0043] Some embodiments of this disclosure provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the question-and-answer processing method described in some aspects of this disclosure. Attached Figure Description
[0044] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings used in the description of the embodiments of this disclosure will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0045] Figure 1 This is a flowchart of a question-and-answer processing method in some embodiments of this disclosure;
[0046] Figure 2 This is an architecture diagram of the model in some embodiments of this disclosure;
[0047] Figure 3 This is the intention of sharing a language model in some embodiments of this disclosure;
[0048] Figure 4 This is a schematic diagram of the first model in some embodiments of this disclosure;
[0049] Figure 5 This is a schematic diagram illustrating an implementation scenario of the question-and-answer processing method in some embodiments of this disclosure;
[0050] Figure 6 This is a structural diagram of the question-and-answer processing apparatus in some embodiments of this disclosure. Detailed Implementation
[0051] The technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this disclosure. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0052] In related technologies, the best answer in a knowledge base is often found solely by the similarity between questions. However, this approach cannot solve the problem of synonyms. For example, a user's question is "What foods can diabetics eat?", while the knowledge base stores the question "Diet for diabetics". The word form similarity between "What foods to eat" and "Diet" is 0, but their semantic similarity is very high (i.e., the relevant answers for "Diet for diabetics" can answer the user's question "What foods can diabetics eat?").
[0053] This disclosure provides a question-and-answer processing method through several embodiments. The method can be executed by any electronic device, such as an application with question-and-answer functionality. The method can be executed by the application's server or a terminal device; optionally, the method can be executed by the server.
[0054] The technical solution in this embodiment is applied to intelligent question answering, that is, returning corresponding answers to user questions. Specifically, this technical solution can be applied to customer service, question answering of common diseases, etc.
[0055] For example, in this embodiment, the technical solution is applied to answering questions related to diabetes, so as to provide some opinions or suggestions to the consulter.
[0056] like Figure 1 As shown, in some embodiments, the question-and-answer processing method includes the following steps:
[0057] Step 101: Obtain the input question and candidate question answer pairs.
[0058] In some embodiments, the input question is a question that the user needs to ask and input. The candidate question-answer pair includes candidate questions and candidate answers that match them. This candidate question-answer pair can be, for example, a pre-established database containing questions and answers. For instance, the candidate question-answer pairs can be stored in the database, and when applied to different scenarios, candidate question-answer pairs matching the corresponding needs can be set. For example, the user can be any user, such as any registered user of the aforementioned application. For example, the input question can be obtained by receiving the user's input question through a terminal device.
[0059] For example, when used to answer questions related to diabetes, the database may include questions and professional answers to those questions from professionals such as doctors.
[0060] For example, the candidate question-answer pair could include the question "Diet for diabetics" and the corresponding answer "Dietary considerations for diabetics: Eat more high-fiber foods to promote the body's sugar metabolism, such as corn, cabbage...", or the question "Can type 1 diabetics use vinegar in cooking?" and the corresponding answer "Yes".
[0061] Step 102: Input the input problem into the first model to obtain the input problem vector.
[0062] In some embodiments, the input question is fed into a first model to obtain its corresponding input question vector.
[0063] In some embodiments, the method further includes: inputting the candidate question into a second model to obtain a candidate question vector, and inputting the candidate answer into a third model to obtain a candidate answer vector, wherein the first model, the second model, and the third model are obtained through joint training.
[0064] It can be understood that, in some embodiments, during the execution process, the input question, candidate questions, and candidate answers can be input into the first model, the second model, and the third model respectively in each execution process to obtain the corresponding input question vector, candidate question vector, and candidate answer vector respectively.
[0065] In other embodiments, candidate questions and candidate answers can be pre-input into the second and third models respectively to obtain corresponding candidate question vectors and candidate answer vectors, and these vectors can be saved. During execution, the input question is input into the first model, and the pre-saved candidate question vectors and candidate answer vectors are called to obtain the input question vector, candidate question vector, and candidate answer vector.
[0066] The steps to obtain the input question vector, candidate question vector, and candidate answer vector can be implemented through multiple models. That is, the first model, the second model, and the third model can be relatively independent models. Alternatively, the steps to obtain the input question vector, candidate question vector, and candidate answer vector can be implemented through a single model. It can be understood that the first model, the second model, and the third model are three components of a single overall model.
[0067] The parameters of the first, second, and third models are obtained through joint training. This means that all three models are trained together while their parameters are adjusted simultaneously. During parameter adjustment, the models are not independent but rather influence each other. For example, the three models can be of the same type, such as all three being deep neural network models, or they can be at least partially different types of models, such as the first model being a deep neural network model, the second a recurrent neural network model, and the third a convolutional neural network model. No further limitations are imposed here.
[0068] Since the three models are obtained through joint training, the similarity between the input question and the candidate questions, as well as the relevance between the input question and the candidate answers, are fully considered, which improves the accuracy of determining the candidate answers that match the input question. At the same time, by considering the relationship between similarity and relevance, the number of model parameters is reduced.
[0069] In some embodiments, the method further includes: inputting the input question, the candidate question, and the candidate answer into a shared language model to obtain text vectors corresponding to the input question, the candidate question, and the candidate answer, respectively.
[0070] In some embodiments, the text vector corresponding to the input question, the text vector corresponding to the candidate question, and the text vector corresponding to the candidate answer all have the same dimension.
[0071] In some embodiments, a shared language model is used to first convert the input content into text vectors, and then the corresponding input question vector, candidate question vector, and candidate answer vector are generated based on the converted text vectors.
[0072] In some embodiments, the text vectors corresponding to the input question, the candidate questions, and the candidate answers are all obtained by processing the same shared language model. Processing with the same shared language model can reduce the number of models and lower the complexity of the models.
[0073] In some embodiments, the text vector corresponding to the input question is input into the first model; and
[0074] Input the text vector corresponding to the candidate question into the second model; and
[0075] The text vectors corresponding to the candidate answers are input into the third model.
[0076] In some embodiments, the vectors output by the first model, the second model, and the third model all have the same dimension.
[0077] For example, the input question, candidate question, and candidate answer are first converted into corresponding text vectors with the same dimension using the same shared language model. Then, the text vectors are converted into input question vectors, candidate question vectors, and candidate answer vectors with the same dimension using the first model, the second model, and the third model, respectively.
[0078] Since the obtained text vectors are transformed through the same shared language model and have the same dimension, the number of model parameters can be effectively reduced. The input question vector, candidate question vector, and candidate answer vector have the same dimension, so they can be mapped to the same dimension vector space for calculation, which helps to improve the subsequent processing effect and reduce the complexity of the operation.
[0079] In this embodiment, the shared language model can be a language processing model such as Seq2Seq (one type of language model) or left-to-right (one type of language model), for example. Figure 2 As shown, in some embodiments, the shared language model can be the BERT (a language model). The BERT model has a better understanding of deep semantics and performs relatively well in processing short texts, thus enabling faster and more accurate extraction of text vectors.
[0080] In some embodiments, at least one of the first model, the second model, and the third model is a neural network model. The first model, the second model, and the third model can be selected from RNN (Recurrent Neural Network), GRU (Gated Recurrent Neural Network), LSTM (Long Short-Term Memory), etc. In some embodiments, the first model, the second model, and the third model can all be selected from LSTM models. For example, the first model can be referred to as LSTM1, the second model as LSTM2, and the third model as LSTM3.
[0081] LSTM models possess long-term memory capabilities and are relatively simple to implement, helping to reduce system load and modeling difficulty. The first, second, and third models can all use LSTM, enabling input and output vectors with the same feature vector specifications. Thus, when obtaining text vectors from each model using a shared language model, the processing is essentially the same. Furthermore, processing the output vectors of each model involves processing vectors with the same specifications, simplifying the process and further reducing the number of model parameters.
[0082] This example illustrates how to handle input issues. Figure 3As shown, in the process of converting the input question into a corresponding text vector using the BERT model, the marker symbol [CLS] required by the BERT model is first added to the beginning of the input question text. Then, the text containing the marker symbol [CLS] is converted into character vectors. Specifically, the converted character vectors include the prefix vector ECLS corresponding to the marker symbol [CLS], and the character vector Ei (i = 1, 2, 3, 4...n) corresponding to each character in the input question, where n is the total number of characters in the input question, and i represents the i-th character in the input question. The prefix vector ECLS and the character vector Ei are processed by the BERT model to generate a text vector V with a certain dimension. This text vector V serves as the input of the first model. The text vector V specifically includes the VCLS representing the entire text and the vector Vi (i = 1, 2, 3, 4...n) corresponding to each character.
[0083] It should be understood that the process of converting text into character vectors described above can be handled separately, or it can be done in a Bert-based model by adding a specific processing module to convert text into corresponding character vectors.
[0084] The process for processing candidate questions and candidate answers can refer to the above process, and will not be repeated here.
[0085] For example, in some embodiments, the vector dimension is 512, meaning each word is represented using a 512-dimensional vector. For instance, "Vi" represents the vector representation of "word i" formed by the BERT model, which has a dimension of 512.
[0086] Next, the obtained text vector V is used as the input to the LSTM model.
[0087] Let's take an input question as an example, such as... Figure 4 As shown, hi is the hidden state of the LSTM at the i-th word (e.g., when the text vector is a 512-dimensional vector, the vector dimension is 256). This hidden state hi is determined based on the vector Vi corresponding to the current i-th word and the hidden state hi-1 corresponding to the previous word, and can be denoted as: h i =LSTM(V i ,h i-1 ).
[0088] In some implementations, after determining the hidden state hn of the last character among the n characters in the input text, the input problem vector vq corresponding to the entire input problem is calculated. Since the vector Vi corresponding to the i characters and the hidden state hi-1 corresponding to the previous character are determined, the hidden state hn of the last character actually includes all the information of the input text, thereby avoiding omissions and improving the accuracy of calculating the input problem vector vq. Where vq = W1 × hn +b1, where W1 is the parameter matrix and b1 is the bias vector. For example, W1 is one of the parameters adjusted through the joint training process.
[0089] In some embodiments, when the vector representation formed by the Bert model is 512-dimensional, the dimension of vq is 128-dimensional.
[0090] The dimensions of the input text, hidden state, and the final vector can be the same or gradually decrease. Taking the processing of the input problem as an example, the input problem may contain a lot of information, including useful core information and some unimportant non-core information. Therefore, the dimension of the text vector of the input problem is relatively high.
[0091] During processing, the core information contained in the input question vector vq is extracted using a neural network model. Compared with text vectors, the input question vector vq, which only contains core information, contains relatively less information. Therefore, the input question vector can be represented by a low-dimensional vector, which helps to simplify the parameter processing and reduce the storage space occupied.
[0092] Similarly, the candidate question vector vq1 can be obtained through the second model, and the candidate answer vector va can be obtained through the third model.
[0093] In some embodiments, the candidate question vector vq1, the input question vector vq, and the candidate answer vector va are all vectors of the same dimension. For example, the candidate question vector vq1, the input question vector vq, and the candidate answer vector va are all column vectors.
[0094] Step 103: Calculate the similarity between the input question vector and the candidate question vector, and calculate the correlation between the input question vector and the candidate answer vector.
[0095] In some embodiments, step 103 includes:
[0096] The similarity between the input question vector and the candidate question vector is calculated using Formula 1, where Formula 1 is:
[0097]
[0098] sim(vq, vq1) represents the similarity, where vq is the input question vector, vq1 is the candidate question vector, and va T ·vq1 is the dot product of the transpose of the input problem vector and the candidate problem vector, |vq| is the length of the input problem vector, and |vq1| is the length of the candidate problem vector.
[0099] In some implementations, if vq and vq1 in the above formula are a row vector and a column vector respectively, the transpose step can be omitted, and the two can be directly multiplied by a dot product. If both are row vectors, or both are column vectors, one needs to be transposed before multiplying by the other. Generally, the vector format output by the model is a column vector, meaning that a transpose process is usually involved.
[0100] In some embodiments, step 103 further includes:
[0101] The correlation between the input question vector and the candidate answer vector is calculated using Formula 2, where Formula 2 is:
[0102]
[0103] rel(vq, va) represents the relevance, where vq is the input question vector, va is the candidate answer vector, and vq... T ·va is the dot product of the transpose of the input question vector and the candidate answer vector, |vq| is the length of the input question vector, and |va| is the length of the candidate answer vector.
[0104] In some implementations, if vq and va in the above formula are a row vector and a column vector respectively, the transpose step can be omitted, and the two can be directly multiplied by a dot product. If both are row vectors, or both are column vectors, one needs to be transposed before multiplying by the other. Generally, the vector format output by the model is a column vector, meaning that a transpose process is usually involved.
[0105] In some embodiments, the candidate question vector vq1, the input question vector vq, and the candidate answer vector va are all column vectors. Therefore, in the above formulas (1) and (2),
[0106] In some embodiments, the first model can be adjusted so that the input problem vector vq output by the first model is a row vector. In this case, the transpose vq of the input problem vector can be used in the above formula. T If we replace the input problem vector vq, the underlying calculation principle and results are the same as the process described above.
[0107] Step 104: Determine the degree of matching between the candidate answer and the input question based on the similarity and relevance.
[0108] In some embodiments, step 104 includes:
[0109] The matching degree between the candidate answer and the input question is calculated using Formula 3, where Formula 3 is: score=λ×sim+(1-λ)×rel; score is the matching degree, sim is the similarity, rel is the relevance, and λ is a preset coefficient greater than 0 and less than 1.
[0110] In the technical solution of this embodiment, Formula 3 considers the influence of the calculated similarity and relevance on the degree of matching between the candidate answer and the input question. By adjusting the size of the preset coefficient λ, the weight of similarity and relevance can be adjusted. The value of the preset coefficient λ can be set as needed. For example, it can be input into the preset system through the user interface, which can improve the accuracy of the calculation of the degree of matching between the candidate answer and the input question.
[0111] It may also include: outputting candidate answers that match the input question to a degree greater than a preset matching degree threshold.
[0112] In this embodiment, after inputting the matching degree between the question and each candidate answer, the matching degree can be further output as greater than a preset matching degree threshold, so that the user can understand the answer to the question.
[0113] In this embodiment, the matching degree threshold can be a score threshold. For example, the matching degree threshold is set to 90%. In this case, the output candidate answers have a matching degree greater than or equal to 90% with the input question. At this time, the output answer may be one or more.
[0114] The matching threshold can also be a ranking threshold. For example, if the matching threshold is set to the top 5, then after determining the matching degree between the candidate answers and the input question, the top five answers with the highest matching degree will be output to provide the user with multiple answers for reference.
[0115] For example, candidate answers matching the input question can be output through a human-computer interaction interface, or output through voice broadcasting or other means.
[0116] like Figure 5As shown, the technical solution of this embodiment can be summarized as follows: First, the user inputs the question they want to ask through the interaction module. Next, based on the matching candidate questions and answers pre-stored in the database, the similarity between the input question and the candidate questions, as well as the relevance between the input question and the candidate answers, are calculated to determine the degree of matching between the input question, candidate questions, and candidate answers. There is a certain correspondence and correlation between the candidate questions and candidate answers. Then, each candidate question and candidate answer is sorted according to its degree of matching with the input question, and the interaction module returns the candidate answer with the highest degree of matching or several sets of candidate answers with a high degree of matching to the user. In this way, the answer to the user's input question is completed.
[0117] In some embodiments, the method further includes the step of obtaining a first model, a second model, and a third model through joint training.
[0118] In some embodiments, the method further includes:
[0119] The first model, the second model, and the third model are obtained through joint training.
[0120] In some implementations, the first model is a neural network model that takes the text vector of the input question as input and the input question vector corresponding to the input question as output.
[0121] The second model is a neural network model that takes the text vector of the candidate question as input and the candidate question vector corresponding to the candidate question as output.
[0122] The third model is a neural network model that takes the text vector of the candidate answer as input and the candidate answer vector corresponding to the candidate answer as output.
[0123] The loss function for joint training is:
[0124] loss=(y rel -rel(vq, va)) 2 +(y sim -sim(vq, vq1)) 2 ;
[0125] Where loss is the loss value, y rel For the preset relevance labels, y sim The preset similarity labels are rel(vq, va), which is the relevance between the input question vector and the candidate answer vector, and sim(vq, vq1), which is the similarity between the input question vector and the candidate question vector.
[0126] In some embodiments, the first model, the second model, and the third model can all be LSTM models. Obviously, other models can also be selected.
[0127] Generally, the architecture of an LSTM model can be understood as including input nodes, input gates, internal state nodes, forget gates, and output gates. The input node receives the output of the hidden node from the previous time step and the current input as input, then passes it through a tanh activation function. The input gate controls the input information; its input is the output of the hidden node from the previous time step and the current input, with a sigmoid activation function. The internal state node receives the current input filtered by the input gate and the output of the internal state node from the previous time step. The forget gate controls the internal state information; its input is the output of the hidden node from the previous time step and the current input, with a sigmoid activation function. The output gate (oc) controls the output information; its input is the output of the hidden node from the previous time step and the current input, with a sigmoid activation function.
[0128] During LSTM model training, the main focus is on updating the weight coefficients, which include input weights, output weights, and internal states. Input weights are used to weight the input at the current time step, output weights are used to weight the output at the previous step, and internal states refer to the internal states used in the output calculation at this time step.
[0129] By adjusting the weight coefficients based on the value of the loss function, under certain training conditions, such as reaching a certain number of iterations or when the loss function converges, the first, second, and third models can be obtained after training.
[0130] During training, pre-labeled training data is provided first. This data includes the input question, candidate questions, and candidate answers matching the candidate questions. The similarity between the input question and candidate questions includes at least three cases: dissimilar, partially similar, and very similar. Correspondingly, similarity labels with different values are provided; for example, they can be set to y. sim =1 indicates that the input problem and the candidate problem are very similar, y sim =0.5 indicates that the input problem and the candidate problem are partially similar, y sim =0 indicates that the input question and the candidate question are not similar. Obviously, the above similarity level and similarity label values are only exemplary settings in this embodiment. In practice, other formats of levels and corresponding similarity labels can be set as needed.
[0131] Similarly, the relevance level and relevance label values can be set according to the relevance between the input question and the candidate answers. In this embodiment, the exemplary relevance level is set to y. rel=1 indicates that the input question and the candidate answers are highly relevant, y rel =0.5 indicates that the input question is partially related to the candidate answers, y rel =0 means that the input question is not related to the candidate answer.
[0132] For example, the first model, the second model, and the third model can be jointly trained according to the loss function set above. For example, the parameters can be learned by minimizing the loss function through backpropagation and stochastic gradient descent. When certain training conditions are met (e.g., when the loss function converges or when a certain number of iterations are met), the first model, the second model, and the third model that meet the usage requirements can be obtained.
[0133] Through joint training, the parameter values of the above models are obtained. The first, second, and third models share the underlying network. For example, by using a shared neural network to capture the relationship between similarity and relevance, the number of model parameters is reduced, the complexity of the model is decreased, and the accuracy of the output results can be improved.
[0134] Some embodiments of this disclosure also provide a question-and-answer processing apparatus.
[0135] like Figure 6 As shown, in one embodiment, the question-and-answer processing device 600 includes:
[0136] The acquisition module 601 acquires input questions and candidate question-answer pairs, wherein the candidate question-answer pairs include candidate questions and candidate answers that match the candidate questions;
[0137] Input module 602 is used to input the input problem into the first model;
[0138] The calculation module 603 is used to calculate the similarity between the input question vector and the candidate question vector, and to calculate the correlation between the input question vector and the candidate answer vector;
[0139] The matching degree determination module 604 is used to determine the degree of matching between the candidate answer and the input question based on the similarity and the relevance.
[0140] In some embodiments, the computing module 603 is specifically used for:
[0141] The similarity between the input question vector and the candidate question vector is calculated using Formula 1, where Formula 1 is:
[0142]
[0143] sim(vq, vq1) represents the similarity, where vq is the input question vector, vq1 is the candidate question vector, and vq... T·vq1 is the dot product of the transpose of the input problem vector and the candidate problem vector, |vq| is the length of the input problem vector, and |vq1| is the length of the candidate problem vector.
[0144] In some embodiments, the computing module 603 is specifically used for:
[0145] The correlation between the input question vector and the candidate answer vector is calculated using Formula 2, where Formula 2 is:
[0146]
[0147] rel(vq, va) represents the relevance, where vq is the input question vector, va is the candidate answer vector, and vq... T ·va is the dot product of the transpose of the input question vector and the candidate answer vector, |vq| is the length of the input question vector, and |va| is the length of the candidate answer vector.
[0148] In some embodiments, the input module 602 is further configured to input the candidate question into a second model to obtain a candidate question vector, and input the candidate answer into a third model to obtain a candidate answer vector, wherein the first model, the second model, and the third model are obtained through joint training.
[0149] In some embodiments, it also includes:
[0150] The vector input module is used to input the input question, the candidate question, and the candidate answer into the shared language model respectively, and obtain the text vectors corresponding to the input question, the candidate question, and the candidate answer respectively;
[0151] The input module 602 is specifically used to input the text vector corresponding to the input question into the first model; and
[0152] Used to input the text vector corresponding to the candidate question into the second model; and
[0153] The text vectors corresponding to the candidate answers are input into the third model.
[0154] In some embodiments, at least one of the first model, the second model, and the third model is a neural network model.
[0155] In some embodiments, the shared language model is the BERT model.
[0156] In some embodiments, it also includes:
[0157] The training module is used to obtain the first model, the second model, and the third model through joint training;
[0158] The loss function for the joint training is:
[0159] loss=(y rel -rel(vq, va)) 2 +(y sim -sim(vq, vq1)) 2 ;
[0160] Where loss is the loss value, y rel For the preset relevance labels, y sim The preset similarity labels are rel(vq, va), which is the relevance between the input question vector and the candidate answer vector, and sim(vq, vq1), which is the similarity between the input question vector and the candidate question vector.
[0161] In some embodiments, the matching degree determination module 604 is specifically used to calculate the matching degree between the candidate answer and the input question using formula 3, wherein formula 3 is: score=λ×sim+(1-λ)×rel; score is the matching degree, sim is the similarity, rel is the relevance, and λ is a preset coefficient greater than 0 and less than 1.
[0162] In some embodiments, an output module is also included, which is used to output candidate answers that match the input question to a degree greater than a preset matching degree threshold.
[0163] This disclosure also provides an electronic device, including a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, it implements the various processes of the above-described question-and-answer processing method embodiments and achieves the same technical effects, which will not be repeated here.
[0164] This disclosure also provides a computer-readable storage medium storing a computer program. When executed by a processor, the computer program implements the various processes of the above-described question-and-answer processing method embodiments and achieves the same technical effects, which will not be elaborated further here. The computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.
[0165] Those skilled in the art will recognize that the modules, units, and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this disclosure.
[0166] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0167] It should be understood that although the steps in the flowcharts of the accompanying figures are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the accompanying figures may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0168] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods 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 apparatuses or units may be electrical, mechanical, or other forms.
[0169] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments of this disclosure, depending on actual needs.
[0170] In addition, the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0171] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.
[0172] The above description is merely a specific embodiment of this disclosure, but the scope of protection of this disclosure is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this disclosure should be included within the scope of protection of this disclosure. Therefore, the scope of protection of this disclosure should be determined by the scope of the claims.
Claims
1. A question-and-answer processing method, comprising the following steps: Obtain input question and candidate question-answer pairs, wherein the candidate question-answer pairs include candidate questions and candidate answers that match the candidate questions; The input question is input into the first model to obtain the input question vector; Calculate the similarity between the input question vector and the candidate question vector, and calculate the correlation between the input question vector and the candidate answer vector, wherein the candidate question vector is the vector corresponding to the candidate question, and the candidate answer vector is the vector corresponding to the candidate answer; The degree of matching between the candidate answer and the input question is determined based on the similarity and the relevance. The question-and-answer processing method further includes: The candidate questions are input into the second model to obtain a candidate question vector, and the candidate answers are input into the third model to obtain a candidate answer vector. The first, second, and third models are obtained through joint training. The method further includes: The first model, the second model, and the third model are obtained through joint training. The loss function for the joint training is: loss=(y rel -rel(vq,va)) 2 +(y sim -sim(vq,vq1)) 2 ; Where loss is the loss value, y rel For the preset relevance labels, y sim The preset similarity labels are rel(vq, va), which is the relevance between the input question vector and the candidate answer vector, and sim(vq, vq1), which is the similarity between the input question vector and the candidate question vector.
2. The method according to claim 1, wherein, The calculation of the similarity between the input question vector and the candidate question vector includes: The similarity between the input question vector and the candidate question vector is calculated using Formula 1, where Formula 1 is: sim(vq, vq1) represents the similarity, where vq is the input question vector, vq1 is the candidate question vector, and vq... T ·vq1 is the dot product of the transpose of the input problem vector and the candidate problem vector, |vq| is the length of the input problem vector, and |vq1| is the length of the candidate problem vector.
3. The method according to claim 1, wherein, The calculation of the correlation between the input question vector and the candidate answer vector includes: The correlation between the input question vector and the candidate answer vector is calculated using Formula 2, where Formula 2 is: rel(vq, va) represents the relevance, where vq is the input question vector, va is the candidate answer vector, and vq... T ·va is the dot product of the transpose of the input question vector and the candidate answer vector, |vq| is the length of the input question vector, and |va| is the length of the candidate answer vector.
4. The method according to claim 1, wherein, After obtaining the input question and candidate question answer pairs, the process also includes: The input question, the candidate question, and the candidate answer are respectively input into a shared language model to obtain text vectors corresponding to the input question, the candidate question, and the candidate answer, respectively. The step of inputting the input question into the first model includes: Input the text vector corresponding to the input question into the first model; The step of inputting the candidate problem into the second model includes: Input the text vector corresponding to the candidate question into the second model; The step of inputting the candidate answer into the third model includes: The text vectors corresponding to the candidate answers are input into the third model.
5. The method according to claim 1, wherein, At least one of the first model, the second model, and the third model is a neural network model.
6. The method according to claim 4, wherein, The shared language model is the BERT model.
7. The method according to claim 1, wherein, Determining the matching degree between the candidate answer and the input question based on the similarity and the relevance includes: The matching degree between the candidate answer and the input question is calculated using Formula 3, where Formula 3 is: score=λ×sim+(1-λ)×rel; score is the matching degree, sim is the similarity, rel is the relevance, and λ is a preset coefficient greater than 0 and less than 1.
8. The method according to claim 1, wherein, After determining the matching degree between the candidate answer and the input question based on the similarity and the relevance, the method further includes: Output candidate answers that match the input question to a degree greater than a preset matching threshold.
9. A question-and-answer processing device, comprising: The acquisition module acquires input questions and candidate question-answer pairs, wherein the candidate question-answer pairs include candidate questions and candidate answers that match the candidate questions; The input module is used to input the input question into a first model to obtain an input question vector, input the candidate question into a second model to obtain a candidate question vector, and input the candidate answer into a third model to obtain a candidate answer vector, wherein the first model, the second model, and the third model are obtained through joint training; The calculation module is used to calculate the similarity between the input question vector and the candidate question vector, and to calculate the correlation between the input question vector and the candidate answer vector; A matching degree determination module is used to determine the degree of matching between the candidate answer and the input question based on the similarity and the relevance. The input module is further configured to input the candidate question into the second model to obtain a candidate question vector, and input the candidate answer into the third model to obtain a candidate answer vector, wherein the first model, the second model, and the third model are obtained through joint training; It also includes: a training module for obtaining the first model, the second model, and the third model through joint training; The loss function for the joint training is: loss=(y rel -rel(vq,va)) 2 +(y sim -sim(vq,vq1)) 2 ; Where loss is the loss value, y rel For the preset relevance labels, y sim The preset similarity labels are rel(vq, va), which is the relevance between the input question vector and the candidate answer vector, and sim(vq, vq1), which is the similarity between the input question vector and the candidate question vector.
10. An electronic device comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the question-and-answer processing method as described in any one of claims 1 to 8.
11. A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the question-and-answer processing method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Method and device for semantic matching of question and answer texts
CN108920654A