A method, apparatus, storage medium, and device for generating knowledge conversations
By combining historical dialogue and knowledge sentences in the dialogue generation model for dynamic selection and interactive encoding, the problem of low reply quality in the existing dialogue system is solved, and more meaningful and informative dialogue replies are generated, which improves the user experience.
Patent Information
- Application Number
- CN202211581115.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-09
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2042-12-09
AI Technical Summary
Existing generation-based dialogue systems are prone to generate insufficient content and meaningless replies when digging into specific topics, and have poor user experience.
By obtaining historical dialogue sentences and related knowledge sentences of the target dialogue, using multiple rounds of historical dialogue discourse corpus and knowledge corpus to train the dialogue generation model, dynamic selection and interactive encoding are performed, and high-quality replies are generated.
Generate high-quality responses with rich knowledge and information, improving the user experience.
Smart Images

Figure CN115878769B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing technology, and in particular to a method, apparatus, storage medium and device for generating knowledge dialogues. Background Art
[0002] With the rapid development of artificial intelligence (AI) technology, human-computer interaction is occurring with increasing frequency in our daily work and lives. To enable natural conversations between people and machines, researchers have continuously explored dialogue systems, building numerous dialogue systems using both retrieval-based and generation-based approaches. Compared to retrieval-based dialogue systems, generation-based dialogue systems can generate coherent and diverse responses, offering the advantage of generalization while avoiding tedious and time-consuming retrieval operations. These systems are more flexible and natural, possessing significant research and application value.
[0003] However, current dialogue systems built using generative methods often produce meaningless and empty responses such as "I don't know" and "You're right." This is primarily due to the system's inability to understand and utilize relevant knowledge. When delving into specific topics, it tends to generate responses that lack substance and are meaningless. In real-world conversations, people typically engage in divergent thinking based on a few words or topics in the conversation, recalling relevant knowledge stored in their minds and organizing it into coherent sentences to respond. Therefore, the responses generated by existing dialogue systems often lack quality, resulting in a poor user experience. It is necessary to enhance the quality of responses by integrating knowledge. Summary of the Invention
[0004] The main purpose of the embodiments of the present application is to provide a method, device, storage medium and equipment for generating knowledge dialogues, which can improve the quality of responses to generated dialogues and thereby improve user experience.
[0005] This embodiment of the present application provides a method for generating a knowledge dialogue, including:
[0006] Obtain L rounds of historical conversation sentences for the current target conversation; and based on the topic of the target conversation, obtain M knowledge sentences related to the topic; where L and M are both positive integers greater than 0;
[0007] The L rounds of historical dialogue sentences and the M knowledge sentences are input into a pre-built dialogue generation model to predict the response sentences corresponding to the target dialogue; the dialogue generation model is trained by dynamically selecting knowledge based on the interaction between historical dialogues and knowledge using multiple rounds of historical dialogue data and knowledge data.
[0008] In one possible implementation, the dialogue generation model is constructed as follows:
[0009] Obtain L rounds of training history dialogue sentences of the training dialogue, and according to the training topic of the training dialogue, obtain M training knowledge sentences related to the training topic;
[0010] Inputting the L rounds of training history dialogue sentences and the M training knowledge sentences into the initial dialogue generation model to train and obtain the dialogue generation model;
[0011] The initial dialogue generation model includes an input layer, an encoding layer, a dialogue history encoding layer, and a knowledge interaction encoding layer.
[0012] In one possible implementation, inputting the L rounds of training history dialogue sentences and the M training knowledge sentences into an initial dialogue generation model to train the dialogue generation model includes:
[0013] Inputting the character vectors or word vectors of the L rounds of training history dialogue sentences and the vector representations of the M training knowledge sentences into the input layer to obtain sample input vectors of the L rounds of training history dialogue sentences and sample input vectors of the M training knowledge sentences;
[0014] Inputting the sample input vectors of the L rounds of training history dialogue sentences and the sample input vectors of the M training knowledge sentences into the encoding layer to obtain encoding vectors of the L rounds of training history dialogue sentences and encoding vectors of the M training knowledge sentences;
[0015] Inputting the encoding vector of the L-round training history conversation sentence into the conversation history encoding layer to perform feature enhancement to obtain the enhanced feature vector of the L-round training history conversation sentence;
[0016] Inputting the enhanced feature vectors of the L rounds of training history dialogue sentences and the encoding vectors of the M training knowledge sentences into the knowledge interaction encoding layer for interactive encoding to obtain training reply sentences corresponding to the training dialogues;
[0017] The initial dialogue generation model is trained using the obtained training response sentences corresponding to the training dialogue, the real response results corresponding to the training dialogue, and a preset loss function to obtain the dialogue generation model.
[0018] In one possible implementation, inputting the encoding vector of the L-round training history conversation sentence into the conversation history encoding layer to perform feature enhancement to obtain the enhanced feature vector of the L-round training history conversation sentence includes:
[0019] Input the encoding vectors of the L rounds of training history conversation sentences into the conversation history encoding layer, and use a dynamic window of size Lt to sample t historical conversation segments from the L rounds of training history conversation sentences in order from near to far, where t is a positive integer greater than 0 and not less than L-1;
[0020] Constructing a semantic dependency tree corresponding to each of the t historical conversation segments, and calculating a historical conversation matrix corresponding to the t historical conversation segments based on the semantic dependency tree;
[0021] Calculate the mutual attention between the historical dialogue matrix corresponding to the t historical dialogue segments and the encoding vector of the L-th round of training historical dialogue sentences, and perform weighted summation on the hidden layer states of the t historical dialogue segments based on the obtained mutual attention to obtain the fused feature vector of the L-th round of training historical dialogue sentences.
[0022] In one possible implementation, the knowledge interaction encoding layer includes a multi-head attention layer, a knowledge interaction fusion attention layer, and a feedforward neural network layer; the enhanced feature vectors of the L rounds of training history dialogue sentences and the encoding vectors of the M training knowledge sentences are input into the knowledge interaction encoding layer for interactive encoding to obtain training response sentences corresponding to the training dialogue, including:
[0023] Inputting the enhanced feature vector of the L-round training history dialogue sentence and the currently obtained training reply word sequence into the knowledge interaction encoding layer for splicing to obtain a splicing vector;
[0024] Input the concatenated vector into the multi-head attention layer and perform normalization processing to obtain a first decoding vector;
[0025] Inputting the first decoding vector and the encoding vectors of the M training knowledge sentences into the knowledge interaction fusion attention layer to obtain weight values corresponding to the M training knowledge sentences, and using the weight values to perform weighted summation on the M training knowledge sentences to obtain updated knowledge representations corresponding to the M training knowledge sentences;
[0026] Utilizing a gating mechanism, the feedforward neural network layer performs weighted and normalized processing on the updated knowledge representations corresponding to the M training knowledge sentences and the currently obtained training response word sequence to generate a training response sentence corresponding to the training dialogue.
[0027] In a possible implementation, the method further includes:
[0028] Obtain L rounds of verification history dialogue sentences of the verification dialogue, and according to the verification topic of the verification dialogue, obtain M verification knowledge sentences related to the verification topic;
[0029] Input the L rounds of verification history dialogue sentences and the M verification knowledge sentences into the dialogue generation model to predict the verification reply sentences corresponding to the verification dialogue;
[0030] When the verification response statement corresponding to the verification dialogue is inconsistent with the actual response result corresponding to the verification dialogue, the verification dialogue is used again as the training dialogue, and the dialogue generation model is updated to obtain an updated dialogue generation model.
[0031] In one possible implementation, inputting the L rounds of historical dialogue sentences and the M knowledge sentences into a pre-built dialogue generation model to predict a response sentence corresponding to the target dialogue includes:
[0032] Inputting the character vectors or word vectors of the L-round historical dialogue sentences and the vector representations of the M knowledge sentences into the input layer of the dialogue generation model to obtain the input vectors of the L-round historical dialogue sentences and the input vectors of the M knowledge sentences;
[0033] Inputting the input vectors of the L rounds of historical dialogue sentences and the input vectors of the M knowledge sentences into the encoding layer of the dialogue generation model to obtain encoding vectors of the L rounds of historical dialogue sentences and encoding vectors of the M knowledge sentences;
[0034] Inputting the encoding vector of the L-round historical conversation sentence into the conversation history encoding layer of the conversation generation model to perform feature enhancement to obtain an enhanced feature vector of the L-round historical conversation sentence;
[0035] The enhanced feature vectors of the L-round historical dialogue sentences and the encoding vectors of the M knowledge sentences are input into the knowledge interaction encoding layer of the dialogue generation model for interactive encoding to obtain the reply sentences corresponding to the target dialogue.
[0036] The present application also provides a knowledge dialogue generation device, including:
[0037] A first acquisition unit is configured to acquire L rounds of historical conversation sentences of a current target conversation; and based on the topic of the target conversation, acquire M knowledge sentences related to the topic; where both L and M are positive integers greater than 0;
[0038] The first prediction unit is used to input the L rounds of historical dialogue sentences and the M knowledge sentences into a pre-built dialogue generation model to predict the response sentence corresponding to the target dialogue; the dialogue generation model is trained by dynamically selecting knowledge based on the interaction between historical dialogue and knowledge using multiple rounds of historical dialogue data and knowledge data.
[0039] In a possible implementation, the apparatus further includes:
[0040] A second acquisition unit is configured to acquire L rounds of training history dialogue sentences of the training dialogue, and acquire M training knowledge sentences related to the training topic according to the training topic of the training dialogue;
[0041] A training unit, configured to input the L rounds of training history dialogue sentences and the M training knowledge sentences into an initial dialogue generation model, and train the dialogue generation model;
[0042] The initial dialogue generation model includes an input layer, an encoding layer, a dialogue history encoding layer, and a knowledge interaction encoding layer.
[0043] In one possible implementation, the training unit includes:
[0044] A first input subunit is configured to input the character vectors or word vectors of the L rounds of training history dialogue sentences and the vector representations of the M training knowledge sentences into the input layer to obtain sample input vectors of the L rounds of training history dialogue sentences and sample input vectors of the M training knowledge sentences;
[0045] A second input subunit is configured to input the sample input vectors of the L rounds of training history dialogue sentences and the sample input vectors of the M training knowledge sentences into the encoding layer to obtain encoding vectors of the L rounds of training history dialogue sentences and encoding vectors of the M training knowledge sentences;
[0046] A first enhancement subunit is configured to input the encoding vector of the L-round training history conversation sentence into the conversation history encoding layer to perform feature enhancement to obtain an enhanced feature vector of the L-round training history conversation sentence;
[0047] A first encoding subunit is configured to input the enhanced feature vectors of the L rounds of training history dialogue sentences and the encoding vectors of the M training knowledge sentences into the knowledge interaction encoding layer to perform interactive encoding to obtain training reply sentences corresponding to the training dialogues;
[0048] The training subunit is used to train the initial dialogue generation model using the training response sentences corresponding to the training dialogue, the real response results corresponding to the training dialogue, and the preset loss function to obtain the dialogue generation model.
[0049] In one possible implementation, the first enhancer unit includes:
[0050] A sampling subunit is configured to input the encoding vectors of the L rounds of training history conversation sentences into the conversation history encoding layer, and use a dynamic window of size Lt to sample the L rounds of training history conversation sentences in order from near to far to obtain t historical conversation segments; where t is a positive integer greater than 0 and not less than L-1;
[0051] A first calculation subunit is configured to construct a semantic dependency tree corresponding to each of the t historical conversation segments, and calculate a historical conversation matrix corresponding to the t historical conversation segments based on the semantic dependency tree;
[0052] The second computing subunit is configured to calculate the mutual attention between the historical dialogue matrices corresponding to the t historical dialogue segments and the encoding vectors of the historical dialogue sentences of the L-th round of training, and perform weighted summation on the hidden layer states of the t historical dialogue segments based on the obtained mutual attention to obtain the fused feature vectors of the historical dialogue sentences of the L-th round of training.
[0053] In one possible implementation, the knowledge interaction encoding layer includes a multi-head attention layer, a knowledge interaction fusion attention layer, and a feedforward neural network layer; the first encoding subunit includes:
[0054] A splicing subunit, configured to input the enhanced feature vector of the L-round training history dialogue sentence and the currently obtained training reply word sequence into the knowledge interaction encoding layer for splicing to obtain a splicing vector;
[0055] a normalization subunit, configured to input the concatenated vector into the multi-head attention layer and perform normalization processing to obtain a first decoding vector;
[0056] a third input subunit, configured to input the first decoding vector and the encoding vectors of the M training knowledge sentences into the knowledge interaction fusion attention layer, obtain weight values corresponding to the M training knowledge sentences, and use the weight values to perform weighted summation on the M training knowledge sentences to obtain updated knowledge representations corresponding to the M training knowledge sentences;
[0057] The generation subunit is used to utilize a gating mechanism to weight and normalize the updated knowledge representations corresponding to the M training knowledge sentences and the currently obtained training response word sequence through the feedforward neural network layer to generate a training response sentence corresponding to the training dialogue.
[0058] In a possible implementation, the apparatus further includes:
[0059] A third acquisition unit is configured to acquire L rounds of verification dialogue sentences of the verification dialogue, and acquire M verification knowledge sentences related to the verification topic according to the verification topic of the verification dialogue;
[0060] A second prediction unit is configured to input the L rounds of verification history dialogue sentences and the M verification knowledge sentences into the dialogue generation model to predict a verification reply sentence corresponding to the verification dialogue;
[0061] An updating unit is used to, when the verification response statement corresponding to the verification dialogue is inconsistent with the actual response result corresponding to the verification dialogue, use the verification dialogue as the training dialogue again to update the dialogue generation model to obtain an updated dialogue generation model.
[0062] In a possible implementation, the first prediction unit includes:
[0063] a fourth input subunit, configured to input the character vectors or word vectors of the L rounds of historical dialogue sentences and the vector representations of the M knowledge sentences into the input layer of the dialogue generation model, thereby obtaining input vectors of the L rounds of historical dialogue sentences and input vectors of the M knowledge sentences;
[0064] a fifth input subunit, configured to input the input vectors of the L rounds of historical dialogue sentences and the input vectors of the M knowledge sentences into the encoding layer of the dialogue generation model to obtain encoding vectors of the L rounds of historical dialogue sentences and encoding vectors of the M knowledge sentences;
[0065] A second enhancement subunit is configured to input the encoding vector of the L-round historical dialogue sentence into the dialogue history encoding layer of the dialogue generation model to perform feature enhancement to obtain an enhanced feature vector of the L-round historical dialogue sentence;
[0066] The second encoding sub-unit is used to input the enhanced feature vectors of the L-round historical dialogue sentences and the encoding vectors of the M knowledge sentences into the knowledge interaction encoding layer of the dialogue generation model to perform interactive encoding to obtain the reply sentence corresponding to the target dialogue.
[0067] The embodiment of the present application also provides a knowledge dialogue generation device, comprising: a processor, a memory, and a system bus;
[0068] The processor and the memory are connected via the system bus;
[0069] The memory is used to store one or more programs, and the one or more programs include instructions. When the instructions are executed by the processor, the processor executes any one of the implementations of the above-mentioned knowledge dialogue generation method.
[0070] An embodiment of the present application also provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a terminal device, the terminal device executes any one of the implementations of the above-mentioned knowledge dialogue generation method.
[0071] An embodiment of the present application further provides a computer program product, which, when executed on a terminal device, enables the terminal device to execute any one of the implementations of the above-mentioned knowledge dialogue generation method.
[0072] The embodiment of the present application provides a method, apparatus, storage medium, and device for generating knowledge dialogues. The method first obtains L rounds of historical dialogue sentences of the current target dialogue; and based on the topic of the target dialogue, obtains M knowledge sentences related to the topic; wherein L and M are both positive integers greater than 0; then the L rounds of historical dialogue sentences and M knowledge sentences are input into a pre-built dialogue generation model to predict the response sentences corresponding to the target dialogue; wherein the dialogue generation model is trained by dynamically selecting knowledge based on the interaction between historical dialogues and knowledge using multiple rounds of historical dialogue data and knowledge data. It can be seen that because the present application fully considers the complex interactive relationship between dialogue history and knowledge when generating response words for the target dialogue using the dialogue generation model, and dynamically selects knowledge during the decoding process, it can generate high-quality responses with rich knowledge information, thereby improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0073] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0074] Figure 1 A flowchart of a method for generating a knowledge dialogue provided in an embodiment of the present application;
[0075] Figure 2 A schematic diagram of the structure of the dialogue generation model provided in an embodiment of the present application;
[0076] Figure 3 A schematic diagram of the composition of a knowledge dialogue generation device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0077] One of the key goals of artificial intelligence technology has always been to enable people to have natural conversations with machines, which has led researchers to continuously explore dialogue systems.
[0078] Based on their construction methods, dialogue systems are generally categorized into two types: retrieval-based and generation-based. Retrieval-based approaches rapidly retrieve relevant candidate information from a larger corpus, then, through sorting and filtering, retrieve the optimal responses and return them to the user. Their advantages include low content risk and high controllability. However, their disadvantages are that dialogue effectiveness is limited by the corpus coverage and retrieval accuracy, and practical applications involve numerous retrieval operations, resulting in a high computational load. In contrast, generation-based approaches employ an end-to-end Seq2Seq neural network architecture, using the conversation history as input. These approaches can generate coherent, diverse, and generalizable responses, while avoiding tedious and time-consuming retrieval operations and providing a more flexible and natural experience. Therefore, dialogue generation models hold great research and application value.
[0079] However, current conversational systems built using generative approaches often produce meaningless and empty responses such as "I don't know" or "You're right." This is primarily due to the system's inability to understand and utilize relevant knowledge. When delving into specific topics, it tends to generate responses that lack substance and are meaningless. In real-life conversations, people typically engage in divergent thinking based on a few words or topics in the conversation, recalling relevant knowledge stored in their minds and organizing it into coherent sentences to respond. Consequently, the responses generated by existing conversational systems often lack quality, resulting in a poor user experience.
[0080] Specifically, current generative approaches for building dialogue systems generally employ a transformer-based seq2seq dialogue generation model, employing a self-attention mechanism to address long-term dependencies in text sequences. However, this also causes the model to leverage more information from earlier stages of the conversation. As conversational turns progress, the topic often shifts or even mutates. In this case, forcing the history window size can easily cause the model to reference incorrect history and generate erroneous responses. For example, the model may mix previous historical content with redundant noise into responses. Furthermore, when incorporating knowledge into dialogue generation, existing methods typically directly concatenate the knowledge representation with the dialogue history representation and feed it into the decoder to generate responses, failing to consider the complex interactions between the dialogue history and knowledge. Furthermore, the separation of the knowledge selection process from the dialogue generation process reduces the accuracy of knowledge integration during the decoding process, easily leading to knowledge confusion, fabrication, and inconsistency.
[0081] As can be seen, the accuracy of responses in conversations generated by existing conversation systems is often low, resulting in a poor user experience. Therefore, addressing these issues to improve the quality of responses in generated conversations and, in turn, enhance the user experience is a pressing technical challenge.
[0082] To address the above-mentioned shortcomings, the present application provides a knowledge dialogue generation method, which first obtains L rounds of historical dialogue sentences of the current target dialogue; and based on the topic of the target dialogue, obtains M knowledge sentences related to the topic; wherein L and M are both positive integers greater than 0; then the L rounds of historical dialogue sentences and M knowledge sentences are input into a pre-built dialogue generation model to predict the response sentences corresponding to the target dialogue; wherein the dialogue generation model is obtained by dynamically selecting knowledge based on the interaction between historical dialogues and knowledge using multiple rounds of historical dialogue data and knowledge data and then training. Then, the response words corresponding to the target dialogue can be spliced to generate the response sentences of the target dialogue. It can be seen that because the present application fully considers the complex interactive relationship between dialogue history and knowledge when generating the response words of the target dialogue using the dialogue generation model, and dynamically selects knowledge during the decoding process, it can generate high-quality responses with rich knowledge information, thereby improving the user experience.
[0083] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0084] First embodiment
[0085] See also Figure 1 , is a flow chart of a knowledge dialogue generation method provided in this embodiment, the method comprising the following steps:
[0086] S101: Obtain L rounds of historical dialogue sentences of the current target dialogue; and according to the topic of the target dialogue, obtain M knowledge sentences related to the topic; wherein L and M are both positive integers greater than 0.
[0087] In this embodiment, any conversation in which a reply statement is generated using this embodiment is defined as a target conversation text. Furthermore, this embodiment does not restrict the language type of the target conversation; for example, the target conversation can be a Chinese or English conversation. Accordingly, this embodiment does not restrict the language type of the target conversation text; for example, the target conversation text can be Chinese or English. Furthermore, this embodiment does not restrict the length of the target conversation; for example, the target conversation can be a sentence or a paragraph.
[0088] It is understandable that the target conversation can be obtained through recording or other means according to actual needs. For example, the voice of telephone calls in people's daily lives or the recordings of instant messaging software can be used as the target conversation voice.
[0089] It should be noted that in order to better integrate knowledge and improve the response quality of the generated target dialogue, this application pre-constructs a multi-round dialogue corpus composed of multi-round dialogue materials and a knowledge corpus composed of knowledge corpus. Among them, the multi-round dialogue corpus can include multi-round historical dialogues in various fields (such as education, sports, food, etc.), which can be obtained from various network platforms, or multi-round historical dialogues can be constructed by manually writing annotated data sets.
[0090] The knowledge corpus is constructed based on the topics of multiple rounds of conversations in various fields (such as education, sports, food, etc.) (for example, the topic of a discussion about an athlete "Zhang San" in the sports field is the athlete), and links to corresponding related articles and encyclopedia knowledge documents. For example, it can be connected to articles that introduce the athlete's sports career and other related articles.
[0091] Furthermore, for each conversation topic, information retrieval methods such as reverse index lookup can be used to retrieve relevant knowledge paragraphs from the knowledge corpus to build a knowledge base. For example, this could include but is not limited to the first paragraph and article titles of the first five articles found, as well as the first ten sentences of the encyclopedia page corresponding to the topic.
[0092] On this basis, in order to improve the quality of responses to the generated target dialogue and thus improve the user experience, this application first needs to obtain L rounds of historical dialogue sentences of the target dialogue, and according to the topic of the target dialogue, obtain M knowledge sentences related to the topic from the knowledge base to execute the subsequent step S102, where L and M are both positive integers greater than 0.
[0093] S102: Input L rounds of historical dialogue sentences and M knowledge sentences into a pre-built dialogue generation model to predict the response sentences corresponding to the target dialogue; wherein, the dialogue generation model is trained by dynamically selecting knowledge based on the interaction between historical dialogues and knowledge using multiple rounds of historical dialogue data and knowledge data.
[0094] In this embodiment, after obtaining L rounds of historical dialogue sentences and M knowledge sentences of the target dialogue through step S101, in order to improve the quality of generating the target dialogue response, the L rounds of historical dialogue sentences and M knowledge sentences can be further input into a pre-built dialogue generation model to predict the response sentences corresponding to the target dialogue.
[0095] Among them, it should be noted that in order to improve the response quality of the generated target dialogue, this application pre-constructs a dialogue generation model. Since the dialogue generation model uses multiple rounds of historical dialogue data and knowledge data, and dynamically selects knowledge based on the interaction between historical dialogues and knowledge, it is trained. Therefore, when generating the response words of the target dialogue, the complex interactive relationship between the dialogue history and knowledge is fully considered, and the knowledge is dynamically selected during the decoding process, so that high-quality responses with rich knowledge information can be generated, thereby improving the user experience.
[0096] Furthermore, it should be noted that this application does not limit the specific structure of the dialogue generation model. A preferred implementation method is as follows: Figure 2 As shown, the dialogue generation model may include, but is not limited to, an input layer, an encoding layer (a transformer-based encoder), a dialogue history encoding layer, and a knowledge interaction encoding layer. The specific training process of the dialogue generation model can be found in the detailed description of the second embodiment below.
[0097] On this basis, an optional implementation method is that the specific implementation process of "inputting L rounds of historical dialogue sentences and M knowledge sentences into the pre-built dialogue generation model to predict the response sentences corresponding to the target dialogue" in this step S102 may include the following steps S1021-S1024:
[0098] Step S1021: Input the character vectors or word vectors of the L-round historical dialogue sentences and the vector representations of the M knowledge sentences into the input layer of the dialogue generation model to obtain the input vectors of the L-round historical dialogue sentences and the input vectors of the M knowledge sentences.
[0099] Specifically, in this implementation, after obtaining L historical conversation sentences and M knowledge sentences from the target conversation, existing or future feature extraction methods can be used to extract the character vectors or word vectors contained in each sentence in the L historical conversation sentences, as well as the vector representations of the M knowledge sentences. The extracted character vectors or word vectors for the L historical conversation sentences and the vector representations of the M knowledge sentences are then input into the input layer of the conversation generation model, resulting in input vectors for the L historical conversation sentences and the M knowledge sentences, which are then used to execute the subsequent step S1022.
[0100] For example, Figure 2 As shown, assuming that the word vector or word vector of the first round of historical dialogue sentences extracted is w1 、 w2 、 w3 Wait until the word vector or word vector of the L-th round of historical dialogue sentences is extracted w1 、 w2 、 w3etc., and the vector representations corresponding to the M extracted knowledge sentences are respectively k1 、 k2 … kM Then the word vector or term vector of the first round of historical dialogue sentences can be transferred to the word vector or term vector of the Lth round of historical dialogue sentences ( w1 、 w2 、 w3 etc.) and the vector representations corresponding to the M knowledge sentences ( k1 、 k2 … kM ) are jointly input into the input layer of the dialogue generation model to obtain the input vectors of L rounds of historical dialogue sentences and the input vectors of M knowledge sentences.
[0101] Step S1022: Input the input vectors of the L-round historical dialogue sentences and the input vectors of the M knowledge sentences into the encoding layer of the dialogue generation model to obtain the encoding vectors of the L-round historical dialogue sentences and the encoding vectors of the M knowledge sentences.
[0102] In this implementation, the word vectors or term vectors of the L-round historical dialogue sentences and the vector representations of the M knowledge sentences are input into the input layer of the dialogue generation model through step S1021. After obtaining the input vectors of the L-round historical dialogue sentences and the input vectors of the M knowledge sentences, the input vectors of the L-round historical dialogue sentences and the input vectors of the M knowledge sentences can be further input into the encoding layer of the dialogue generation model (such as Figure 2 The transformer-based encoder in is used for encoding, such as Figure 2 As shown, we get the encoding vectors of L rounds of historical dialogue sentences and the encoding vectors of M knowledge sentences (such as Figure 2 k′1, k′2…k′ in M ) to execute subsequent steps S1023 and S1024.
[0103] Step S1023: Input the encoding vector of the L-round historical dialogue sentence into the dialogue history encoding layer of the dialogue generation model to perform feature enhancement to obtain the enhanced feature vector of the L-round historical dialogue sentence.
[0104] In this implementation, after obtaining the encoding vectors of the L-round historical dialogue sentences in step S1022, the encoding vectors of the L-round historical dialogue sentences can be further input into the dialogue history encoding layer of the dialogue generation model (e.g., Figure 2 The transformer-based encoder in
[15] is used to perform feature enhancement processing through a series of operations such as history window slicing, semantic dependency tree construction, and dialogue history fusion. The feature vector of the enhanced L-round historical dialogue sentence is obtained and defined as Hs , used to execute subsequent step S1024.
[0105] Specifically, in real chat scenarios, when people respond to conversations, they often refer to multiple related fragments of speech in previous conversation histories. These discourses are organized according to certain logical structural relationships. Mining the discourse structure will help improve the semantic understanding of the conversation. Therefore, this application first proposes a historical window slicing mechanism in long-term multi-round conversations. The historical conversation is sliced in chronological order. The earlier the historical window, the more historical information it contains, and the more recent the historical window, the shorter but more urgent the conversation intention. This ensures that long-term historical information dependencies can be considered while satisfying short-term intentions first.
[0106] The historical window slicing mechanism can be to input the encoding vector of L rounds of historical dialogue sentences into the dialogue history encoding layer, and then use a dynamic window of size Lt to sample t historical dialogue segments in the L rounds of historical dialogue sentences in the order from near to far, and define them as p1, p2...p t , where t is a positive integer greater than 0 and not less than L-1.
[0107] Then, construct these t historical dialogue segments p1, p2...p t The corresponding semantic dependency trees are as follows: Figure 2 As shown, these semantic dependency trees are the t historical dialogue segments p1, p2...p t The semantic dependency trees obtained after semantic dependency parsing can help understand the coherence of the conversation context, enhance the semantic expression of the conversation history, and calculate the historical conversation matrix corresponding to each of the t historical conversation segments based on these semantic dependency trees.
[0108] Among them, for the t-th historical dialogue segment p t , it can be defined as a historical dialogue segment consisting of t sentences, that is, p t =[s1, s2, ..., s n ], where s n Represents the encoding vector of the nth round of historical dialogue sentences, where n is a positive integer greater than 0. Then construct a sentence-level attention matrix A. Each element (a, b) in the matrix represents the probability value of sentence a being the parent node of sentence b. The specific calculation formula is as follows:
[0109]
[0110] Among them, sentence a and sentence b represent p respectively. t The encoding vector of any two historical dialogue sentences in ; ⊙ represents the dot product operation.
[0111] On this basis, we can calculate p t The encoding vector s of the jth historical dialogue sentence in j The probability value r as the root nodej , the specific calculation formula is as follows:
[0112]
[0113] Among them, s j [o] indicates p t The encoding vector s of the jth historical dialogue sentence in j Each element in .
[0114] In this way, when constructing the t-th historical dialogue segment p t When constructing the corresponding semantic dependency tree, we can first select a root node probability value (r j ) is inserted into the tree with the largest encoding vector of the historical dialogue sentence as the root, and then the child node with the largest probability (i.e., calculated using the above formula A(a, b)) when the discourse node is the parent node is selected from the attention matrix A as the child node, and linked to the parent node. The above steps are repeated until all nodes are inserted into the tree. The tree is regarded as a directed acyclic graph with child nodes pointing to parent nodes, such as Figure 2 As shown, when there is an edge between any nodes i and j in the graph, the weight is A(i, j), based on which the adjacency matrix can be constructed After aggregating the adjacent sentences of the encoding vector si of the i-th historical dialogue sentence in the tree, the aggregation result is expressed as:
[0115]
[0116] in, is the updated node s i The aggregation result is represented by .
[0117] Similarly, we can aggregate the updated aggregation result representation corresponding to other nodes in the tree (i.e., the encoding vectors of historical conversation sentences), and then after all nodes are subjected to the maximum pooling operation, we can get the t-th historical conversation segment p t The corresponding window representation of the semantic dependency tree is:
[0118]
[0119] Furthermore, GRU can be used to sequentially fuse the speech segments of all historical windows (i.e., t historical dialogue segments p1, p2...p t ), the hidden state of each time step is expressed as like Figure 2 The specific calculation formula is as follows:
[0120]
[0121] Then After stacking, these t historical dialogue fragments p1, p2...p t The corresponding historical dialogue matrix is defined as H s For example, suppose each is a row of m-dimensional vectors, then After stacking, we can form the m×t dimension historical dialogue matrix H s .
[0122] Considering that the most recent conversation history segment usually contains the user's most urgent intention, its corresponding encoding vector is defined as S. In actual conversation scenarios, the reply content often refers to the previous speech segment to varying degrees, so the historical conversation matrix H can be calculated s Mutual attention between the encoding vector S of the most recent conversation segment:
[0123] F=tanh(H s T W F S)
[0124] H c =tanh(W s S+(W c H s )F)
[0125] α=softmax(wH c )
[0126] Among them, W F 、W s 、W c Represents the parameter weight matrix, which can be trained according to the actual situation; α=(α1,α2,...,α t ), where α1, α2,...,α t Represents the hidden state of t historical dialogue segments respectively The weight of .
[0127] In this way, using α1, α2, ..., α t The hidden state of t historical dialogue segments After weighted summation, the feature vector of the fused L-round historical dialogue sentence can be obtained and defined as H′ s , serves as the feature vector of the enhanced L-round historical dialogue sentence, which is used to execute the subsequent step S1024. This allows the mutual attention mechanism to remove irrelevant information from longer historical dialogue sentences, adaptively select important dialogue history windows, and avoid noise interference.
[0128] Step S1024: Input the enhanced feature vectors of the L-round historical dialogue sentences and the encoding vectors of the M knowledge sentences into the knowledge interaction encoding layer of the dialogue generation model for interactive encoding to obtain the reply sentences corresponding to the target dialogue.
[0129] In this implementation, the encoding vectors of M knowledge sentences are obtained through step S1022 (e.g. Figure 2 k′1, k′2...k′ in M ), and the enhanced feature vector H′ of the L-round historical dialogue sentence is obtained through step S1023 s Finally, the enhanced feature vectors of L historical dialogue sentences and the encoding vectors of M knowledge sentences can be input into the knowledge interaction encoding layer of the dialogue generation model for interactive encoding. In the decoding process, the knowledge sentences can be dynamically selected to obtain high-quality response sentences with rich knowledge information corresponding to the target dialogue.
[0130] Specifically, if Figure 2 As shown, the knowledge interaction encoding layer may include but is not limited to a multi-head attention layer, a knowledge interaction fusion attention layer, and a feedforward neural network layer. When generating the jth reply word, the feature vector H′ of the enhanced L-round historical dialogue sentence can be obtained. s The sequence of the j-1 response words currently obtained (here defined as Y j-1 , and Y j-1 =[y1, y2, ..., y j-1 ]) Input the knowledge interaction encoding layer for splicing, and get the splicing vector, which is defined as H l-1 , that is, H l-1 =[H′ s ; Y j-1 ], then after inputting it into the multi-head attention layer and normalizing it, the first decoding vector can be obtained and defined as h l ,like Figure 2 The specific calculation formula is as follows:
[0131] h l =LayerNorm(H l-1 +MHAtt(H l-1 ))
[0132] Among them, MHAtt(·) represents the multi-head attention layer; LayerNorm(·) represents the normalization operation. Both can be implemented using the Transformer decoder, and the specific implementation process will not be repeated here.
[0133] Furthermore, since the encoding vectors of M knowledge sentences (such as Figure 2 k′1, k′2...k′ inM ) are closely related to the response generation, so they need to be sorted by importance to avoid the most relevant candidate sentences being ignored. To this end, the first decoding vector h l and the encoding vectors of M knowledge sentences (such as Figure 2 k′1, k′2...k′ in M ) Input knowledge interaction fusion attention layer, such as Figure 2 As shown, to calculate the encoding vector of each knowledge sentence and the dialogue history and current decoded reply content h l The attention value (i.e. weight value) is calculated as follows:
[0134]
[0135] Among them, W k , W h are all learnable parameters; k′ i represents the encoding vector of the i-th knowledge sentence; k″ represents the encoding vector of other knowledge sentences except the i-th knowledge sentence.
[0136] In this way, according to the importance of different knowledge sentences to the current dialogue content (i.e., weight value α(k′ i ), we can use the weight value to perform weighted summation on each knowledge sentence to obtain the updated knowledge representation C corresponding to the M knowledge sentences:
[0137]
[0138] Then, using the gating mechanism, the updated knowledge representation C corresponding to the M training knowledge sentences and the currently obtained j-1 response word sequence Y are processed through the feedforward neural network layer. j-1 Perform weighted and normalized processing to generate the jth reply word corresponding to the target dialogue. The specific calculation formula is as follows:
[0139] g=sigmoid(W g [h l , C]+b g )
[0140] y j-1 =LayerNorm(y j-1 +gh l +(1-g)C)
[0141] y j =LayerNorm(y j-1 +FFN(y j-1 ))
[0142] Among them, g represents the gating unit. When g is 0, the content generated at this time step is represented by the updated knowledge representation C corresponding to the knowledge sentence and the word Y generated in the previous round. j-1 It is determined that when g is 1, no knowledge information is introduced when generating the j-th response word; FFN(·) represents the feed-forward neural network.
[0143] By analogy, each response word included in the response sentence corresponding to the target dialogue can be predicted. For example, assume that the sequence of response words already generated by the dialogue generation model is "You too", and then after the model outputs the response word "ah" and generates a termination symbol to stop, it can be determined that the response sentence corresponding to the target dialogue is the sentence "You too ah".
[0144] In this way, by executing the above steps S101 - S102, it is possible to dynamically select effective historical segments in long-term multi-round dialogues, integrate external knowledge in the process of generating coherent responses through the interaction between the dialogue history and knowledge, and finally generate responses with rich knowledge and content, thereby improving the user experience.
[0145] In summary, a knowledge dialogue generation method provided in this embodiment first obtains L rounds of historical dialogue sentences of the current target dialogue; and obtains M knowledge sentences related to the theme according to the theme of the target dialogue; where L and M are both positive integers greater than 0; then inputs the L rounds of historical dialogue sentences and M knowledge sentences into a pre-constructed dialogue generation model to predict the response sentence corresponding to the target dialogue; the dialogue generation model is trained by using multi-round historical dialogue corpus and knowledge corpus, and dynamically selects knowledge according to the interaction between the historical dialogue and knowledge. Then, the response words corresponding to the target dialogue can be concatenated to generate the response sentence of the target dialogue. It can be seen that since this application fully considers the complex interaction relationship between the dialogue history and knowledge when using the dialogue generation model to generate the response words of the target dialogue, and dynamically selects knowledge during the decoding process, it can pre-generate high-quality responses with rich knowledge information, thereby improving the user experience.
[0146] Second embodiment
[0147] This embodiment will introduce the construction process of the dialogue generation model mentioned in the above embodiment. Specifically, it can include the following steps S201 - S202:
[0148] S201: Obtain L rounds of training historical dialogue sentences of the training dialogue, and obtain M training knowledge sentences related to the training theme according to the training theme of the training dialogue.
[0149] In this embodiment, in order to construct a dialogue generation model, it is necessary to collect a large number of training dialogues in advance, and by executing a similar process to the above-mentioned step S101, replace the "target dialogue" with the "training dialogue" to obtain L rounds of training history dialogue sentences of the training dialogue, and obtain M training knowledge sentences related to the training topic based on the training topic of the training dialogue. For example, L rounds of training history dialogue sentences of the training dialogue can be obtained from websites in various languages such as Chinese, English, and Japanese, and M training knowledge sentences related to the training topic can be obtained based on the training topic of the training dialogue. In addition, after obtaining the L rounds of training history dialogue sentences of the training dialogue and the M training knowledge sentences related to the training topic, it is also necessary to manually mark the actual response results of the training dialogue for executing the subsequent step S202.
[0150] S202: Inputting L rounds of training history dialogue sentences and M training knowledge sentences into the initial dialogue generation model, and training to obtain the dialogue generation model.
[0151] After obtaining the L rounds of training history dialogue sentences and M training knowledge sentences of the training dialogue through step S201, further, a similar process can be performed to replace the "target dialogue" with "training dialogue", "L rounds of history dialogue sentences" with "L rounds of training history dialogue sentences", "M knowledge sentences" with "M training knowledge sentences", etc., by executing a similar process to the above step S102, and input the L rounds of training history dialogue sentences and M training knowledge sentences into the initial dialogue generation model, predict the various training response words corresponding to the training dialogue, and then train the initial dialogue generation model based on the obtained various training response words and the actual response results of the training dialogue and the preset loss function to generate a dialogue generation model.
[0152] Among them, the initial dialogue generation model includes but is not limited to the input layer, encoding layer, dialogue history encoding layer, and knowledge interaction encoding layer.
[0153] Specifically, in an optional implementation manner, the specific implementation process of step S202 may include the following steps A1-A5:
[0154] Step A1: Input the character vectors or word vectors of L rounds of training history dialogue sentences and the vector representations of M training knowledge sentences into the input layer to obtain sample input vectors of L rounds of training history dialogue sentences and sample input vectors of M training knowledge sentences.
[0155] Step A2: Input the sample input vectors of L rounds of training history dialogue sentences and the sample input vectors of M training knowledge sentences into the encoding layer to obtain the encoding vectors of L rounds of training history dialogue sentences and the encoding vectors of M training knowledge sentences.
[0156] Step A3: Input the encoding vector of the L-round training history dialogue sentence into the dialogue history encoding layer to perform feature enhancement to obtain the enhanced feature vector of the L-round training history dialogue sentence.
[0157] First, the encoding vectors of L rounds of training history dialogue sentences can be input into the dialogue history encoding layer, and a dynamic window of size Lt is used to sample t historical dialogue segments in the L rounds of training history dialogue sentences in order from near to far; where t is a positive integer greater than 0 and not less than L-1.
[0158] Then, a semantic dependency tree corresponding to each of the t historical dialogue segments is constructed, and based on the semantic dependency tree, the historical dialogue matrix corresponding to the t historical dialogue segments is calculated.
[0159] Next, the mutual attention between the historical dialogue matrix corresponding to the t historical dialogue segments and the encoding vector of the L-th round of training historical dialogue sentences is calculated. Based on the obtained mutual attention, the hidden layer states of the t historical dialogue segments are weighted summed to obtain the feature vector of the fused L-th round of training historical dialogue sentences.
[0160] Step A4: Input the enhanced feature vectors of the L rounds of training history dialogue sentences and the encoding vectors of the M training knowledge sentences into the knowledge interaction coding layer for interactive coding to obtain the training response sentences corresponding to the training dialogue.
[0161] Among them, the knowledge interaction encoding layer includes but is not limited to a multi-head attention layer, a knowledge interaction fusion attention layer and a feedforward neural network layer. First, the feature vectors of the enhanced L-round training history dialogue sentences and the currently obtained training response word sequence can be input into the knowledge interaction encoding layer for splicing to obtain a splicing vector. Then, the splicing vector is input into the multi-head attention layer and normalized to obtain a first decoding vector. Next, the first decoding vector and the encoding vectors of the M training knowledge sentences are input into the knowledge interaction fusion attention layer to obtain the weight values corresponding to the M training knowledge sentences, and the weight values are used to perform weighted summation on the M training knowledge sentences to obtain the updated knowledge representations corresponding to the M training knowledge sentences. Then, a gating mechanism can be used to perform weighted and normalized processing on the updated knowledge representations corresponding to the M training knowledge sentences and the currently obtained training response word sequence through the feedforward neural network layer to generate the various words contained in the training response sentences corresponding to the training dialogue.
[0162] It should be noted that the execution process of the above steps A1-A4 is similar to the execution process of steps S1021-S1024 in the first embodiment, except that the "target dialogue" is replaced by "training dialogue", and the L rounds of historical dialogue sentences and M knowledge sentences of the target dialogue are replaced by the L rounds of training historical dialogue sentences and M training knowledge sentences of the training dialogue respectively. The specific implementation process can be found in the introduction of the first embodiment, and will not be repeated here.
[0163] Step A5: The initial dialogue generation model is trained using the training response sentences corresponding to the obtained training dialogues, the real response results corresponding to the training dialogues, and the preset loss function to obtain a dialogue generation model.
[0164] In this implementation, L rounds of training history dialogue sentences and M training knowledge sentences from a training dialogue can be sequentially extracted from the training data as inputs to the initial dialogue generation model, so as to obtain training response sentences corresponding to the training dialogue through step A4. Multiple rounds of model training are performed, and the training response sentences corresponding to the training dialogue obtained in each round of training are compared with the true response results corresponding to the manually annotated training dialogue. The model parameters are updated based on the difference between the two until a preset condition is met. For example, the value of the preset loss function (defined here as L) is very small and basically unchanged. In this case, the model parameter update is stopped, the training of the dialogue generation model is completed, and a trained dialogue generation model is generated.
[0165] In order to enable the model to learn the correct knowledge representation during model training, this embodiment introduces the knowledge loss function L knowledge , and define the loss function as the cross entropy between the predicted knowledge sentence (i.e., C mentioned in the above embodiment) and the real knowledge sentence (i.e., the knowledge text corresponding to the real reply result. After the real reply result is given, the corresponding knowledge sentence can be found from the corresponding knowledge base). Combined with the real reply result, a preset loss function is generated to jointly optimize the model. The specific calculation formula of the preset loss function L is as follows:
[0166] L=(1-λ)L NLL +λL knowledge
[0167] Among them, λ represents a learnable parameter used to adjust the weight coefficients of the two losses; L NLL Represents the loss function between the model prediction result and the true response result, which can be specifically the negative log-likelihood loss function (NLL).
[0168] On this basis, after training and generating a dialogue generation model based on L rounds of training dialogue history sentences and M training knowledge sentences related to the training topic, the generated dialogue generation model can be further verified using L rounds of verification dialogue history sentences and M verification knowledge sentences related to the verification topic. The specific verification process may include the following steps B1-B3:
[0169] Step B1: Obtain L rounds of verification history dialogue sentences of the verification dialogue, and according to the verification topic of the verification dialogue, obtain M verification knowledge sentences related to the verification topic.
[0170] In this embodiment, in order to verify the dialogue generation model, it is first necessary to obtain L rounds of verification history dialogue sentences of the verification dialogue, and according to the verification topic of the verification dialogue, obtain M verification knowledge sentences related to the verification topic. The verification dialogue refers to the dialogue information for performing generation model type verification. After obtaining the L rounds of verification history dialogue sentences of these verification dialogues and the M verification knowledge sentences related to the verification topic, the real response marking results corresponding to each verification dialogue can be manually marked, and then the subsequent step B2 can be continued.
[0171] Step B2: Input L rounds of verification history dialogue sentences and M verification knowledge sentences into the dialogue generation model to predict the verification response sentences corresponding to the verification dialogue.
[0172] After obtaining L rounds of verification history dialogue sentences and M verification knowledge sentences related to the verification topic through step B1, the L rounds of verification history dialogue sentences and M verification knowledge sentences can be further input into the dialogue generation model to predict the verification response sentences corresponding to the verification dialogue to execute the subsequent step B3.
[0173] Step B3: When the verification response statement corresponding to the verification dialogue is inconsistent with the actual response result corresponding to the verification dialogue, the verification dialogue is used again as a training dialogue to update the dialogue generation model to obtain an updated dialogue generation model.
[0174] After obtaining the verification response statement corresponding to the verification dialogue through step B2, if the verification response statement corresponding to the verification dialogue is inconsistent with the actual response result corresponding to the verification dialogue (such as manually marking the actual response marking result corresponding to each verification dialogue), the verification dialogue can be used again as a training dialogue, and the parameters of the dialogue generation model can be updated to obtain an updated dialogue generation model.
[0175] Through the above embodiment, the dialogue generation model can be effectively verified using the L rounds of verification history dialogue sentences of the verification dialogue and the M verification knowledge sentences related to the verification topic. When the verification reply sentence corresponding to the predicted verification dialogue is inconsistent with the actual reply result corresponding to the verification dialogue, the dialogue generation model can be adjusted and updated in time, which helps to improve the prediction precision and accuracy of the dialogue generation model.
[0176] Third embodiment
[0177] This embodiment will introduce a knowledge dialogue generation device. For related content, please refer to the above method embodiment.
[0178] See also Figure 3 , is a schematic diagram of the composition of a knowledge dialogue generation device provided in this embodiment, the device 300 includes:
[0179] The first acquisition unit 301 is configured to acquire L rounds of historical conversation sentences of the current target conversation; and based on the topic of the target conversation, acquire M knowledge sentences related to the topic; where L and M are both positive integers greater than 0;
[0180] The first prediction unit 302 is used to input the L rounds of historical dialogue sentences and the M knowledge sentences into a pre-built dialogue generation model to predict the response sentence corresponding to the target dialogue; the dialogue generation model is trained by dynamically selecting knowledge based on the interaction between historical dialogues and knowledge using multiple rounds of historical dialogue data and knowledge data.
[0181] In one implementation of this embodiment, the apparatus further includes:
[0182] A second acquisition unit is configured to acquire L rounds of training history dialogue sentences of the training dialogue, and acquire M training knowledge sentences related to the training topic according to the training topic of the training dialogue;
[0183] A training unit, configured to input the L rounds of training history dialogue sentences and the M training knowledge sentences into an initial dialogue generation model, and train the dialogue generation model;
[0184] The initial dialogue generation model includes an input layer, an encoding layer, a dialogue history encoding layer, and a knowledge interaction encoding layer.
[0185] In one implementation of this embodiment, the training unit includes:
[0186] A first input subunit is configured to input the character vectors or word vectors of the L rounds of training history dialogue sentences and the vector representations of the M training knowledge sentences into the input layer to obtain sample input vectors of the L rounds of training history dialogue sentences and sample input vectors of the M training knowledge sentences;
[0187] A second input subunit is configured to input the sample input vectors of the L rounds of training history dialogue sentences and the sample input vectors of the M training knowledge sentences into the encoding layer to obtain encoding vectors of the L rounds of training history dialogue sentences and encoding vectors of the M training knowledge sentences;
[0188] A first enhancement subunit is configured to input the encoding vector of the L-round training history conversation sentence into the conversation history encoding layer to perform feature enhancement to obtain an enhanced feature vector of the L-round training history conversation sentence;
[0189] A first encoding subunit is configured to input the enhanced feature vectors of the L rounds of training history dialogue sentences and the encoding vectors of the M training knowledge sentences into the knowledge interaction encoding layer to perform interactive encoding to obtain training reply sentences corresponding to the training dialogues;
[0190] The training subunit is used to train the initial dialogue generation model using the training response sentences corresponding to the training dialogue, the real response results corresponding to the training dialogue, and the preset loss function to obtain the dialogue generation model.
[0191] In one implementation of this embodiment, the first enhancer unit includes:
[0192] A sampling subunit is configured to input the encoding vectors of the L rounds of training history conversation sentences into the conversation history encoding layer, and use a dynamic window of size Lt to sample the L rounds of training history conversation sentences in order from near to far to obtain t historical conversation segments; where t is a positive integer greater than 0 and not less than L-1;
[0193] A first calculation subunit is configured to construct a semantic dependency tree corresponding to each of the t historical conversation segments, and calculate a historical conversation matrix corresponding to the t historical conversation segments based on the semantic dependency tree;
[0194] The second computing subunit is configured to calculate the mutual attention between the historical dialogue matrices corresponding to the t historical dialogue segments and the encoding vectors of the historical dialogue sentences of the L-th round of training, and perform weighted summation on the hidden layer states of the t historical dialogue segments based on the obtained mutual attention to obtain the fused feature vectors of the historical dialogue sentences of the L-th round of training.
[0195] In one implementation of this embodiment, the knowledge interaction encoding layer includes a multi-head attention layer, a knowledge interaction fusion attention layer, and a feedforward neural network layer; the first encoding subunit includes:
[0196] A splicing subunit, configured to input the enhanced feature vector of the L-round training history dialogue sentence and the currently obtained training reply word sequence into the knowledge interaction encoding layer for splicing to obtain a splicing vector;
[0197] a normalization subunit, configured to input the concatenated vector into the multi-head attention layer and perform normalization processing to obtain a first decoding vector;
[0198] a third input subunit, configured to input the first decoding vector and the encoding vectors of the M training knowledge sentences into the knowledge interaction fusion attention layer, obtain weight values corresponding to the M training knowledge sentences, and use the weight values to perform weighted summation on the M training knowledge sentences to obtain updated knowledge representations corresponding to the M training knowledge sentences;
[0199] The generation subunit is used to utilize a gating mechanism to weight and normalize the updated knowledge representations corresponding to the M training knowledge sentences and the currently obtained training response word sequence through the feedforward neural network layer to generate a training response sentence corresponding to the training dialogue.
[0200] In one implementation of this embodiment, the apparatus further includes:
[0201] A third acquisition unit is configured to acquire L rounds of verification dialogue sentences of the verification dialogue, and acquire M verification knowledge sentences related to the verification topic according to the verification topic of the verification dialogue;
[0202] A second prediction unit is configured to input the L rounds of verification history dialogue sentences and the M verification knowledge sentences into the dialogue generation model to predict a verification reply sentence corresponding to the verification dialogue;
[0203] An updating unit is used to, when the verification response statement corresponding to the verification dialogue is inconsistent with the actual response result corresponding to the verification dialogue, use the verification dialogue pair as the training dialogue again to update the dialogue generation model to obtain an updated dialogue generation model.
[0204] In one implementation of this embodiment, the first prediction unit includes:
[0205] a fourth input subunit, configured to input the character vectors or word vectors of the L rounds of historical dialogue sentences and the vector representations of the M knowledge sentences into the input layer of the dialogue generation model, thereby obtaining input vectors of the L rounds of historical dialogue sentences and input vectors of the M knowledge sentences;
[0206] a fifth input subunit, configured to input the input vectors of the L rounds of historical dialogue sentences and the input vectors of the M knowledge sentences into the encoding layer of the dialogue generation model to obtain encoding vectors of the L rounds of historical dialogue sentences and encoding vectors of the M knowledge sentences;
[0207] A second enhancement subunit is configured to input the encoding vector of the L-round historical dialogue sentence into the dialogue history encoding layer of the dialogue generation model to perform feature enhancement to obtain an enhanced feature vector of the L-round historical dialogue sentence;
[0208] The second encoding sub-unit is used to input the enhanced feature vectors of the L-round historical dialogue sentences and the encoding vectors of the M knowledge sentences into the knowledge interaction encoding layer of the dialogue generation model to perform interactive encoding to obtain the reply sentence corresponding to the target dialogue.
[0209] Furthermore, an embodiment of the present application also provides a knowledge dialogue generation device, comprising: a processor, a memory, and a system bus;
[0210] The processor and the memory are connected via the system bus;
[0211] The memory is used to store one or more programs, and the one or more programs include instructions. When the instructions are executed by the processor, the processor executes any one of the implementation methods of the above-mentioned knowledge dialogue generation method.
[0212] Furthermore, an embodiment of the present application also provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a terminal device, the terminal device executes any one of the implementation methods of the above-mentioned knowledge dialogue generation method.
[0213] Furthermore, an embodiment of the present application also provides a computer program product, which, when running on a terminal device, enables the terminal device to execute any one of the implementation methods of the above-mentioned knowledge dialogue generation method.
[0214] Through the description of the above embodiments, it can be seen that those skilled in the art can clearly understand that all or part of the steps in the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network communication device such as a media gateway, etc.) to execute the methods described in each embodiment of the present application or certain parts of the embodiments.
[0215] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Reference can be made to the common and similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the methods.
[0216] It should also be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.
[0217] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present application. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application is not limited to the embodiments shown herein, but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A knowledge dialogue generation method, characterized in that: include: Get L rounds of historical dialogue sentences for the current target dialogue; And according to the topic of the target conversation, obtain M knowledge sentences related to the topic; Both L and M are positive integers greater than 0; Input the L rounds of historical dialogue sentences and the M knowledge sentences into a pre-built dialogue generation model to predict the response sentence corresponding to the target dialogue; the dialogue generation model is trained by dynamically selecting knowledge based on the interaction between historical dialogue and knowledge using multiple rounds of historical dialogue corpus and knowledge corpus; The dialogue generation model is constructed as follows: Obtain L rounds of training history dialogue sentences of the training dialogue, and according to the training topic of the training dialogue, obtain M training knowledge sentences related to the training topic; Inputting the L rounds of training history dialogue sentences and the M training knowledge sentences into the initial dialogue generation model to train and obtain the dialogue generation model; The initial dialogue generation model includes an input layer, an encoding layer, a dialogue history encoding layer, and a knowledge interaction encoding layer; The L rounds of historical dialogue sentences and the M knowledge sentences are input into a pre-built dialogue generation model to predict the response sentences corresponding to the target dialogue, including: Inputting the character vectors or word vectors of the L-round historical dialogue sentences and the vector representations of the M knowledge sentences into the input layer of the dialogue generation model to obtain the input vectors of the L-round historical dialogue sentences and the input vectors of the M knowledge sentences; Inputting the input vectors of the L rounds of historical dialogue sentences and the input vectors of the M knowledge sentences into the encoding layer of the dialogue generation model to obtain encoding vectors of the L rounds of historical dialogue sentences and encoding vectors of the M knowledge sentences; Inputting the encoding vector of the L-round historical conversation sentence into the conversation history encoding layer of the conversation generation model to perform feature enhancement to obtain an enhanced feature vector of the L-round historical conversation sentence; The enhanced feature vectors of the L-round historical dialogue sentences and the encoding vectors of the M knowledge sentences are input into the knowledge interaction encoding layer of the dialogue generation model for interactive encoding to obtain the reply sentences corresponding to the target dialogue.
2. The method according to claim 1, characterized in that Inputting the L rounds of training history dialogue sentences and the M training knowledge sentences into the initial dialogue generation model to train the dialogue generation model includes: Inputting the character vectors or word vectors of the L rounds of training history dialogue sentences and the vector representations of the M training knowledge sentences into the input layer to obtain sample input vectors of the L rounds of training history dialogue sentences and sample input vectors of the M training knowledge sentences; Inputting the sample input vectors of the L rounds of training history dialogue sentences and the sample input vectors of the M training knowledge sentences into the encoding layer to obtain encoding vectors of the L rounds of training history dialogue sentences and encoding vectors of the M training knowledge sentences; Inputting the encoding vector of the L-round training history conversation sentence into the conversation history encoding layer to perform feature enhancement to obtain the enhanced feature vector of the L-round training history conversation sentence; Inputting the enhanced feature vectors of the L rounds of training history dialogue sentences and the encoding vectors of the M training knowledge sentences into the knowledge interaction encoding layer for interactive encoding to obtain training reply sentences corresponding to the training dialogues; The initial dialogue generation model is trained using the obtained training response sentences corresponding to the training dialogue, the real response results corresponding to the training dialogue, and a preset loss function to obtain the dialogue generation model.
3. The method according to claim 2, characterized in that Inputting the encoding vector of the L-round training history dialogue sentence into the dialogue history encoding layer to perform feature enhancement to obtain the enhanced feature vector of the L-round training history dialogue sentence includes: Input the encoding vectors of the L rounds of training history conversation sentences into the conversation history encoding layer, and use a dynamic window of size Lt to sample t historical conversation segments from the L rounds of training history conversation sentences in order from near to far, where t is a positive integer greater than 0 and not less than L-1; Constructing a semantic dependency tree corresponding to each of the t historical conversation segments, and calculating a historical conversation matrix corresponding to the t historical conversation segments based on the semantic dependency tree; Calculate the mutual attention between the historical dialogue matrix corresponding to the t historical dialogue segments and the encoding vector of the L-th round of training historical dialogue sentences, and perform weighted summation on the hidden layer states of the t historical dialogue segments based on the obtained mutual attention to obtain the fused feature vector of the L-th round of training historical dialogue sentences.
4. The method according to claim 2, characterized in that The knowledge interaction encoding layer includes a multi-head attention layer, a knowledge interaction fusion attention layer, and a feedforward neural network layer; the enhanced feature vectors of the L-round training history dialogue sentences and the encoding vectors of the M training knowledge sentences are input into the knowledge interaction encoding layer for interactive encoding to obtain the training reply sentences corresponding to the training dialogue, including: Inputting the enhanced feature vector of the L-round training history dialogue sentence and the currently obtained training reply word sequence into the knowledge interaction encoding layer for splicing to obtain a splicing vector; Input the concatenated vector into the multi-head attention layer and perform normalization processing to obtain a first decoding vector; Inputting the first decoding vector and the encoding vectors of the M training knowledge sentences into the knowledge interaction fusion attention layer to obtain weight values corresponding to the M training knowledge sentences, and using the weight values to perform weighted summation on the M training knowledge sentences to obtain updated knowledge representations corresponding to the M training knowledge sentences; Utilizing a gating mechanism, the feedforward neural network layer performs weighted and normalized processing on the updated knowledge representations corresponding to the M training knowledge sentences and the currently obtained training response word sequence to generate a training response sentence corresponding to the training dialogue.
5. The method according to claim 1, wherein The method further comprises: Obtain L rounds of verification history dialogue sentences of the verification dialogue, and according to the verification topic of the verification dialogue, obtain M verification knowledge sentences related to the verification topic; Input the L rounds of verification history dialogue sentences and the M verification knowledge sentences into the dialogue generation model to predict the verification reply sentences corresponding to the verification dialogue; When the verification response statement corresponding to the verification dialogue is inconsistent with the actual response result corresponding to the verification dialogue, the verification dialogue is used again as the training dialogue, and the dialogue generation model is updated to obtain an updated dialogue generation model.
6. A knowledge dialogue generation device, characterized in that: include: The first acquisition unit is used to obtain L rounds of historical dialogue sentences of the current target dialogue; And according to the topic of the target conversation, M knowledge sentences related to the topic are obtained; both L and M are positive integers greater than 0; A first prediction unit is configured to input the L rounds of historical dialogue sentences and the M knowledge sentences into a pre-built dialogue generation model to predict a response sentence corresponding to the target dialogue; the dialogue generation model is trained by dynamically selecting knowledge based on the interaction between historical dialogues and knowledge using multiple rounds of historical dialogue data and knowledge data; A second acquisition unit is configured to acquire L rounds of training history dialogue sentences of the training dialogue, and acquire M training knowledge sentences related to the training topic according to the training topic of the training dialogue; A training unit, configured to input the L rounds of training history dialogue sentences and the M training knowledge sentences into an initial dialogue generation model, and train the dialogue generation model; The initial dialogue generation model includes an input layer, an encoding layer, a dialogue history encoding layer, and a knowledge interaction encoding layer; The first prediction unit includes: a fourth input subunit, configured to input the character vectors or word vectors of the L rounds of historical dialogue sentences and the vector representations of the M knowledge sentences into the input layer of the dialogue generation model, thereby obtaining input vectors of the L rounds of historical dialogue sentences and input vectors of the M knowledge sentences; a fifth input subunit, configured to input the input vectors of the L rounds of historical dialogue sentences and the input vectors of the M knowledge sentences into the encoding layer of the dialogue generation model to obtain encoding vectors of the L rounds of historical dialogue sentences and encoding vectors of the M knowledge sentences; A second enhancement subunit is configured to input the encoding vector of the L-round historical dialogue sentence into the dialogue history encoding layer of the dialogue generation model to perform feature enhancement to obtain an enhanced feature vector of the L-round historical dialogue sentence; The second encoding sub-unit is used to input the enhanced feature vectors of the L-round historical dialogue sentences and the encoding vectors of the M knowledge sentences into the knowledge interaction encoding layer of the dialogue generation model to perform interactive encoding to obtain the reply sentence corresponding to the target dialogue.
7. A knowledge dialogue generation device, characterized in that: include: Processor, memory, system bus; The processor and the memory are connected via the system bus; The memory is configured to store one or more programs, wherein the one or more programs include instructions, and when the instructions are executed by the processor, the processor is enabled to perform the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device executes the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Dialogue generation method, related equipment and readable storage medium
CN114756693A
Expandable dialogue system
US20180350349A1