An open-domain dialogue method based on dialogue structure graph constraint
By constructing a dialogue structure graph and utilizing relevant loss functions and behavior cloning algorithms, the problem of topic shifting in open-domain dialogue is solved, enabling the generation of more relevant and coherent dialogues and improving the fluency and robustness of the dialogue.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NANJING UNIV OF AERONAUTICS & ASTRONAUTICS
- Filing Date
- 2022-11-26
- Publication Date
- 2026-05-08
AI Technical Summary
Existing open-domain dialogue generation models tend to overlook topic shifts in multi-turn dialogues, resulting in the generation of responses that are irrelevant to the current topic and affecting the fluency of the dialogue.
We adopt a dialogue structure graph-based approach, constructing the dialogue structure graph through a bidirectional attention transformer encoder and a clustering algorithm. We train the encoder using absolute relevance loss and relative relevance loss, simulate topic shifts using a behavior cloning algorithm, and generate topic-related dialogues using a left-to-right attention transformer decoder.
It effectively improves the fluency of the model-generated dialogues and the connection of topic shifts. The generated dialogues are more relevant and coherent. The model is not sensitive to parameters and has good robustness.
Smart Images

Figure CN115796187B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of natural language processing in the computer science field, specifically an open-domain dialogue method based on dialogue structure graph constraints. Background Technology
[0002] In recent years, large-scale pre-trained language models have achieved success in many tasks within the field of natural language processing. In dialogue generation, autoregressive pre-trained language models can generate fluent and rich dialogues. However, in multi-turn open-domain dialogues, models often ignore topic shifts between contexts, generating responses irrelevant to the current topic, making the dialogue feel abrupt and awkward. Therefore, dialogue structure graphs are needed to constrain models to generate topic-related dialogues. Past work has focused on dialogue structure graphs in task-oriented dialogue systems. However, compared to task-oriented dialogues, open-domain dialogues involve a massive number of dialogue states and numerous uncertain state transitions. Therefore, methods for constructing dialogue structure graphs in task-oriented dialogues are not applicable to open-domain dialogue scenarios. The difficulty in constructing open-domain dialogue structure graphs lies in two aspects: how to extract dialogue states or topics in an unsupervised manner; and how to capture the transitions between topics.
[0003] Currently, there is little research on dialogue structure graphs in open-domain dialogue. The mainstream approach is to use graph neural networks to construct graphs at the statement and topic levels, calculate the transition probability between statements or topics by statistically analyzing the co-occurrence frequency of words and sentences, and finally train the dialogue model by incorporating topic information into the reward function through reinforcement learning. Summary of the Invention
[0004] The technical problem to be solved by this invention:
[0005] The purpose of this invention is to design an open-domain dialogue method based on dialogue structure graph constraints to address the problem of existing dialogue generation being irrelevant to the current or expected topic. Humans can easily recognize topics and topic shifts in different situations during dialogue, thus organizing their language to provide relevant responses. This invention attempts to mimic human topic awareness, providing a method for constructing a structure graph for open-domain multi-turn dialogues and a method for generating dialogues using structure graph constraints. This method demonstrates excellent performance on high-quality human dialogue datasets, and the model is parameter-insensitive and highly robust.
[0006] To solve its technical problem, the present invention adopts the following technical solution:
[0007] An open-domain dialogue method based on dialogue structure graph constraints includes the following steps:
[0008] (1) Input dialogue statement, use the average pooling output of the bidirectional attention transformer encoder as the initial vector representation of the dialogue statement, design a loss function, and train the bidirectional attention transformer encoder in a self-supervised manner. After training, the bidirectional attention transformer encoder outputs a dialogue statement vector representation that fully contains semantics.
[0009] (2) Cluster the obtained dialogue statement vector representations that fully contain semantics to form several clusters. Each cluster represents a dialogue topic. Use the behavior cloning method to simulate the transition of dialogue topics, calculate the transition probability between the clusters, and construct the dialogue structure graph with the clusters as vertices and the transition probabilities as edges.
[0010] (3) By constraining the dialogue statements generated by the transformer decoder with left-to-right attention through the obtained dialogue structure graph, the distance between the generated dialogue statements and the cluster is reduced.
[0011] Preferably, the design process of the loss function in step 1) is as follows: based on the input dialogue statements satisfying the order and relevance, define the absolute relevance loss and the relative relevance loss.
[0012] The absolutely relevant loss is:
[0013]
[0014] Wherein: S i This represents the i-th dialogue statement. This represents the i-th dialogue statement of character A. and express Two data augmentation samples;
[0015] h Ai Let the vector represent the initial vector representation of character A's i-th dialogue statement. and h i The vector representation of the two data augmented samples;
[0016] sim is the cosine distance between dialogue statement vectors, τ is a hyperparameter representing the temperature coefficient, and X j Let represent the set of dialogue statements in the j-th group, and D represent the enhanced dialogue dataset.
[0017] Relative correlation loss includes strong correlation loss and weak correlation loss. Strong correlation loss is defined as:
[0018]
[0019] in, This represents the i-th dialogue statement of character B, and also... Defined as a dialog statement The next dialogue statement, Let the vector represent the initial vector representation of character B's i-th dialogue statement, and simultaneously... Defined as a dialog statement The initial vector representation of the next dialogue statement; the weak correlation loss is defined as:
[0020]
[0021] in, Defined as a dialog statement The previous dialogue statement, Defined as a dialog statement The initial vector representation of the previous dialogue statement, where λ1 is a hyperparameter controlling the strength of the weak correlation loss;
[0022] Then we have: the absolute correlation loss function and the relative correlation loss function are respectively:
[0023]
[0024]
[0025] Where N is the batch size, S i-1 This represents the (i-1)th dialogue statement;
[0026] The bidirectional attention transformer encoder is trained on a dialogue dataset using a mini-batch gradient descent method. After training, the bidirectional attention transformer encoder outputs a dialogue phrasal vector representation that fully contains semantics.
[0027] Preferably, in step 2), the behavior cloning algorithm is used to simulate the transition of conversation topics as follows:
[0028] (3) Specify h i The state is represented by the center vector c of each cluster, and the action is represented by the center vector c of each cluster.
[0029] (4) After obtaining the continuous actions in Euclidean space, select the cluster center vector c that is closest to the action in cosine distance as the final action and enter the next state.
[0030] Preferably, step 3) is implemented as follows: reduce h i KL divergence with c:
[0031]
[0032] Among them, hi+1 c is the dialogue statement vector obtained by average pooling the original output of the transformer decoder with left-to-right attention. i+1 Predict the cluster center vector of the dialogue statement vector to which the dialogue structure graph belongs.
[0033] Compared with the prior art, the present invention, employing the above technical solution, has the following beneficial effects:
[0034] This paper presents a powerful method for representing dialogue statements using vectors, which fully leverages the sequential and relevance characteristics of dialogue. Based on excellent statement representation, a dialogue structure graph is constructed to fully grasp topic shifts and generate topic-related responses. Experiments show that this invention proposes an excellent method for representing dialogue statements using vectors to build a dialogue structure graph. Under the constraints of the dialogue structure graph, it can effectively improve the fluency of the model's generated dialogue and the connection between topic shifts. Attached Figure Description
[0035] Figure 1 This is a schematic diagram of the overall process of the proposed algorithm framework. Detailed Implementation
[0036] The invention will now be described in further detail with reference to the accompanying drawings.
[0037] This invention constrains dialogue generation based on a dialogue structure graph. The overall framework is as follows: Figure 1 As shown, it is divided into three parts: 1. Dialogue utterance vector representation based on contrastive learning. 2. Construction of dialogue structure graph.
[0038] 3. Dialogue generation with dialogue structure graph constraints.
[0039] (1) Dialogue sentence vector representation based on contrastive learning
[0040] For each input sentence, a transformer encoder based on bidirectional attention is used for representation. The encoder's output is then averaged and pooled to obtain the initial dialogue sentence vector. Sentences in a dialogue exhibit sequentiality and relevance. The former refers to the fact that a dialogue can be viewed as a unidirectional flow of topics, with sentences having an inherent logical relationship and not being arbitrarily interchangeable. The latter refers to the fact that each sentence in a dialogue is related to its context, and the closer the sentence is to the preceding sentence, the stronger the correlation. Utilizing these two characteristics, it can be concluded that a sentence is semantically strongly correlated with its following sentence and weakly correlated with its preceding sentence. Combining relevant knowledge of contrastive learning, this invention designs absolute relevance loss and relative relevance loss for training the dialogue sentence representation. Absolute relevance loss refers to the loss of a sentence... Two data augmentation samples and A pair of positive samples is formed, and the other samples form a negative sample. The formula is as follows, where h is the representation of the sentence, and sim is the cosine distance between the vectors.
[0041]
[0042] Relative correlation loss consists of strong correlation loss and weak correlation loss. Strong correlation loss refers to the loss of a statement. and the next statement These constitute positive samples, and together with other samples, they constitute negative samples.
[0043]
[0044] Weak correlation loss refers to a statement And the previous statement These constitute a slightly weaker positive sample, and together with other samples, they form a negative sample.
[0045]
[0046] Training is performed on the dialogue dataset using mini-batch gradient descent. For a batch size of N, the absolute correlation loss and relative correlation loss are as follows:
[0047]
[0048]
[0049] The entire encoder training process is self-supervised and requires no additional data annotation. After training, the encoder outputs dialogue sentence vectors that represent semantics.
[0050] (2) Construction of the Dialogue Structure Diagram
[0051] K-means clustering based on cosine distance is performed on the sentence vectors in the dataset, resulting in k clusters, each corresponding to a major topic category in the dialogue. Next, the transitions between topics need to be calculated using the behavior cloning method from imitation learning. Let the dialogue statement vector h of each sentence be the state, and the center vector c of each cluster be the action. Then, the expert trajectory represents the sentence, and the alternating clusters are h1, c2, h2, c3, h3, ..., h m Each cluster represents the topic cluster to which the following statement belongs. The model uses maximum likelihood estimation to determine the policy π. For continuous action and state spaces, it is assumed that the policy distribution follows a Gaussian distribution. The maximum likelihood optimization objective can be written as...
[0052]
[0053] Here, the mean is the object to be estimated, and the variance is assumed to be a constant. Therefore, the final problem is reduced to a mean squared error regression problem.
[0054]
[0055] The model uses a neural network to solve this regression problem, ultimately deriving a strategy—the action to take given a state. The cluster center vector closest in cosine distance to this action is selected as the final action. After completing these steps, for any sentence in the dialogue, the model can predict the topic and probability of the next response, thus completing the construction of the dialogue structure graph, i.e., the topic state transition graph.
[0056] (3) Dialogue generation with dialogue structure graph constraints
[0057] The model employs a left-to-right attention-based transformer decoder to generate dialogue in an autoregressive manner. The loss function to be optimized in this step is...
[0058]
[0059] When the decoder finishes outputting the sentence, it takes the average pooling of the output as the vector representation h of the sentence. i+1 Then, the established dialogue structure graph is used to predict the topic cluster center vector c to which the statement belongs. i+1 These two vectors belong to different vector spaces, and treating them both as one-dimensional distributions reduces the distance between the statement vector and the topic cluster center vector, thus decreasing the KL divergence between them.
[0060]
[0061] This constrains the relevance of the generated dialogue to the topic. Finally, the training loss of the decoder during the generation phase is...
[0062] Loss Gen =l NLL +λ2D KL .
[0063] After training the decoder, the end-to-end encoder-decoder architecture can be directly used to generate dialogue.
[0064] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. An open-domain dialogue method based on dialogue structure graph constraints, characterized in that, Includes the following steps: (1) Input dialogue statement, use the average pooling output of the bidirectional attention transformer encoder as the initial vector representation of the dialogue statement, design a loss function, and train the bidirectional attention transformer encoder in a self-supervised manner. After training, the bidirectional attention transformer encoder outputs a dialogue statement vector representation that fully contains semantics. (2) Cluster the obtained dialogue statement vector representations that fully contain semantics to form several clusters. Each cluster represents a dialogue topic. Use the behavior cloning method to simulate the transition of dialogue topics, calculate the transition probability between the clusters, and construct the dialogue structure graph with the clusters as vertices and the transition probabilities as edges. The implementation process of simulating the shift of conversation topics using the behavior cloning method is as follows: The dialogue statement vector h for each sentence is defined as the state, and the center vector c of each cluster is defined as the action; After obtaining the continuous actions in Euclidean space, select the cluster center vector c that is closest to the action in cosine distance as the final action and enter the next state; (3) By constraining the dialogue sentences generated by the transformer decoder with left-to-right attention through the obtained dialogue structure graph, the distance between the generated dialogue sentences and the cluster is reduced, that is, the KL divergence between the sentence vector and the topic cluster center vector is reduced: ; in, The dialogue statement vector is obtained by average pooling the original output of the transformer decoder with left-to-right attention. Predict the cluster center vector of the dialogue statement vector to which the dialogue structure graph belongs.
2. The open-domain dialogue method based on dialogue structure graph constraints as described in claim 1, characterized in that, The design process of the loss function in step (1) is as follows: based on the fact that the input dialogue statements satisfy the order and relevance, define the absolute relevance loss and the relative relevance loss. The absolutely relevant loss is: ; in: This represents the i-th dialogue statement. This represents the i-th dialogue statement of character A. and express Two data augmentation samples; Let the vector represent the initial vector representation of character A's i-th dialogue statement. and express The vector representation of the two data augmented samples; It is the cosine distance between the dialogue statement vectors. X is a hyperparameter representing the temperature coefficient. j Let represent the set of dialogue statements in the j-th group, and D represent the enhanced dialogue dataset. Relative correlation loss includes strong correlation loss and weak correlation loss. Strong correlation loss is defined as: ; in, This represents the i-th dialogue statement of character B, and also... Defined as a dialog statement The next dialogue statement, Let the vector represent the initial vector representation of character B's i-th dialogue statement, and simultaneously... Defined as a dialog statement The initial vector representation of the next dialogue statement; the weak correlation loss is defined as: ; in, Defined as a dialog statement The previous dialogue statement, Defined as a dialog statement The initial vector representation of the previous dialogue statement. The hyperparameters used to control the intensity of weak correlation loss; Then we have: the absolute correlation loss function and the relative correlation loss function are respectively: ; ; Where N is the size of the dialogue dataset samples. This represents the (i-1)th dialogue statement; The bidirectional attention transformer encoder is trained on a dialogue dataset using a mini-batch gradient descent method. After training, the bidirectional attention transformer encoder outputs a dialogue phrasal vector representation that fully contains semantics.