A dialogue reply generation method and a dialogue reply generation model system

By constructing a knowledge graph and introducing time-dimensional features and sequence graph embedding mechanisms, the problem of insufficient response quality and diversity in generative dialogue systems is solved, achieving accuracy in dialogue response generation and efficient utilization of external knowledge.

CN115357694BActive Publication Date: 2025-12-12SOUTH CHINA NORMAL UNIV +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210885006.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-26
Publication Date
2025-12-12
Estimated Expiration
2042-07-26

AI Technical Summary

Technical Problem

In existing technologies, generative dialogue systems have shortcomings in terms of response quality and diversity, especially in terms of unfluent sentences, inconsistent contextual logic, low utilization of external knowledge, and inability to accurately select different entities in knowledge triples.

Method used

By constructing a knowledge graph and introducing time-dimensional features, the knowledge graph is encoded using a sequence graph embedding mechanism. Combined with attention mechanisms and generation pointers, the probability of vocabulary generation and knowledge selection is balanced, thereby improving the accuracy and effective utilization of knowledge selection.

Benefits of technology

It improves the quality and diversity of dialogue response generation, can distinguish different entities in the knowledge graph at different times, reduces noise, and improves the utilization rate of external knowledge.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115357694B_ABST
    Figure CN115357694B_ABST
Patent Text Reader

Abstract

The application relates to a dialogue reply generation method, which comprises the following steps: S11, constructing a knowledge graph according to external knowledge; S12, encoding the knowledge graph to obtain a knowledge representation vector retaining a time dimension feature; S13, encoding a dialogue history to obtain a dialogue history hidden state vector; S21, decoding a generated word of a previous moment according to the dialogue history hidden state vector to obtain a dialogue reply hidden state vector of a current moment; S22, calculating a word table generation probability of the current moment according to the dialogue reply hidden state vector; S31, calculating an attention weight of the dialogue reply hidden state vector to the knowledge representation vector; S32, calculating a knowledge selection probability of the current moment according to the attention weight; S40, calculating a generation pointer of the current moment according to the knowledge representation vector, the attention weight and the dialogue reply hidden state vector; and S50, balancing the knowledge selection probability and the word table generation probability by using the generation pointer to obtain a final generation probability of the current moment.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of dialogue systems, and in particular to a dialogue reply generation method and a dialogue reply generation model system. BACKGROUND

[0002] A dialogue system is a computer system that can effectively converse with humans through natural language, and is a challenging task in the field of artificial intelligence. Dialogue systems often use deep learning-based methods, and can be divided into retrieval-based dialogue systems and generative dialogue systems according to different implementation methods.

[0003] A retrieval-based dialogue system mainly uses text matching technology in natural language processing to match the user's inquiry with the replies in the candidate reply library that has been constructed, and selects the one with the highest matching score as the reply to return to the user. The advantage is high controllability, and the text matching task as a natural language processing understanding task is relatively mature, and is a method widely used in the industry. However, in a retrieval-based dialogue system, the quality of the reply is often related to the quality of the candidate reply library, and a large candidate library often needs to be constructed, and it is difficult to handle the case where there is no matching reply in the candidate library, and the flexibility is low.

[0004] With the development of computer hardware and deep learning-related technologies, natural language generation tasks have gradually become feasible, and dialogue systems have gradually developed towards generation. As a natural language generation task, a generative dialogue system mainly uses a deep learning model based on sequence to sequence (Seq2Seq), which includes an encoder and a decoder. The encoder is responsible for encoding the dialogue history into a context vector, and the decoder is responsible for generating a reply according to the context vector. However, this end-to-end dialogue reply generation model has two common problems: first, the quality of the reply needs to be improved, specifically manifested as incoherent sentences and incoherent context logic; second, it is easy to generate general replies, specifically manifested as low reply diversity. Currently, structured external knowledge is often introduced to alleviate the above two problems, and the most common form of external knowledge is knowledge triples, for example, apple-color-red, apple-type-fruit.

[0005] In the prior art, the dialogue reply generation model introducing external knowledge often adopts two architectures of non-graph neural network and graph neural network. Among them, the non-graph neural network often only processes multiple knowledge triples as multiple separate texts, which is easy to appear frequently in external knowledge because an entity has multiple attributes, thereby reducing the proportion of effective knowledge. And the above model ignores the graph structure that may exist between knowledge triples, causing the loss of part of the information, and the modeling of the model on external knowledge is not sufficient, thereby reducing the quality of reply generation. On the other hand, in the ordinary graph neural network, it is usually defaulted that only one entity exists in each node, and only one fixed dimension feature is used to represent each node. However, multiple entities may exist in the nodes in many knowledge triples. If the knowledge triples are reconstructed into a knowledge graph, and the ordinary graph neural network is used to encode the knowledge graph, not only the different entities inside the same node cannot be distinguished, which cannot meet the demand of accurately selecting knowledge, but also noise is easy to be introduced, thereby reducing the effective utilization rate of external knowledge. SUMMARY

[0006] Based on this, the purpose of the present application is to provide a dialogue reply generation method capable of accurately selecting knowledge.

[0007] The present application is realized by the following technical solutions:

[0008] A dialogue reply generation method, comprising the steps of:

[0009] S11: constructing a knowledge graph according to external knowledge;

[0010] S12: encoding the knowledge graph to obtain a knowledge representation vector retaining a time dimension feature;

