Question and Answer Method, Device, Electronic Device and Storage Medium
By introducing knowledge graph coding and feature matching in the question-and-answer method, the problems of inaccurate answers and insufficient adaptability in the existing question-and-answer methods are solved, and higher answer accuracy and adaptability to complex questions are achieved.
Patent Information
- Application Number
- CN202111598824.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-24
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2041-12-24
AI Technical Summary
Among the existing question-and-answer methods, the retrieval response is inaccurate and the generative question-and-answer method is low in adaptability to complex questions, resulting in insufficient answer accuracy.
The current alternative reply set is encoded using a knowledge graph, combined with the encoding characteristics of the current user input and historical question and answer information, and the matching information is determined through feature matching, and the answer is iteratively adjusted to improve accuracy.
Improves the accuracy and adaptability of answers, ensures the relevance of answers to user input, simplifies the answer determination process and reduces dependence on the dataset.
Smart Images

Figure CN114265925B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of text processing, and in particular, to a question-answering method, device, electronic device, and storage medium. Background Art
[0002] Currently, the automated query of information has gradually replaced the manual query method. The process of automated query of information can be understood as a question-answering process, that is, the process of answering questions raised by users.
[0003] With the development of artificial intelligence, question-answering methods can be divided into two types according to the main application technologies: retrieval-based and generative. Through the retrieval-based question-answering method, a fluent reply can be obtained, but the disadvantage is that the retrieved reply may not be relevant to the topic, resulting in inaccurate replies. Through the generative question-answering method, a brand-new reply can be generated, but the disadvantage is that it is greatly affected by the dataset, has low adaptability to complex questions, and the accuracy of the reply needs to be improved.
[0004] Therefore, there is an urgent need to provide a question-answering method. Summary of the Invention
[0005] The present invention provides a question-answering method, device, electronic device, and storage medium to solve the defects existing in the prior art.
[0006] The present invention provides a question-answering method, including:
[0007] Receiving the current user input and determining the current alternative reply set corresponding to the current user input;
[0008] Encoding the current alternative reply set based on the knowledge graph to obtain a set encoding feature;
[0009] Based on the encoding feature corresponding to the current user input, the encoding feature corresponding to the historical question-answering information, and the set encoding feature, determining the matching information between the current user input and the current alternative reply set and the historical question-answering information;
[0010] Based on the matching information and the current alternative reply set, determining the answer corresponding to the initial user input
[0011] According to the question-answering method provided by the present invention, the matching information includes a matching result, the matching result includes matching success or matching failure, and the matching information further includes a rhetorical question sentence when the matching fails;
[0012] Correspondingly, the determining the answer corresponding to the initial user input based on the matching information and the current alternative reply set includes:
[0013] If the matching result is a successful match, determine the current alternative response set as the answer;
[0014] If the matching result is a failed match, receive the response information of the user for the rhetorical question sentence, and use the response information as the current user input, and continue to determine the matching information until the matching information is a successful match.
[0015] According to a question-and-answer method provided by the present invention, the determining the matching information of the current user input with the current alternative response set and the historical question-and-answer information based on the coding feature corresponding to the current user input, the coding feature corresponding to the historical question-and-answer information, and the set coding feature includes:
[0016] Perform feature matching on the coding feature corresponding to the current user input with the coding feature corresponding to the historical question-and-answer information and the set coding feature respectively, to obtain the first matching feature and the second matching feature of the current user input;
[0017] Based on the first matching feature and the second matching feature, determine the matching information.
[0018] According to a question-and-answer method provided by the present invention, the determining the matching information based on the first matching feature and the second matching feature includes:
[0019] Based on the first matching feature and the second matching feature, use a classification function to determine the score that the first matching feature and the second matching feature belong to the same category;
[0020] Based on the score, determine the matching information.
[0021] According to a question-and-answer method provided by the present invention, the encoding the current alternative response set based on the knowledge graph to obtain the set coding feature includes:
[0022] Determine the graph information in the knowledge graph corresponding to the current alternative response set;
[0023] Encode the graph information to obtain the set coding feature.
[0024] According to a question-and-answer method provided by the present invention, the determining the current alternative response set corresponding to the current user input includes:
[0025] Based on the current user input, screen the previous alternative response set corresponding to the previous user input of the current user input to obtain the current alternative response set;
[0026] Among them, the initial alternative response set corresponding to the initial user input is determined based on the answers in the Q&A database that match the initial user input.
[0027] According to a Q&A method provided by the present invention, the field to which the initial user input belongs includes the construction field. The Q&A database stores the correspondence between question templates and answers, and the answers in the Q&A database are building codes.
[0028] The present invention also provides a Q&A device, including:
[0029] A receiving module, configured to receive the current user input and determine the current alternative response set corresponding to the current user input;
[0030] An encoding module, configured to encode the current alternative response set based on the knowledge graph to obtain a set encoding feature;
[0031] A matching module, configured to determine the matching information between the current user input, the current alternative response set, and the historical Q&A information based on the encoding feature corresponding to the current user input, the encoding feature corresponding to the historical Q&A information, and the set encoding feature;
[0032] A reply module, configured to determine the answer corresponding to the initial user input based on the matching information and the current alternative response set.
[0033] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the steps of the Q&A method as described in any one of the above are implemented.
[0034] The present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the Q&A method as described in any one of the above are implemented.
[0035] The present invention also provides a computer program product, including a computer program. When the computer program is executed by a processor, the steps of the Q&A method as described in any one of the above are implemented.
[0036] The question-answering method, device, electronic device, and storage medium provided by the present invention first receive the input of the current user and determine the current alternative response set corresponding to the current user input; then, based on the knowledge graph, encode the current alternative response set to obtain set encoding features; secondly, based on the encoding features corresponding to the current user input, the encoding features corresponding to the historical question-answering information, and the set encoding features, determine the matching information between the current user input and the current alternative response set and the question-answering information; finally, based on the matching information and the current alternative response set, determine the answer corresponding to the initial user input. Due to the introduction of the knowledge graph, the set encoding features obtained can carry structural relationship information, ensuring the relevance between the answer and the initial user input and improving the accuracy of the answer. Since the matching information between the current user input and the current alternative response set and the historical question-answering information is considered, the answer can be further approximated to the current user input, greatly improving the accuracy of the answer used to reply to the user. In addition, this method is not affected by the data set and has strong adaptability to complex initial user inputs. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] To more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings described below can be used by those of ordinary skill in the art to obtain other drawings without creative efforts.
[0038] Figure 1 is a flowchart of the question-answering method provided by the present invention;
[0039] Figure 2 is a structural diagram of the rhetorical question generation model involved in the question-answering method provided by the present invention;
[0040] Figure 3 is a structural diagram of the question-answering device provided by the present invention;
[0041] Figure 4 is a structural diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0042] To make the objectives, technical solutions, and advantages of the present invention clearer, the following will clearly and completely describe the technical solutions in the present invention with reference to the drawings in the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art without creative efforts based on the embodiments in the present invention belong to the scope of protection of the present invention.
[0043] Since the accuracy of the answers obtained by existing question-and-answer methods is relatively low, it is difficult to meet the needs of users. Therefore, an embodiment of the present invention provides a question-and-answer method.
[0044] Figure 1 It is a schematic flowchart of a question-and-answer method provided in an embodiment of the present invention. As Figure 1 shown, the method includes:
[0045] S1. Receive the current user input and the current alternative response set corresponding to the current user input;
[0046] S2. Based on the knowledge graph, encode the current alternative response set to obtain a set encoding feature;
[0047] S3. Based on the encoding feature corresponding to the current user input, the encoding feature corresponding to the historical question-and-answer information, and the set encoding feature, determine the matching information between the current user input, the current alternative response set, and the historical question-and-answer information;
[0048] S4. Based on the matching information and the current alternative response set, determine the answer corresponding to the initial user input.
[0049] Specifically, for the question-and-answer method provided in an embodiment of the present invention, the execution entity is a question-and-answer device, which can be configured in a server. The server can be a local server or a cloud server. The local server can specifically be a computer, a tablet computer, a smart phone, etc., and the present invention does not make specific limitations thereto. This question-and-answer method can involve single-round question-and-answer or multi-round question-and-answer, depending on the matching situation between the user's question and the alternative response set, and no specific limitations are made here.
[0050] Execute step S1 to receive the current user input, and the current user input corresponds to the current question-and-answer round. In an embodiment of the present invention, it can be considered that each user input corresponds to a question-and-answer round, that is, each question-and-answer round has a user input. When the question-and-answer method involves single-round question-and-answer, the current user input is the initial user input, that is, the user's question. When the question-and-answer method involves multi-round question-and-answer, the current question-and-answer round corresponding to the current user input can be any question-and-answer round in the multi-round question-and-answer, for example, it can be the initial question-and-answer round or a non-initial question-and-answer round. Correspondingly, the current user input can be the initial user input, that is, the user's question, or the current user input can also be a non-initial user input, that is, the reply information made by the user in response to the rhetorical statement generated in the previous question-and-answer round.
[0051] It can be understood that, for the convenience of subsequent processing, it is necessary to ensure that the current user input is in text form. If the current user input is in voice form, it needs to be transcribed into text.
[0052] In addition, in step S1, a current alternative response set corresponding to the current user input can also be determined. The current alternative response set includes one or more alternative responses, and the current user input matches each alternative response in the current alternative response set.
[0053] The current alternative response set can be obtained by querying relevant data with the current user input. During the process of determining the current alternative response set, to reduce the amount of data processing, the field to which the current user input belongs can be determined first, and then the current alternative response set can be obtained by querying the relevant data in the field to which the current user input belongs.
[0054] In particular, if the current user input is an abbreviation, that is, associated with the rhetorical question sentence generated in the previous Q&A round, then based on the current user input, it is necessary to combine with the previous alternative response set obtained in the previous Q&A round to jointly determine the current alternative response set.
[0055] Execute step S2 to encode the current alternative response set based on the knowledge graph to obtain a set encoding feature. Here, the knowledge graph may include multiple graph nodes and the connection lines between the graph nodes. Each graph node can represent an element, and the connection lines between the graph nodes can represent the relationships between the elements. Among them, the elements involved in the embodiments of the present invention may include entities, attributes, relationships, operations, and attribute values, etc., which are not specifically limited here.
[0056] To reduce the calculation amount, the knowledge graph can be the knowledge graph of the field to which the initial user input belongs. Taking the field as the construction field as an example, the knowledge graph can be used to represent the elements included in each building specification in the construction field and the relationships between the elements. Each graph node can be the elements included in each building specification in the construction field, and the connection lines between the graph nodes can represent the relationships between the elements.
[0057] Since the knowledge graph can represent the relationships between the elements, the process of encoding the alternative response set in combination with the knowledge graph can be regarded as making the set encoding feature obtained by encoding not only include element information but also include relationship structure information between the elements. The implementation method can be to first determine the graph information corresponding to the alternative response set in the knowledge graph, and then the set encoding feature can be obtained through the graph information.
[0058] It can be understood that since the knowledge graph is based on elements as units, the set encoding feature obtained by encoding the alternative response set is usually a word-level encoding sequence.
[0059] It can be understood that the execution processes of the action of receiving the current user input in step S1 and the action of encoding the alternative response set in step S2 are independent of each other, and their execution order can be set as needed, which is not specifically limited here.
[0060] Then, step S3 is executed to determine the matching information between the current user input, the current alternative response set, and the historical Q&A information based on the encoding features corresponding to the current user input, the encoding features corresponding to the historical Q&A information, and the set encoding features.
[0061] Here, the encoding features corresponding to the current user input can be semantic encoding features. First, the current user input can be processed by word-embedding, that is, each word in the current user input is represented by a word vector based on the Bag of Words (BOW), and a word vector is obtained. This word vector can be represented by a One-Hot vector, which is not specifically limited here. Then, the current user input can be represented by a sequence of word vectors.
[0062] Then, the sequence of word vectors of the current user input is encoded by a Gate Recurrent Unit (GRU). After encoding, the sequence of word vectors of the current user input can obtain two sequences, namely the word-level embedding sequence and the segment-level embedding sequence. The above two encoding sequences are the encoding features corresponding to the current user input.
[0063] The historical Q&A information can refer to the summary of the Q&A information of each Q&A round before the current Q&A round, which can be understood as the context interaction information (utterance). By using the above method for determining the encoding features corresponding to the current user input, the encoding features corresponding to the historical Q&A information can be determined, and the encoding features can also include the word-level encoding sequence and the segment-level encoding sequence.
[0064] Combining the encoding features corresponding to the current user input, the encoding features corresponding to the historical Q&A information, and the set encoding features, the matching information between the current user input, the alternative response set, and the historical Q&A information is determined. The matching information can be the matching information among the current user input, the alternative response set, and the historical Q&A information. The matching information can be determined by the matching results obtained by feature matching between the encoding features corresponding to the current user input and the encoding features corresponding to the historical Q&A information, and feature matching between the encoding features corresponding to the current user input and the set encoding features. Among them, the process of feature matching can be realized by multiplying the corresponding sequences, which is not specifically limited here.
[0065] The matching information may include a matching result, which may include two cases: matching success and matching failure. If the matching result is matching failure, the matching information further includes a rhetorical question statement corresponding to the matching failure. This rhetorical question statement can be provided to the user so that the user can reply to this rhetorical question statement.
[0066] Finally, step S4 is executed. By combining the matching information and the current alternative reply set, the answer corresponding to the initial user input can be determined, and this answer can be provided to the user. Here, different methods can be used to determine the above answer according to different matching results in the matching information. For example, when the matching result in the matching information is matching success, the answer corresponding to the initial user input can be directly determined according to the current alternative reply set. When the matching result in the matching information is matching failure, it is necessary to further combine the reply information of the user to the rhetorical question statement when the matching fails and the current alternative reply set to determine the answer corresponding to the initial user input. At this time, it can be an iterative execution process, and the end flag of the iterative execution can be that the matching result in the matching information is matching success.
[0067] In the question-and-answer method provided in the embodiments of the present invention, first, the current user input is received, and the current alternative reply set corresponding to the current user input is determined; then, based on the knowledge graph, the current alternative reply set is encoded to obtain a set encoding feature; secondly, based on the encoding feature corresponding to the current user input, the encoding feature corresponding to the historical question-and-answer information, and the set encoding feature, the matching information of the current user input with the current alternative reply set and the question-and-answer information is determined; finally, based on the matching information and the current alternative reply set, the answer corresponding to the initial user input is determined. Due to the introduction of the knowledge graph, the obtained set encoding feature can carry structural relationship information, ensuring the relevance between the answer and the initial user input, and improving the accuracy of the answer. Since the matching information of the current user input with the current alternative reply set and the historical question-and-answer information is considered, the answer can be further closer to the current user input, greatly improving the accuracy of the answer used to reply to the user. In addition, this method is not affected by the data set and has strong adaptability to complex initial user inputs.
[0068] Based on the above embodiments, in the question-and-answer method provided in the embodiments of the present invention, the matching information includes a matching result, the matching result includes matching success or matching failure, and the matching information further includes the rhetorical question statement when the matching fails;
[0069] Correspondingly, based on the matching information and the current alternative reply set, determining the answer corresponding to the initial user input includes:
[0070] If the matching result is matching success, determine the current alternative reply set as the answer;
[0071] If the matching result is a failure, receive the response information from the user for the rhetorical question statement, and use the response information as the current user input, and continue to determine the matching information until the matching information is a success.
[0072] Specifically, since the matching result in the matching information can include a success or a failure, further the matching information also includes the rhetorical question statement when the matching fails. On this basis, when determining the answer corresponding to the initial user input according to the matching information and the current alternative response set, if the matching result is a success, it means that all the alternative responses in the current alternative response set match the initial user input, so the current alternative response set can be directly determined as the answer, that is, each alternative response in the current alternative response set can be provided to the user as the answer.
[0073] If the matching result is a failure, it means that only some or none of the alternative responses in the current alternative response set match the initial user input. Therefore, it is necessary to receive the response information from the user for the rhetorical question statement, and use the response information as the current user input, and iteratively execute the above steps S1 - S3 to continue to determine the matching information until the matching information is a success.
[0074] In the embodiment of the present invention, when the matching is successful, directly using the current alternative response set as the answer can simplify the answer determination process, shorten the answer determination duration, and quickly answer the user's question. When the matching fails, further determine the response information from the user for the rhetorical question statement, iteratively determine the above matching information until the matching is successful, and determine the corresponding current alternative response set at this time as the answer. Adopting a multi - round question - answering method to obtain the response information from the user as auxiliary information to determine the answer can improve the accuracy of the answer.
[0075] Based on the above - mentioned embodiment, in the question - answering method provided in the embodiment of the present invention, determining the matching information between the current user input and the current alternative response set and the historical question - answering information based on the coding feature corresponding to the current user input, the coding feature corresponding to the historical question - answering information, and the set coding feature includes:
[0076] Perform feature matching on the coding feature corresponding to the current user input with the coding feature corresponding to the historical question - answering information and the set coding feature respectively, to obtain the first matching feature and the second matching feature of the current user input;
[0077] Determine the matching information based on the first matching feature and the second matching feature.
[0078] Specifically, in the embodiments of the present invention, when determining the matching information, the encoding features corresponding to the current user input can be first feature-matched with the encoding features corresponding to the historical Q&A information to obtain a first matching feature, and the encoding features corresponding to the current user input can be feature-matched with the set encoding features to obtain a second matching feature. Among them, the first matching feature is used to characterize the important matching information between the current user input and the historical Q&A information, and the second matching feature is used to characterize the important matching information between the current user input and the current alternative reply set.
[0079] Among them, the first matching feature can be determined by the following method:
[0080] First, the word-level encoding sequence in the encoding features corresponding to the current user input can be multiplied by the word-level encoding sequences in the encoding features corresponding to each piece of information in the historical Q&A information to obtain a word-level sequence matching feature. The segment-level encoding sequence in the encoding features corresponding to the current user input can be multiplied by the segment-level encoding sequences in the encoding features corresponding to each piece of information in the historical Q&A information to obtain a segment-level sequence matching feature. The word-level sequence matching feature and the segment-level sequence matching feature can be represented in the form of matrices, that is, corresponding to the word-level sequence matching matrix and the segment-level sequence matching matrix respectively.
[0081] It should be noted that each piece of information in the historical Q&A information can be either a historical rhetorical question sentence sent by the execution subject to the user or a historical user input, and the user input can include the initial user input and non-initial user input before the current user input.
[0082] The word-level sequence matching feature and the segment-level sequence matching feature corresponding to each piece of information in the historical Q&A information can form a two-dimensional matching feature tensor corresponding to each piece of information. The matching feature tensors corresponding to each piece of information are all subjected to alternating convolution and pooling operations to obtain a two-dimensional tensor operation result corresponding to each piece of information. The two dimensions in the tensor operation result are concatenated and linearly mapped to obtain a fixed-dimension vector.
[0083] Finally, the fixed-dimension vectors corresponding to each piece of information in the historical Q&A information are accumulated in chronological order to obtain an accumulated vector. The first matching feature can be determined through this accumulated vector. Among them, the accumulation process can be implemented by GRU, and the obtained accumulated vector can be the hidden state sequence of GRU. This hidden state sequence can be represented as H n =[h′1, h′2,..., h′ n , where n is the number of pieces of information in the historical Q&A information.
[0084] When determining the first matching feature through this accumulated vector, it can be implemented in the following two ways:
[0085] The first method: Take the last component in the cumulative vector, that is, the last hidden state in the hidden state sequence, as the first matching feature, namely:
[0086] L u (·) = h′ n
[0087] where L u (·) is the first matching feature.
[0088] The second method: Obtain the first matching feature by performing weighted summation on each component in the cumulative vector, namely:
[0089]
[0090] where ω i is the weight of the i-th component in the cumulative vector, which can be obtained through training or set to a suitable fixed value as needed, and no specific limitation is made here.
[0091] The second matching feature can be determined by the following method:
[0092] Since the encoding features corresponding to the current user input include a word-level encoding sequence and a segment-level encoding sequence, and the set encoding features are usually word-level encoding sequences, the encoding features corresponding to the current user input can be feature-matched with the set encoding features in the word-level dimension, that is, the word-level encoding sequence in the encoding features corresponding to the current user input is feature-matched with the set encoding features.
[0093] First, the word-level encoding sequence in the encoding features corresponding to the current user input can be multiplied by the set encoding features to obtain a word-level sequence matching feature.
[0094] Then, the word-level sequence matching feature corresponding to the set encoding features can be alternately convolved and pooled to obtain an operation result corresponding to the set encoding features. Then, the operation result is linearly mapped to obtain a fixed-dimensional vector, and this fixed-dimensional vector is the second matching feature.
[0095] Finally, combining the first matching feature and the second matching feature, the matching information of the current user input with the current alternative response set and historical Q&A information can be obtained. Here, the matching result in the matching information can be determined by the matching score between the current user input and the current alternative response set and historical Q&A information, and this matching score can be determined by the weighted summation result of the first matching feature and the second matching feature. For example, the matching result can be classified through the weighted summation result, and the category score corresponding to the successful matching is the matching score.
[0096] The rhetorical question sentence sent to the user when the matching fails in the matching information can be generated based on the difference between the alternative responses that match the current user input and the alternative responses that do not match the current user input in the current alternative response set, so that the response information of the user to the rhetorical question sentence can be used to determine an appropriate alternative response in the current alternative response set as the answer input.
[0097] In the embodiments of the present invention, by introducing the first matching feature and the second matching feature, the determination process of the matching information can be refined, the error generated in the determination process can be reduced, and the accuracy of the matching information can be improved.
[0098] Based on the above embodiments, in the question-answering method provided in the embodiments of the present invention, determining the matching information based on the first matching feature and the second matching feature includes:
[0099] Based on the first matching feature and the second matching feature, using a classification function, determine the score that the first matching feature and the second matching feature belong to the same category;
[0100] Based on the score, determine the matching information.
[0101] Specifically, when determining the matching information, a classification function can be first used, and the score that the first matching feature and the second matching feature belong to the same category can be determined in a weighted summation manner. This classification function can be a softmax function, a sigmoid function, or other functions that can implement classification. Taking the classification function as the softmax function as an example for illustration, the score that the first matching feature and the second matching feature belong to the same category can be expressed as:
[0102] S(u, a, r) = softmax(W u L u (·) + W a v + b)
[0103] where S(u, a, r) represents the score, u represents the historical question-answering information, a represents the current alternative response set, r represents the current user input, L u (·) represents the first matching feature, W u represents the weight corresponding to the first matching feature, v represents the second matching feature, W a represents the weight corresponding to the second matching feature, b represents the bias introduced by the weighted summation, usually a constant. W u and W a can both be set as needed or obtained through training, and no specific limitation is made here.
[0104] Then, combining the above scores, the matching information can be determined. In this process, a score threshold can be introduced. If the above score is greater than the score threshold, it is considered that the first matching feature and the second matching feature belong to the same category, and the matching information is a successful match at this time. Otherwise, if the above score is less than or equal to the score threshold, it is considered that the first matching feature and the second matching feature belong to different categories, and the matching information is a failed match at this time, and a rhetorical question sentence for sending to the user is further generated.
[0105] In the embodiments of the present invention, a classification function is adopted, so that the method for determining the matching information is equivalent to the feature classification method, which can improve the data processing efficiency, improve the speed of determining the matching information, and further improve the response efficiency of the initial user input and enhance the user experience.
[0106] Based on the above embodiments, in the question-answering method provided in the embodiments of the present invention, encoding the current alternative response set based on the knowledge graph to obtain a set encoding feature includes:
[0107] Determine the graph information in the knowledge graph corresponding to the current alternative response set;
[0108] Encode the graph information to obtain the set encoding feature.
[0109] Specifically, in the embodiments of the present invention, when encoding the current alternative response set, each alternative response in the current alternative response set can be first parsed to determine the elements included in each alternative response, and then each element can be mapped to the knowledge graph to obtain the graph information corresponding to the current alternative set. This graph information can be a local knowledge graph, which contains the elements corresponding to each alternative response in the current alternative response set and the structural relationships between the elements.
[0110] Then, by encoding the graph information, the set encoding feature can be obtained. Here, the DeepWalk model can be used to encode the graph information to obtain the set encoding feature (Graph embedding), that is, perform random walks on the graph structure corresponding to the graph information to generate several element relationship sequences corresponding to the graph structure. Each element relationship sequence can correspond to a structural relationship on the graph structure and the elements involved, that is, an edge and the elements it connects. Then these element relationship sequences can be encoded through the word2vec model to obtain the element relationship encoding, that is, the set encoding feature.
[0111] In the embodiments of the present invention, when determining the set encoding feature, first determine the graph information in the knowledge graph corresponding to the current alternative response set, and further encode the graph information, so that the encoding amount can be reduced and the encoding efficiency can be improved.
[0112] Based on the above embodiments, in the question-answering method provided by the embodiments of the present invention, steps S1 to S3 can be implemented by a rhetorical question generation model.
[0113] As Figure 2 shown, the rhetorical question generation model may include an Utterance-response matching module, a Matching accumulation module, an Answer-response matching module, and a Matching prediction module.
[0114] The input of the Utterance-response matching module is historical question-answering information u1, u2, …, u n and the current user input r, and the output is the tensor operation result corresponding to each piece of information in the historical question-answering information. The Utterance-response matching module includes a Word Embedding unit, a GRU, a word-level sequence matching (Word Pairs) unit, a segment-level sequence matching (Segment Pairs) unit, a convolution (Convolution) unit, and a pooling (Pooling) unit. The Word Embedding unit is used to determine the word vectors of the historical question-answering information and the current user input. The GRU is used to encode the word vector sequences of the historical question-answering information and the current user input. The Word Pairs unit is used to determine the word-level sequence matching features corresponding to each piece of information in the historical question-answering information. The Segment Pairs unit is used to determine the segment-level sequence matching features corresponding to each piece of information in the historical question-answering information. The Convolution unit is used to perform a convolution operation on the matching feature tensors corresponding to each piece of information in the historical question-answering information to obtain a convolution result. The Pooling unit is used to perform a pooling operation on the convolution result to obtain a tensor operation result.
[0115] The input of the Matching accumulation module is the tensor operation result corresponding to each piece of information in the historical question-answering information, and the output is a hidden state sequence, that is, H n =[h′1, h′2, …, h′ n . The Matching accumulation module includes an accumulation unit and a GRU. The accumulation unit is used to determine the fixed-dimensional vectors corresponding to each piece of information in the historical question-answering information. The GRU is used to determine the hidden state sequence corresponding to the historical question-answering information.
[0116] The input of the Answer-response matching module is each alternative response a1, a2, …, a in the current alternative response sett and a knowledge graph KG, with the output being the second matching feature v, where t is the number of candidate responses in the current candidate response set. The Answer-response matching module includes a Graph Embedding unit, a Word Pairs unit, a Convolution unit, and a Pooling unit. The Graph Embedding unit is used to determine the set encoding features corresponding to the graph information. The Word Pairs unit is used to determine the word-level sequence matching features corresponding to the set encoding features. The Convolution unit is used to perform a convolution operation on the word-level sequence matching features to obtain a convolution result. The Pooling unit is used to perform a pooling operation on the convolution result to obtain an operation result, and perform a linear mapping on the operation result to obtain the second matching feature.
[0117] The input of the Matching prediction module is the hidden state sequence corresponding to the historical question and answer information and the second matching feature. The Matching prediction module includes a preprocessing unit and a prediction unit. The preprocessing unit is used to determine the first matching feature L u (·), and the prediction unit is used to calculate the score Score that the first matching feature and the second matching feature belong to the same category.
[0118] In the embodiments of the present invention, the steps involved in the question and answer method are integrated and implemented through a rhetorical question generation model, which can ensure the integrity and aggregation of the question and answer method.
[0119] Based on the above embodiments, in the question and answer method provided in the embodiments of the present invention, the determining the current candidate response set corresponding to the current user input includes:
[0120] Based on the current user input, screening the previous candidate response set corresponding to the previous user input of the current user input to obtain the current candidate response set;
[0121] Among them, the initial candidate response set corresponding to the initial user input is determined based on the answers in the question and answer database that match the initial user input.
[0122] Specifically, in the embodiments of the present invention, when determining the current alternative response set, the previous alternative response set corresponding to the previous user input of the current user input may be filtered first according to the current user input, that is, the current alternative response set is obtained. Among them, the previous user input refers to the user input in the previous question-and-answer round of the current question-and-answer round. The previous alternative response set refers to the alternative response set obtained by filtering through the previous user input. It can be seen from this that the process of determining the current alternative response set in the embodiments of the present invention is an iterative process. The initial alternative response set of the iterative process corresponds to the initial user input and can be determined by the answers matching the initial user input in the question-and-answer database.
[0123] Question templates and corresponding answers may be stored in the question-and-answer database. First, the initial user input may be matched with the question templates, and the answers corresponding to the successfully matched question templates are the answers matching the initial user input. Since the answers matching the initial user may be one or more, all the answers may jointly constitute the initial alternative response set.
[0124] In the embodiments of the present invention, the current alternative response set is determined through an iterative process, so that the current alternative response set is updated in real time following the current user input, and the alternative response set gradually shrinks during the iterative process, which can improve the encoding efficiency of the current alternative response set. Moreover, through the question-and-answer database, the initial alternative response set can be quickly determined.
[0125] Based on the above embodiments, in the question-and-answer method provided in the embodiments of the present invention, the field to which the initial user input belongs includes the construction field. The question-and-answer database stores the corresponding relationship between the question templates and the answers, and the answers in the question-and-answer database are building codes.
[0126] Specifically, in the embodiments of the present invention, the initial user input may be a user question in the construction field. Correspondingly, the question-and-answer database stores the corresponding relationship between the question templates and the answers, and the answers in the question-and-answer database are building codes. That is, the user provides a user question to the question-and-answer device, intending to obtain the building codes matching the user question.
[0127] For example, the initial user input may be "What are the requirements for the clear width of the aisle leading to the bedroom?", and its field belongs to the construction field. Then, the building codes matching the initial user input can be queried from various building codes in the construction field as alternative responses and stored in the initial alternative response set, thereby realizing the construction of the initial alternative response set.
[0128] Furthermore, the knowledge graph may be composed of entities, attributes, and clauses in the construction field, and the clauses may represent the relationship between the entities and the attributes. For example, in the initial user input, the bedroom and the aisle are both entities, and the clear width is an attribute.
[0129] In the embodiments of the present invention, the provided question-and-answer method can be applied to the query of building codes in the construction field, enabling users to quickly and accurately obtain the required building codes.
[0130] As Figure 3 shown, on the basis of the above embodiments, an embodiment of the present invention provides a question-and-answer device, including:
[0131] A receiving module 31, configured to receive the current user input and determine the current alternative reply set corresponding to the current user input;
[0132] An encoding module 32, configured to encode the current alternative reply set based on the knowledge graph to obtain a set encoding feature;
[0133] A matching module 33, configured to determine the matching information between the current user input, the current alternative reply set, and the historical question-and-answer information based on the encoding feature corresponding to the current user input, the encoding feature corresponding to the historical question-and-answer information, and the set encoding feature;
[0134] A reply module 34, configured to determine the answer corresponding to the initial user input based on the matching information and the current alternative reply set.
[0135] On the basis of the above embodiments, for the question-and-answer device provided in the embodiments of the present invention, the matching information includes a matching result, the matching result includes a successful match or a failed match, and the matching information further includes a rhetorical question sentence when the match fails;
[0136] Correspondingly, the reply module is configured to:
[0137] If the matching result is a successful match, determine the current alternative reply set as the answer;
[0138] If the matching result is a failed match, receive the reply information of the user for the rhetorical question sentence, and use the reply information as the current user input, and continue to determine the matching information until the matching information is a successful match.
[0139] On the basis of the above embodiments, for the question-and-answer device provided in the embodiments of the present invention, the matching module is configured to:
[0140] Perform feature matching on the encoding feature corresponding to the current user input with the encoding feature corresponding to the historical question-and-answer information and the set encoding feature respectively to obtain a first matching feature and a second matching feature of the current user input;
[0141] Determine the matching information based on the first matching feature and the second matching feature.
[0142] Based on the above embodiments, in the question-and-answer device provided in the embodiments of the present invention, the matching module is specifically configured to:
[0143] Based on the first matching feature and the second matching feature, use a classification function to determine the score indicating that the first matching feature and the second matching feature belong to the same category;
[0144] Based on the score, determine the matching information.
[0145] Based on the above embodiments, in the question-and-answer device provided in the embodiments of the present invention, the encoding module is used to:
[0146] Determine the graph information in the knowledge graph corresponding to the current set of alternative responses;
[0147] Encode the graph information to obtain the set encoding feature.
[0148] Based on the above embodiments, in the question-and-answer device provided in the embodiments of the present invention, the receiving module is used to:
[0149] Based on the current user input, screen the previous set of alternative responses corresponding to the previous user input of the current user input to obtain the current set of alternative responses;
[0150] Wherein, the initial set of alternative responses corresponding to the initial user input is determined based on the answers in the question-and-answer database that match the initial user input.
[0151] Based on the above embodiments, in the question-and-answer device provided in the embodiments of the present invention, the field to which the initial user input belongs includes the construction field, the question-and-answer database stores the corresponding relationship between the question templates and the answers, and the answers in the question-and-answer database are building codes.
[0152] Specifically, the functions of the modules in the question-and-answer device provided in the embodiments of the present invention correspond one-to-one to the operation processes of the steps in the above method embodiments, and the achieved effects are also the same. For details, see the above embodiments, and the embodiments of the present invention will not be elaborated herein.
[0153] Figure 4 An example of the physical structure diagram of an electronic device is shown in Figure 4As shown in the figure, the electronic device may include: a processor 410, a communications interface 420, a memory 430, and a communication bus 440. Among them, the processor 410, the communications interface 420, and the memory 430 complete communication with each other through the communication bus 440. The processor 410 may call the logical instructions in the memory 430 to execute the Q&A method provided in the above embodiments. The method includes: receiving a current user input and determining a current alternative reply set corresponding to the current user input; encoding the current alternative reply set based on a knowledge graph to obtain a set encoding feature; determining matching information of the current user input with the current alternative reply set and the historical Q&A information based on the encoding feature corresponding to the current user input, the encoding feature corresponding to the historical Q&A information, and the set encoding feature; and determining an answer corresponding to the initial user input based on the matching information and the current alternative reply set.
[0154] In addition, when the logical instructions in the above-mentioned memory 430 are implemented in the form of software functional units and sold or used as independent products, they may be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, may be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in various embodiments of the present invention. The foregoing storage medium includes: various media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk, or an optical disc that can store program codes.
[0155] On the other hand, the present invention also provides a computer program product. The computer program product includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the Q&A method provided in the above embodiments. The method includes: receiving a current user input and determining a current alternative reply set corresponding to the current user input; encoding the current alternative reply set based on a knowledge graph to obtain a set encoding feature; determining matching information of the current user input with the current alternative reply set and the historical Q&A information based on the encoding feature corresponding to the current user input, the encoding feature corresponding to the historical Q&A information, and the set encoding feature; and determining an answer corresponding to the initial user input based on the matching information and the current alternative reply set.
[0156] In another aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it is configured to execute the Q&A method provided in the above-mentioned various embodiments. The method includes: receiving a current user input and determining a current set of alternative responses corresponding to the current user input; encoding the current set of alternative responses based on a knowledge graph to obtain set encoding features; determining matching information between the current user input, the current set of alternative responses, and historical Q&A information based on the encoding features corresponding to the current user input, the encoding features corresponding to the historical Q&A information, and the set encoding features; and determining an answer corresponding to the initial user input based on the matching information and the current set of alternative responses.
[0157] The device embodiments described above are merely illustrative. 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 to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. A person of ordinary skill in the art can understand and implement it without creative effort.
[0158] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the essence of the above technical solution, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0159] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments or equivalently replace some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A question-and-answer method, characterized in that, including: Receiving the current user input and determining a current alternative response set corresponding to the current user input; Encoding the current alternative response set based on a knowledge graph to obtain a set encoding feature; Determining matching information of the current user input with the current alternative response set and the historical Q&A information based on an encoding feature corresponding to the current user input, an encoding feature corresponding to the historical Q&A information, and the set encoding feature; Determining an answer corresponding to the initial user input based on the matching information and the current alternative response set; The encoding the current alternative response set based on the knowledge graph to obtain a set encoding feature includes: Determining graph information in the knowledge graph corresponding to the current alternative response set; Encoding the graph information to obtain the set encoding feature; The determining the matching information of the current user input with the current alternative response set and the historical Q&A information based on the encoding feature corresponding to the current user input, the encoding feature corresponding to the historical Q&A information, and the set encoding feature includes: Performing feature matching on the encoding feature corresponding to the current user input with the encoding feature corresponding to the historical Q&A information and the set encoding feature respectively to obtain a first matching feature and a second matching feature of the current user input; Based on the first matching feature and the second matching feature, using a classification function to determine a score indicating that the first matching feature and the second matching feature belong to the same category; Determining the matching information based on the score.
2. The Q&A method according to claim 1, characterized in that The matching information includes a matching result, the matching result includes matching success or matching failure, and the matching information further includes a rhetorical question sentence when the matching fails; Correspondingly, the determining the answer corresponding to the initial user input based on the matching information and the current alternative response set includes: If the matching result is matching success, determining the current alternative response set as the answer; If the matching result is matching failure, receiving reply information of the user for the rhetorical question sentence and using the reply information as the current user input, and continuing to determine the matching information until the matching information is matching success.
3. The Q&A method according to any one of claims 1-2, characterized in that, The determining the current alternative response set corresponding to the current user input includes: Based on the current user input, screening a previous alternative response set corresponding to a previous user input of the current user input to obtain the current alternative response set; Wherein, the initial alternative response set corresponding to the initial user input is determined based on an answer matching the initial user input in a Q&A database.
4. The Q&A method according to claim 3, characterized in that, The field to which the initial user input belongs includes the construction field, and a corresponding relationship between a question template and an answer is stored in the Q&A database, and the answer in the Q&A database is a building code.
5. A question-and-answer device, characterized in that, including: A receiving module, configured to receive the current user input and determine a current alternative response set corresponding to the current user input; An encoding module, configured to encode the current alternative response set based on a knowledge graph to obtain a set encoding feature; A matching module, configured to determine matching information between the current user input, the current alternative reply set, and the historical Q&A information based on the encoding features corresponding to the current user input, the encoding features corresponding to the historical Q&A information, and the set encoding features; A reply module, configured to determine an answer corresponding to the initial user input based on the matching information and the current alternative reply set; The encoding module is specifically configured to: Determine the graph information in the knowledge graph corresponding to the current alternative reply set; Encode the graph information to obtain the set encoding features; The determining the matching information between the current user input, the current alternative reply set, and the historical Q&A information based on the encoding features corresponding to the current user input, the encoding features corresponding to the historical Q&A information, and the set encoding features includes: Performing feature matching on the encoding features corresponding to the current user input with the encoding features corresponding to the historical Q&A information and the set encoding features respectively to obtain a first matching feature and a second matching feature of the current user input; Based on the first matching feature and the second matching feature, using a classification function to determine a score indicating that the first matching feature and the second matching feature belong to the same category; Based on the score, determining the matching information.
6. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the program, the steps of the Q&A method according to any one of claims 1 to 4 are implemented.
7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, the steps of the Q&A method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Question and answer interacting method and device, computer equipment and computer readable storage medium
CN107992543A
Medical question-answering retrieval method, system and device based on multi-modal knowledge perception
CN110895561A
Customer service question and answer processing method and system for retrieving multiple rounds of conversations
CN111046132A