[0011] S13: encoding a dialogue history to obtain a dialogue history hidden state vector; wherein, step S13 is executed simultaneously with step S11 or step S12, or step S13 is executed before step S11 or after step S12;

[0012] S21: decoding a dialogue reply hidden state vector of a current time according to the dialogue history hidden state vector and a generated word of a previous time;

[0013] S22: calculating a word table generation probability of the current time according to the dialogue reply hidden state vector of the current time;

[0014] S31: calculating an attention weight of the dialogue reply hidden state vector of the current time on the knowledge representation vector; wherein, step S31 is executed after step S21;

[0015] S32: calculating a knowledge selection probability of the current time according to the attention weight of the current time;

[0016] S40: calculating a generation pointer at the current moment according to the knowledge representation vector, the attention weight at the current moment and the dialogue reply hidden state vector at the current moment; wherein, step S40 is executed after step S31;

[0017] S50: balancing the knowledge selection probability at the current moment and the vocabulary generation probability at the current moment by using the generation pointer at the current moment, to obtain a final generation probability at the current moment.

[0018] The dialogue reply generation method introduces time dimension features, encodes different entities of a knowledge graph at different moments, obtains a knowledge representation vector that retains time dimension features, is conducive to distinguishing different nodes and different entities inside the nodes, can make more fine-grained selection in subsequent knowledge selection, thereby improving the accuracy of knowledge selection and the effective utilization rate of knowledge, and further improving the quality and diversity of dialogue reply generation; in addition, the way of reconstructing external knowledge into a knowledge graph fully considers the possible graph structure between knowledge triples, can avoid the loss of part of the information when modeling, and reduces the frequency of occurrence of entities with multiple attributes, reduces unnecessary noise, and improves the utilization rate of external knowledge.

[0019] Further, step S12 specifically comprises:

[0020] word embedding is performed on the knowledge graph to obtain node embedding vectors and relation embedding vectors; the node embedding vectors are encoded by a sequence graph embedding mechanism to obtain node set hidden state vectors that retain time dimension features, and the relation embedding vectors are encoded by a bidirectional gated recurrent unit to obtain edge set hidden state vectors, and then the node set hidden state vectors and the edge set hidden state vectors are spliced to obtain the knowledge representation vector.

[0021] In order to obtain a knowledge representation vector that retains time dimension features, the sequence graph embedding mechanism is designed to encode the knowledge graph, the time dimension features of the node set are retained, the effective features of different entities inside the nodes can be extracted, and accurate knowledge selection can be made during decoding; in addition, the sequence graph embedding mechanism can be extended to other dialogue systems based on knowledge graphs, and has strong universality.

[0022] Further, the sequence graph embedding mechanism performs steps of:

[0023] S121: calculating a node intermediate vector from the node embedding vectors by a recurrent neural network, and then calculating a node hidden state vector according to the node intermediate vector;

[0024] S122: determine whether the number of times of calculating the node hidden state vector reaches a preset cycle number, if not, take the node hidden state vector as the node embedding vector, return to step S21, if yes, compose the node set hidden state vector by the node hidden state vectors of all nodes and output; wherein the preset cycle number is set to , and is a positive integer.

[0025] The sequence diagram embedding mechanism is a sequence information-oriented graph neural network, which takes a traditional GCN as a basic framework, and replaces a linear convolution kernel of the GCN with an RNN, and can preserve the time dimension feature of each node during graph convolution calculation.

[0026] Further, step S13 specifically comprises:

[0027] The dialogue history hidden state vector is obtained by encoding the dialogue history through a bidirectional gated recurrent unit. The BiGRU is used for encoding, and richer feature information can be extracted from the dialogue history.

[0028] Further, step S21 specifically comprises:

[0029] The dialogue reply hidden state vector of the current moment is obtained by decoding the dialogue history hidden state vector and the generated word of the previous moment through a gated recurrent unit.

[0030] Further, step S40 specifically comprises:

[0031] The attention weighted sum vector of the current moment is calculated according to the attention weight of the current moment, the dialogue reply hidden state vector of the current moment and the attention weighted sum vector of the current moment are spliced, and then the generated pointer of the current moment is calculated through a sigmoid activation function.

[0032] Further, it further comprises the following steps:

[0033] S60: select the word with the maximum probability value in the final generated probability of the current moment as the generated word of the current moment;

[0034] S70: determine whether the generated word of the current moment is an end symbol, if yes, execute step S80, if not, execute step S21;

[0035] S80: compose a text sequence by the generated words of all moments as a dialogue reply and output.

[0036] Further, it further comprises a parameter optimization step:

[0037] S91: initialize the network parameters of steps S11-S50, randomly divide the samples in the training set into multiple batches, optimize the network parameters by performing steps S11-S50 on the samples in the training set by batch, and perform loss calculation using a total loss function, the expression of the total loss function is:

[0038] (20)

[0039] wherein, the total loss function is, the negative log-likelihood loss function is, the relative entropy loss function is;

[0040] S92: after each iteration, perform steps S11-S50 on the samples in the test set to perform performance testing, and repeat multiple iterations until the performance no longer improves.

[0041] The application also provides a dialogue reply generation model system, comprising:

[0042] A composition module constructs a knowledge graph according to external knowledge;

[0043] A knowledge graph encoding module encodes the knowledge graph to obtain a knowledge representation vector that retains time dimension features;

[0044] A dialogue history encoding module encodes dialogue history to obtain a dialogue history hidden state vector;

[0045] A dialogue reply decoding module calculates a dialogue reply hidden state vector at the current time according to the dialogue history hidden state vector and the generated word at the previous time;

[0046] A word table generation probability calculation module calculates a word table generation probability at the current time according to the dialogue reply hidden state vector at the current time;

[0047] An attention mechanism module calculates an attention weight of the dialogue reply hidden state vector at the current time on the knowledge representation vector;

[0048] A knowledge selection probability calculation module calculates a knowledge selection probability at the current time according to the attention weight at the current time;

[0049] A generation pointer calculation module calculates a generation pointer at the current time according to the knowledge representation vector, the attention weight at the current time, and the dialogue reply hidden state vector at the current time;

[0050] A final generation probability calculation module balances the knowledge selection probability at the current time and the word table generation probability at the current time by using the generation pointer at the current time to obtain a final generation probability at the current time.

[0051] Further, the knowledge graph encoding module further comprises:

[0052] a word embedding unit, which performs word embedding on the knowledge graph to obtain a node embedding vector and a relation embedding vector;

[0053] a node set encoding unit, which encodes the node embedding vector by using a sequence graph embedding mechanism to obtain a node set hidden state vector that retains a time dimension feature;

[0054] an edge set encoding unit, which encodes the relation embedding vector by using a bidirectional gated recurrent unit to obtain an edge set hidden state vector;

[0055] a knowledge representation unit, which concatenates the node set hidden state vector and the edge set hidden state vector to obtain a knowledge representation vector.

[0056] Compared with the prior art, the dialogue reply generation method and the dialogue reply generation method model provided by the present application introduce a time dimension feature, encode different entities of a knowledge graph at different time points, are beneficial to distinguishing different nodes and different entities inside the nodes, and can make more fine-grained selection in subsequent knowledge selection. Further, the present application designs a sequence graph embedding mechanism to encode a node set in the knowledge graph, can retain the time dimension feature inside the nodes, and extract effective features of different entities inside the nodes, is beneficial to selecting correct entities in the decoding process, and thus improves the accuracy of knowledge selection and the effective utilization rate of knowledge, and further improves the quality and diversity of dialogue reply generation. In addition, the sequence graph embedding mechanism can be extended to other dialogue systems based on knowledge graphs, has strong universality, and the way of reconstructing external knowledge into a knowledge graph reduces the frequency of entities with multiple attributes, balances the weights between different knowledge at the data level, reduces unnecessary noise, and improves the utilization rate of external knowledge.

[0057] In order to better understand and implement, the present application is described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF DRAWINGS

[0058] Figure 1 A step flowchart of the dialogue reply generation method provided by the present application;

[0059] Figure 2 A network architecture diagram of the dialogue reply generation model system provided by the present application;

[0060] Figure 3 A module schematic diagram of the dialogue reply generation model system provided by the present application;

[0061] Figure 4An example graph for a sample in the DuConv dataset. DETAILED DESCRIPTION

[0062] In the prior art, the dialogue reply generation model based on the knowledge graph often has poor dialogue reply quality and low diversity, because these models encode nodes as a whole, cannot distinguish and utilize the effective features of different entities inside the nodes, resulting in inaccurate knowledge selection and ineffective utilization of knowledge. Based on this, the present application introduces time dimension features, encodes different entities of the knowledge graph at different time points, which is conducive to distinguishing different nodes and different entities inside the nodes, and making more fine-grained selection in subsequent knowledge selection. In order to obtain knowledge representation vectors that retain time dimension features, the present application designs a sequence graph embedding mechanism to encode the node set in the knowledge graph, which can retain the time dimension features inside the nodes and extract the effective features of different entities inside the nodes, which is conducive to selecting the correct entity in the decoding process, thereby improving the accuracy of knowledge selection and the effective utilization rate of knowledge.

[0063] Please refer to Figure 1 which is a step flow chart of a dialogue reply generation method provided by the present application. The dialogue reply generation method comprises the following steps:

[0064] S11: constructing a knowledge graph according to external knowledge;

[0065] S12: encoding the knowledge graph to obtain a knowledge representation vector that retains time dimension features;

[0066] S13: encoding the dialogue history to obtain a dialogue history hidden state vector; wherein, step S13 is executed simultaneously with step S11 or step S12, or step S13 is executed before step S11 or after step S12;

[0067] S21: decoding the dialogue history hidden state vector and the generated word at the previous time point to obtain a dialogue reply hidden state vector at the current time point;

[0068] S22: calculating a word table generation probability at the current time point according to the dialogue reply hidden state vector at the current time point;

[0069] S31: calculating the attention weight of the dialogue reply hidden state vector at the current time point on the knowledge representation vector; wherein, step S31 is executed after step S21;

[0070] S32: calculating a knowledge selection probability at the current time point according to the attention weight at the current time point;

[0071] S40: calculate the generation pointer of the current moment according to the knowledge representation vector, the attention weight of the current moment and the dialogue reply hidden state vector of the current moment; wherein, step S40 is executed after step S31;

[0072] S50: balance the knowledge selection probability of the current moment and the vocabulary generation probability of the current moment by using the generation pointer of the current moment, to obtain the final generation probability of the current moment; wherein, step S50 is executed after step S22, step S32 and step S40;

[0073] S60: select the word with the maximum probability value in the final generation probability of the current moment as the generation word of the current moment;

[0074] S70: judge whether the generation word of the current moment is the end symbol, if yes, execute step S80, if not, execute step S21;

[0075] S80: compose a text sequence with all the generation words of the current moment as the dialogue reply and output.

[0076] The dialogue reply generation method introducing external knowledge needs to use dialogue-knowledge parallel corpus as the data set in the modeling process, each sample in the data set includes dialogue history, dialogue reply, external knowledge and dialogue target. Among them, the dialogue history is represented as , is the sequence length of the dialogue history, is the th word in the dialogue history, ; the dialogue reply is represented as , is the sequence length of the dialogue reply, is the th word in the dialogue history, ; the external knowledge is represented as , is the total number of triples, is the th knowledge triple in the external knowledge, and has , is the total number of entities of the th knowledge triple, is the th entity of the th knowledge triple; the th knowledge triple is known as , wherein, , , are the text sequences corresponding to the head node, the relationship and the tail node in the knowledge triple respectively, and these text sequences are composed of at least one entity; the dialogue target is represented as , the topic of the dialogue process is transferred from to . The goal of the dialogue reply generation method is to maximize the probability of generating , given , i.e. .

[0077] In practical applications, only the dialogue history can be obtained according to the dialogue content, and the external knowledge needs to be extracted from a known large knowledge graph to construct knowledge triples related to the dialogue history, and then the knowledge graph corresponding to the dialogue history is reconstructed according to step S11.

[0078] In step S11, each knowledge triple in the external knowledge may have multiple relationships, and each tail node of the knowledge triple may be a head node of another knowledge triple, and most of the head nodes and tail nodes in the external knowledge are related to the dialogue target, so the external knowledge in each sample can be constructed into a knowledge graph.

[0079] Specifically, the knowledge graph is represented as . Wherein, is the node set of the knowledge graph, which is represented as , is the total number of nodes in the node set, is the th node in the node set, ; Since the node set is composed of the head node and the tail node of the knowledge triple, that is, and . is the edge set of the knowledge graph, which is represented as .

[0080] The nodes and relationships in the knowledge graph, as well as the dialogue history, are text sequences of different lengths, which need to be encoded into hidden state vectors (Hidden Variables) to extract the potential features in the text sequence.

[0081] In step S12, first, the knowledge graph constructed in step S11 is word embedded to obtain low-dimensional node embedding vectors and relationship embedding vectors. Specifically, the word embedding process of the knowledge graph is:

[0082] (1)

[0083] (2)

[0084] (3)

[0085] In the formula, Embed vectors into knowledge graphs. Embed vectors for the node set. Embedded vectors for edge sets Indicates word embedding; For the first The node embedding vector of each node. For the first The relationship embedding vector of the edge; For the first The sequence length of the nth node, which represents the nth node's sequence length. The total number of nodes contains One word; For the first The sequence length of the edges, which represents the length of the first edge. The total number of edges is One word; To hide the dimension.

[0086] Next, the node embedding vector is encoded through a sequence graph embedding mechanism to obtain the node set hidden state vector that retains the temporal dimension features, and the relation embedding vector is encoded through a bidirectional gated recurrent unit (BiGRU) to obtain the edge set hidden state vector. Then, the node set hidden state vector and the edge set hidden state vector are concatenated to obtain the knowledge representation vector.

[0087] Traditional Graph Convolutional Networks (GCNs) employ linear convolutional kernels, treating each node as a whole and ignoring the different entities that may exist within each node, thus failing to preserve the effective features of different entities. Therefore, this invention designs a sequence graph embedding mechanism to encode node embedding vectors, obtaining hidden state vectors of the node set that retain temporal dimensions. This sequence graph embedding mechanism is a sequence-oriented graph neural network that replaces the linear convolutional kernels of traditional GCNs with recurrent neural networks (RNNs). The computation process preserves the temporal dimensions of each node, enabling the differentiation of different entities within a node. This facilitates the correct selection of effective external knowledge, improving the quality and diversity of responses.

[0088] Specifically, the sequence graph embedding mechanism performs the following steps:

[0089] S121: The node intermediate vector is calculated from the node embedding vector using an RNN, and then the node hidden state vector is calculated based on the node intermediate vector; specifically, for the ... The calculation process for each node is as follows:

[0090] (4)

[0091] (5)

[0092] (6)

[0093] In the formula, This represents the current moment in the RNN encoding process, and That is, each word in the node at each time point; and The first The intermediate vector between the previous and current times of a node; For the first The node embedding vector of the current node at the current time corresponds to the node embedding vector of the node at the current time. The node Embedding vectors of each word; For the first The node intermediate vector of the nth node, which is derived from the node intermediate vector of the nth node. The nodes are composed of the intermediate vectors of each node at all times, which means The temporal dimension features of this node were preserved; For the first The set of neighboring nodes of a node. Indicates the first The node belongs to the _th The neighboring nodes of a node, For the first The node intermediate vector of each node; This represents the sigmoid activation function; For the first The hidden state vector of each node.

[0094] S122: Determine if the number of calculations for the hidden state vector of this node has reached the preset number of iterations. If not, use the hidden state vector of the node as the node embedding vector and return to step S121. If yes, combine the hidden state vectors of all nodes into a node set hidden state vector and output it. The node set hidden state vector is represented as... The preset number of loops is set to ,and It is a positive integer.

[0095] While encoding the node embedding vector, BiGRU is used to calculate the hidden state vector of the edge set based on the relation embedding vector encoding. Then, the hidden state vector of the edge set and the hidden state vector of the node set are concatenated to obtain the knowledge representation vector.

[0096] (7)

[0097] (8)

[0098] (9)

[0099] wherein, is the relationship hidden state vector of the i-th edge, is the edge set hidden state vector, is the knowledge representation vector, and .

[0100] In step S13, the dialogue history is encoded by BiGRU to obtain a dialogue history hidden state vector, and the calculation process is as follows:

[0101] (10)

[0102] (11)

[0103] (12)

[0104] wherein, is the current time in the dialogue history encoding process, and , i.e., each time corresponds to each word in the dialogue history; is a forward Gated Recurrent Unit (GRU), is a backward GRU; and are the forward dialogue history hidden state vectors of the previous time and the current time, respectively, and are the backward dialogue history hidden state vectors of the previous time and the current time, respectively, is the dialogue history hidden state vector of the current time. When , is the first word of the dialogue history, and are both initialized to 0, represents the hidden state vector of the first word of the dialogue history. The dialogue history hidden state vector is composed of the dialogue history hidden state vectors of all times, i.e. .

[0105] In step S21, a single-layer GRU is used to decode the dialogue history hidden state vector and the generated word of the previous time to obtain the dialogue reply hidden state vector of the current time, and the calculation formula is as follows:

[0106] ​ (13)

[0107] wherein, is the current time in the decoding process, and ; is the current time's dialogue reply hidden state vector, is the dialogue history hidden state vector in the decoding process relative to ; wherein, when , the dialogue history hidden state vector encoded in step S13 is directly taken as the dialogue history hidden state vector in the decoding process, i.e. ; when , the dialogue reply hidden state vector of the previous time is taken as the dialogue history hidden state vector in the decoding process; is the generated word of the previous time, and when , is initialized to 0.

[0108] In step S22, the word table generation probability of the current time is calculated according to the dialogue reply hidden state vector of the current time, and the calculation formula is:

[0109] (14)

[0110] wherein, is the word table generation probability of the current time, and ; is the word generated from the word table of the current time, which is obtained by arranging the frequency of each word appearing in the statistical data set from large to small; represents the first trainable weight, is the total number of words in the word table, and the dialogue reply hidden state vector of the current time is normalized by function to obtain the probability of each word in the word table.

[0111] In step S31, the attention weight of the dialogue reply hidden state vector of the current time on the knowledge representation vector is calculated by the attention mechanism, and the calculation formula is:

[0112] (15)

[0113] wherein, is the attention weight of the dialogue reply hidden state vector of the current time on the knowledge representation vector, and .

[0114] In addition to calculating the vocabulary generation probability to generate a word from the vocabulary, the knowledge graph-based dialogue reply generation method also needs to calculate the knowledge selection probability at the current moment to select the corresponding entity from the constructed knowledge graph. In step S32, the knowledge selection probability at the current moment is calculated according to the attention weight at the current moment, and the calculation formula is:

[0115] (16)

[0116] In the formula, is the i-th component of the attention weight at the current moment, corresponding to an entity in the knowledge graph; is the word selected from the knowledge graph at the current moment; represents the corresponding entity is the same as the word selected from the knowledge graph; is the knowledge selection probability at the current moment, and .

[0117] In order to improve the diversity and quality of dialogue reply generation, the above two probabilities need to be balanced by a generation pointer. In step S40, first, the attention weighted sum vector at the current moment is calculated according to the attention weight at the current moment and the knowledge representation vector, then the dialogue reply hidden state vector at the current moment and the attention weighted sum vector at the current moment are spliced, and the generation pointer at the current moment is calculated by the sigmoid activation function, and the calculation formula is:

[0118] (17)

[0119] (18)

[0120] In the formula, is the attention weighted sum vector of the dialogue reply hidden state vector at the current moment to the knowledge representation vector, represents splicing and , and represents the sigmoid activation function; is the second trainable weight; is the generation pointer at the current moment, and .

[0121] In step S50, the generation pointer at the current moment obtained in step S40 is used to balance the knowledge selection probability at the current moment obtained in step S22 and the vocabulary generation probability at the current moment obtained in step S32, to obtain the final generation probability at the current moment:

[0122] (19)​

[0123] wherein, is the final generation probability at the current time, is the generated word at the current time.

[0124] The final generation probability at the current time is a probability distribution, each probability value in the probability distribution corresponds to a word. To generate a complete text sequence as a dialogue reply, step S60 needs to be performed: selecting the word with the largest probability value in the final generation probability at the current time as the generated word at the current time. After obtaining the generated word at the current time, it is judged whether the generated word is an end symbol, if yes, the generated words at all times are combined into a text sequence as a dialogue reply and output, if not, returning to step S21 to continue decoding to obtain the generated word at the next time, and so on, until the generated word is an end symbol.

[0125] Based on steps S11-S80, an initial dialogue reply generation model system can be formed. In order to improve the accuracy of model selection knowledge and the utilization rate of knowledge, the initial dialogue reply generation model system needs to be trained to optimize the network parameters of the model, and then the trained dialogue reply generation model system can be used for dialogue reply generation. Therefore, the dialogue reply generation method further includes a parameter optimization step:

[0126] S91: initializing the network parameters of steps S22 and S40, randomly dividing the samples in the training set into multiple batches, optimizing the network parameters by performing steps S11-S80 on the samples in the training set by batch, and calculating the loss by using a total loss function. The network parameters include the first weight and the second weight The expression of the total loss function is:

[0127] (20)

[0128] wherein, is the total loss function, is a negative log likelihood (NLL) loss function, is a relative entropy (or KL divergence) loss function;

[0129] The calculation formula of the NLL function is:

[0130] (21)

[0131] wherein, represents the given dialogue history , external knowledge and the dialogue reply before the current time , the generated word of the current time is decoded ; The loss between the generated word and the true value is calculated.

[0132] The formula for calculating the relative entropy is:

[0133] (22)

[0134] In the formula, is the i-th component in the knowledge representation vector of the current time, which represents the i-th entity in the knowledge graph; is the prior probability, which refers to the probability of the word selected from the knowledge graph corresponding to the entity under the condition that the dialogue reply is given; is the posterior probability, which refers to the probability of the word selected from the knowledge graph corresponding to the entity under the condition that the dialogue history is given; is the posterior probability, which refers to the probability of the word selected from the knowledge graph corresponding to the entity under the condition that the dialogue history is given; The loss between the prior probability and the posterior probability is calculated. In the training process, the dialogue reply is known, and both the prior probability and the posterior probability can be used to determine which entity in the knowledge graph is selected, and the relative entropy is introduced as the objective function to reduce the difference between the two.

[0135] S92: After each iteration (epoch), perform steps S11-S80 on the samples of the test set to perform performance testing, and repeat multiple iterations until the performance no longer improves. Wherein, each time all samples in the training set are completely traversed, it is called an iteration; After each iteration, performance testing is performed, and the current performance test result and the corresponding network parameters are recorded; After multiple iterations, if the performance no longer improves, it means that steps S11-S80 have been trained to a convergent state (i.e. the best performance state). The performance test uses common indicators of the dialogue reply generation system: BLEU1, BLEU2 and DISTINCT1, DISTINCT2; wherein, BLEU1, BLEU2 measure the fluency of the generated dialogue reply, and DISTINCT1, DISTINCT2 measure the diversity of the generated dialogue reply.

[0136] The application also provides a dialogue reply generation model system constructed according to steps S11-S92.

[0137] Please also refer to Figure 2 andFigure 3 wherein, Figure 2 a network architecture diagram of a dialogue reply generation model system provided by the present application, Figure 3 a module schematic diagram of a dialogue reply generation model system provided by the present application. The dialogue reply generation model system comprises a composition module, a knowledge graph encoding module, a dialogue history encoding module, a dialogue reply decoding module, a word table generation probability calculation module, an attention mechanism module, a knowledge selection probability calculation module, a generation pointer calculation module, a final generation probability calculation module and a dialogue reply generation module.

[0138] The composition module constructs a knowledge graph according to external knowledge.

[0139] The knowledge graph encoder encodes the knowledge graph to obtain a knowledge representation vector of a preserved time dimension feature, which comprises a word embedding unit, a node set encoding unit, an edge set encoding unit and a knowledge representation unit. The word embedding unit performs word embedding on the knowledge graph to obtain low-dimensional node embedding vectors and relationship embedding vectors; the node set encoding unit adopts a sequence graph embedding mechanism to encode the node embedding vectors to obtain a node set hidden state vector of a preserved time dimension feature; the edge set encoding unit adopts BiGRU to encode the relationship embedding vectors to obtain an edge set hidden state vector; and the knowledge representation unit splices the node set hidden state vector and the edge set hidden state vector to obtain the knowledge representation vector.

[0140] Specifically, the sequence graph embedding unit comprises sequentially stacked layer sequence graph embedding mechanisms, and is a positive integer; the sequence graph embedding mechanism is a sequence-oriented graph neural network, which takes a traditional GCN as a basic framework and replaces the linear convolution kernel of the GCN with an RNN, and can preserve the time dimension feature of each node; each layer of the sequence graph embedding mechanism calculates a node intermediate vector from the node embedding vector through the RNN, and then calculates a node hidden state vector from the node intermediate vector, and the node hidden state vector output by the previous layer of the sequence graph embedding mechanism is transmitted to the next layer of the sequence graph embedding mechanism as the node embedding vector for calculation, and the last layer of the sequence graph embedding mechanism outputs the node set hidden state vector composed of the node hidden state vectors of all nodes.

[0141] The dialogue history encoder adopts BiGRU to encode the dialogue history to obtain a dialogue history hidden state vector.

[0142] The dialogue reply decoding module calculates a dialogue reply hidden state vector of a current time according to the dialogue history hidden state vector and a generated word of a previous time.

[0143] The word table generation probability calculation module calculates a word table generation probability of a current time according to the dialogue reply hidden state vector of the current time.

[0144] The attention mechanism module calculates the attention weight of the knowledge representation vector on the dialogue reply hidden state vector at the current time.

[0145] The knowledge selection probability calculation module calculates the knowledge selection probability at the current time according to the attention weight at the current time.

[0146] The generation pointer calculation module calculates the generation pointer at the current time according to the knowledge representation vector, the attention weight at the current time, and the dialogue reply hidden state vector at the current time.

[0147] The final generation probability calculation module balances the knowledge selection probability at the current time and the vocabulary generation probability at the current time by using the generation pointer at the current time, and obtains the final generation probability at the current time.

[0148] The dialogue reply generation module selects the word with the maximum probability value in the final generation probability at the current time as the generation word at the current time, and judges whether the generation word is an end symbol; if yes, a text sequence composed of the generation words at all times is taken as a dialogue reply and output, and if no, the generation word at the current time is transmitted to the dialogue reply decoding unit in the decoding module for continuous decoding to predict the generation word at the next time, until the generation word at the current time is the end symbol.

[0149] The application also provides a dialogue reply generation system, which comprises a memory, a processor, and a computer program stored on the memory and running on the processor, and the processor implements the steps of the dialogue reply generation method when executing the computer program.

[0150] The application also provides a computer readable storage medium, which stores a computer program, and the computer program implements the steps of the dialogue reply generation method when executed by a computer.

[0151] In a specific embodiment, the dialogue reply generation model system is implemented in a PyTorch framework through steps S11-S92. The hidden dimension size of the dialogue reply generation model system is set to 800, and the number of layers of the sequence graph embedding mechanism is set to 2. The data set used is a DuConv data set, wherein the DuConv data set is divided into a training set and a test set, the samples in the training set are randomly divided into multiple batches, and the batch size is set to 64.

[0152] Please refer to Figure 4 which is a sample example graph in the DuConv data set. In the entire dialogue process, “Wang Shuo ah, is the one who graduated from Beijing No. 44 Middle School.” is the dialogue reply, and all the sentences before the dialogue reply are the dialogue history, the dialogue target is transferred from “Sunshine Day” to “Wang Shuo”, and the external knowledge involved in the entire dialogue is represented by a knowledge triple as follows:

[0153] [Sunshine, Time Network / Short Review, A little / Sicilian / feel]

[0154] [Sunshine, Field, Movie]

[0155] [Sunshine, Director, Jiang Wen]

[0156] [Shuo Wang, Graduation / Institute, Beijing 44 Middle School]

[0157] [Shuo Wang, Review, Talent / !]

[0158] Take the first knowledge triple as an example, "Sunshine" is the head node, "Time Network / Short Review" is the relationship, and "A little / Sicilian / feel" is the tail node. Different entities inside the node and relationship are separated by " / ". Since there can be multiple relationships for the head node of each knowledge triple, and the tail node of each knowledge triple can also be the head node of another knowledge triple, the above external knowledge can be constructed into a knowledge graph.

[0159] The network parameters of the dialogue reply generation model system are initialized, the number of training iterations is set to 25, the conversation sequences in the training set are input into the dialogue reply generation model system in batches for training, and the network parameters of the model are optimized through the Adam algorithm; wherein the initial learning rate of the Adam algorithm is 0.0001, and the weight decay rate is 1e-5. When the model converges to a convergent state, the experimental effect of the dialogue reply generation model system of the present application on the DuConv data set is shown in Table 1. Compared with Post_KG (sequence generation model with posterior knowledge distribution, Seq2Seq model with posterior knowledge distribution) and GOKC (goal-oriented knowledge copy network, Goal-Oriented Knowledge Copy network) in the prior art in terms of the four evaluation indexes of BLEU1, BLEU2 and DISTINCT1, DISTINCT2, the dialogue reply generation model system of the present application all achieves the best recommendation effect, which fully proves that after introducing the sequence graph embedding mechanism, the different entities inside the node can be accurately selected considering the topology structure of the knowledge triple, and the quality and diversity of the dialogue reply generation model system are significantly improved.

[0160] Compared with the prior art, the dialogue reply generation method and the dialogue reply generation method model provided by the application introduce time dimension features, encode different entities of the knowledge graph at different time points, are beneficial to distinguish different nodes and different entities inside the nodes, and can make more fine-grained selection in subsequent knowledge selection; further, the application designs a sequence diagram embedding mechanism to encode the node set in the knowledge graph, can retain the time dimension features inside the nodes, and extract effective features of different entities inside the nodes, is beneficial to select correct entities in the decoding process, thereby improves the accuracy of knowledge selection and the effective utilization rate of knowledge, and further improves the quality and diversity of dialogue reply generation; in addition, the sequence diagram embedding mechanism can be extended to other dialogue systems based on the knowledge graph, has strong universality, and the way of reconstructing external knowledge into the knowledge graph reduces the frequency of entities with multiple attributes, balances the weights between different knowledge at the data level, reduces unnecessary noise, and improves the utilization rate of external knowledge.

[0161] Table 1. Comparison of the effect of the dialogue reply generation model system of the application and two dialogue reply generation models in the prior art

[0162]

[0163] The above-mentioned embodiments only express several embodiments of the application, and the description is more specific and detailed, but it should not be understood as a limitation on the scope of the patent. It should be pointed out that for ordinary skilled in the art, without departing from the concept of the application, a number of modifications and improvements can be made, which are all within the scope of protection of the application.

Claims

1. A method for generating a reply to a dialogue, characterized by, The method comprises the steps of: S11: constructing a knowledge graph according to external knowledge; S12: encoding the knowledge graph to obtain a knowledge representation vector that retains time dimension characteristics; S13: encoding the dialogue history to obtain a dialogue history hidden state vector; wherein, step S13 is executed simultaneously with step S11 or step S12, or step S13 is executed before step S11 or after step S12; S21: decoding the dialogue history hidden state vector and the generated word at the previous time to obtain a dialogue reply hidden state vector at the current time; S22: calculating a word table generation probability at the current time according to the dialogue reply hidden state vector at the current time; S31: calculating an attention weight of the dialogue reply hidden state vector at the current time on the knowledge representation vector; wherein, step S31 is executed after step S21; S32: calculating a knowledge selection probability at the current time according to the attention weight at the current time; S40: calculating a generation pointer at the current time according to the knowledge representation vector, the attention weight at the current time, and the dialogue reply hidden state vector at the current time; wherein, step S40 is executed after step S31; S50: balancing the knowledge selection probability at the current time and the word table generation probability at the current time by using the generation pointer at the current time to obtain a final generation probability at the current time. 2.The dialogue reply generation method of claim 1, wherein, Step S12 specifically comprises: performing word embedding on the knowledge graph to obtain node embedding vectors and relation embedding vectors; encoding the node embedding vectors by a sequence graph embedding mechanism to obtain node set hidden state vectors that retain time dimension characteristics, and encoding the relation embedding vectors by a bidirectional gated recurrent unit to obtain edge set hidden state vectors, and then splicing the node set hidden state vectors and the edge set hidden state vectors to obtain the knowledge representation vector.

3. The dialogue reply generation method according to claim 2, characterized in that: the sequence graph embedding mechanism performs the steps of: S121: calculating a node intermediate vector from the node embedding vectors by a recurrent neural network, and then calculating a node hidden state vector from the node intermediate vector; S122: determine whether the number of times of calculating the node hidden state vector reaches a preset loop number, if not, take the node hidden state vector as the node embedding vector, return to step S21, if yes, compose the node set hidden state vector by the node hidden state vectors of all nodes and output; wherein the preset loop number is set as , and is a positive integer. 4.The dialogue reply generation method of claim 3, wherein, Step S13 specifically comprises: encoding the dialogue history by a bidirectional gated recurrent unit to obtain the dialogue history hidden state vector. 5.The dialogue reply generation method of claim 4, wherein, Step S21 specifically comprises: decoding the dialogue history hidden state vector and the generated word at the previous time by a gated recurrent unit to obtain the dialogue reply hidden state vector at the current time. 6.The dialogue reply generation method of claim 5, wherein, Step S40 specifically comprises: calculating an attention weighted sum vector at the current time according to the attention weight at the current time, splicing the dialogue reply hidden state vector at the current time and the attention weighted sum vector at the current time, and then calculating the generation pointer at the current time by a sigmoid activation function. 7.The dialogue reply generation method of claim 6, wherein, The method further comprises the step of: S60: selecting a word with the maximum probability value in the final generation probability at the current time as the generated word at the current time. S70: judging whether the generated word at the current time is an end symbol, if yes, executing step S80, if no, executing step S21; S80: composing a text sequence of the generated words at all times as a dialogue reply and outputting.

8. The dialog reply generation method according to any one of claims 1 to 7, characterized by, Further comprising a parameter optimization step: S91: initializing the network parameters of steps S11-S50, randomly dividing the samples in the training set into multiple batches, optimizing the network parameters of steps S11-S50 according to the batches, and performing loss calculation using a total loss function, the expression of the total loss function being: (20) wherein is the total loss function, is the negative log-likelihood loss function, is the relative entropy loss function; S92: after each iteration, performing performance testing on the samples in the test set by executing steps S11-S50, and repeating multiple iterations until the performance no longer improves.

9. A conversation reply generation model system, characterized by, Comprise: a composition module, constructing a knowledge graph according to external knowledge; a knowledge graph encoding module, encoding the knowledge graph to obtain a knowledge representation vector retaining time dimension features; a dialogue history encoding module, encoding the dialogue history to obtain a dialogue history hidden state vector; a dialogue reply decoding module, calculating a dialogue reply hidden state vector at the current time according to the dialogue history hidden state vector and the generated word at the last time; a word table generation probability calculation module, calculating a word table generation probability at the current time according to the dialogue reply hidden state vector at the current time; an attention mechanism module, calculating an attention weight of the dialogue reply hidden state vector at the current time on the knowledge representation vector; a knowledge selection probability calculation module, calculating a knowledge selection probability at the current time according to the attention weight at the current time; a generation pointer calculation module, calculating a generation pointer at the current time according to the knowledge representation vector, the attention weight at the current time, and the dialogue reply hidden state vector at the current time; a final generation probability calculation module, balancing the knowledge selection probability at the current time and the word table generation probability at the current time by using the generation pointer at the current time, to obtain a final generation probability at the current time. 10.The dialogue reply generation model system of claim 9, wherein, The knowledge graph encoding module further comprises: a word embedding unit, performing word embedding on the knowledge graph to obtain node embedding vectors and relation embedding vectors; a node set encoding unit, encoding the node embedding vectors using a sequential graph embedding mechanism to obtain node set hidden state vectors retaining time dimension features; an edge set encoding unit, encoding the relation embedding vectors by a bidirectional gated recurrent unit to obtain edge set hidden state vectors; a knowledge representation unit, concatenating the node set hidden state vectors and the edge set hidden state vectors to obtain a knowledge representation vector.

Citation Information

Patent Citations

  • Automatic reply generation method for open domain dialogue system

    CN110334190A

  • Man-machine conversation method and device

    CN110704703A