A Human-Computer Dialogue Method and System Based on Role and Knowledge Information Comparison and Selection Network
By comparing roles and knowledge information, the network selects the information most suitable for the current context and inputs it into the dialogue generation network. This solves the problem of responses deviating from the topic in existing technologies and enables richer and more personalized dialogue generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2026-04-03
AI Technical Summary
Existing dialogue systems struggle to select the most suitable role information and knowledge information for the current context when generating responses, resulting in responses that are off-topic or lack personalization.
A role-and-knowledge information comparison and selection network is adopted. The model is trained by supervised contrastive learning to select the most suitable role and knowledge information for the current context, and then input into the dialogue generation network to generate a response.
The generated responses are richer and more personalized, fitting the current context and avoiding the problem of generating responses that are off-topic.
Smart Images

Figure CN115828933B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the fields of natural language processing and deep learning technology, and particularly relates to a human-computer dialogue method and system based on role and knowledge information comparison and selection network. Background Technology
[0002] The statements in this section are merely background information related to the present invention and do not necessarily constitute prior art.
[0003] Dialogue systems have garnered significant attention in the field of natural language processing due to their broad application prospects and substantial demand in real life. Existing dialogue tasks can be categorized into retrieval-based and generative-based systems. Retrieval-based systems select the most appropriate system response based on dialogue history and the current user's utterance, abstracting the dialogue question into a search question. However, the responses generated by retrieval-based systems are relatively fixed and lack flexibility, making them difficult to apply in some random scenarios. Generative dialogue systems typically employ deep learning-based encoder-decoder architectures, usually not relying on specific answer libraries or templates, but rather on language skills learned from large corpora. Methods that directly generate answers based on question content are defined as condition-based generative models. However, generative-based dialogue systems still have certain issues regarding dialogue fluency and the repetition rate of responses. Based on the domain involved, they can be divided into task-specific domain dialogue systems and open-domain dialogue systems. Task-specific domain dialogue systems can solve specific problems in a particular domain, such as movie ticket booking or restaurant table reservation. Open-domain dialogue systems aim to chat with users without task or domain restrictions and are typically entirely data-driven.
[0004] As research has deepened, role-based dialogue systems have emerged, incorporating more role information when generating responses, resulting in more diverse and personalized replies. In recent years, mining implicit roles and understanding explicit roles have become two major research directions for role-based dialogue systems. Dialogue models that mine implicit roles understand and extract user role features from the embedding tensors of information such as dialogue history, and model user role information. However, this method faces problems such as role interpretability and noise interference. Therefore, more and more work has shifted to dialogue models that understand explicit roles. When generating responses, dialogue models that understand explicit roles incorporate predefined explicit user role information into the input to generate more personalized and diverse responses.
[0005] However, the inventors discovered that although many dialogue systems have attempted to extract role information from the dialogue process and integrate it into dialogue generation, truly understanding and integrating role information remains a challenge. Furthermore, during conversations, people not only use known role information in their responses but also consider prior knowledge of the current topic. Existing methods extract features from the acquired role and knowledge information using neural networks to create abstract representations, then synthesize dialogue history information and generate responses through an automatic encoder-decoder. However, the role and knowledge information referenced during generation is often not the most suitable for the current context. The most important reason for this problem is the failure to select the most suitable role and knowledge information for the current context for integration. In most cases, dialogue systems do not need to represent excessive role and knowledge information when generating responses; they only need to select the most suitable role and knowledge information for integration based on the dialogue history. Otherwise, the generated responses may deviate from the topic or be misattributed. Summary of the Invention
[0006] To overcome the shortcomings of the prior art, this invention provides a human-computer dialogue method and system based on a role and knowledge information comparison and selection network. A role and knowledge information comparison and selection network is trained using predefined role candidate information and knowledge candidate information in the dataset. When generating a response, the role and knowledge information comparison and selection network is first used to select the role candidate information and knowledge candidate information that are most suitable for the current context. Then, the selected information is input into the dialogue generation network to generate the response.
[0007] To achieve the above objectives, one or more embodiments of the present invention provide the following technical solutions:
[0008] The first aspect of this invention provides a human-computer dialogue method based on a comparison and selection network of roles and knowledge information;
[0009] Human-computer dialogue methods based on role and knowledge information comparison and selection networks include:
[0010] When engaging in dialogue with a user, the system takes the current user's dialogue history, known role information, and known knowledge information as inputs, and uses a trained role and knowledge information comparison and selection network to select the most suitable role candidate information and knowledge candidate information for the current context.
[0011] The selected role candidate information, knowledge candidate information and dialogue history information are concatenated and input into the trained dialogue generation network to generate and output a response to the latest utterance in the dialogue history information.
[0012] Further, the character and knowledge information comparison and selection network, based on the encoder of GPT2, has the following specific steps:
[0013] Preprocess the input information to obtain the information to be selected;
[0014] Perform a linear transformation on the information to be selected to obtain the classification result;
[0015] Normalize the classification result to obtain the probability corresponding to each candidate information, and select the candidate information with the highest probability as the final output of the character and knowledge information comparison and selection network.
[0016] Further, the preprocessing is specifically: respectively convert the dialogue history information, known character information, and known knowledge information into vector representations through GPT2-encoder, and splice them with the candidate character information and candidate knowledge information to obtain the information to be selected.
[0017] Further, the character and knowledge information comparison and selection network adopts the supervised contrast learning method, taking the correct answers in the character candidate information and knowledge candidate information as positive examples, and the wrong answers as negative examples, gradually narrowing the distance between positive examples and widening the distance between positive examples and negative examples during the learning process, so that the network can better identify and select the most suitable character information and knowledge information for the current context.
[0018] Further, a set of linear transformations are used to construct a set of pseudo-positive examples similar to the correct answers in the candidate information for calculating the similarity between positive examples.
[0019] Further, the dialogue generation network, based on the decoder of GPT2, selects words from candidate words, sets the maximum sequence generation length for autoregressive iteration to generate, obtains the reply sequence, and constructs a reply to the latest utterance in the dialogue history information based on the reply sequence.
[0020] Further, the character and knowledge information comparison and selection network and the dialogue generation network are trained as a whole model, and the loss function during training consists of three parts: supervised contrast loss, binary cross-entropy loss, and cross-entropy loss.
[0021] The second aspect of the present invention provides a human-computer dialogue system based on the character and knowledge information comparison and selection network.
[0022] The human-computer dialogue system based on the character and knowledge information comparison and selection network includes an information selection unit and a reply generation unit:
[0023] An information selection unit, configured to: when conducting a conversation with a user, take the conversation history information, known role information, and known knowledge information of the current user as inputs, and use a trained role and knowledge information comparison and selection network to select the most suitable role candidate information and knowledge candidate information for the current context;
[0024] A reply generation unit, configured to: splice the selected role candidate information, knowledge candidate information with the conversation history information, input them into a trained conversation generation network, and generate and output a reply to the latest utterance in the conversation history information.
[0025] The third aspect of the present invention provides a computer-readable storage medium, on which a program is stored, and when the program is executed by a processor, the steps in the human-machine conversation method based on the role and knowledge information comparison and selection network as described in the first aspect of the present invention are implemented.
[0026] The fourth aspect of the present invention provides an electronic device, including a memory, a processor, and a program stored on the memory and executable on the processor, and when the processor executes the program, the steps in the human-machine conversation method based on the role and knowledge information comparison and selection network as described in the first aspect of the present invention are implemented.
[0027] The above one or more technical solutions have the following beneficial effects:
[0028] In the present invention, by inputting candidate role and knowledge information into the role and knowledge information selection network to select the role and knowledge information with the highest relevance to the current context, and integrating the selected role and knowledge information into the input information for final conversation generation, the reply content generated by the model is made more rich and personalized.
[0029] In order to better select suitable candidate roles and knowledge information and make the generated replies more personalized and diverse, the present invention incorporates the supervised contrastive learning method into the learning process of the model to fine-tune and optimize the model parameters. The correct answers in the role candidate information and knowledge candidate information are used as positive examples, and the wrong answers are used as negative examples. During the learning process, the distance between positive examples is gradually reduced, and the distance between positive examples and negative examples is widened, so that the model can better identify and select the most suitable role information and knowledge information for the current context.
[0030] The advantages of the additional aspects of the present invention will be partly given in the following description, partly will become obvious from the following description, or will be understood through the practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] The specification drawings constituting a part of the present invention are used to provide a further understanding of the present invention, and the schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation to the present invention.
[0032] Figure 1 This is a flowchart of the method in the first embodiment.
[0033] Figure 2 This is a structural diagram of the human-computer dialogue model in the first embodiment.
[0034] Figure 3 This is a system structure diagram of the second embodiment. Detailed Implementation
[0035] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0036] It should be noted that the following detailed descriptions are exemplary and intended to provide further explanation of this disclosure; unless otherwise indicated, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this disclosure pertains.
[0037] It should be noted that the terminology used herein is for the purpose of describing particular implementations only and is not intended to limit the exemplary implementations according to this disclosure; as used herein, the singular form is intended to include the plural form as well, unless the context clearly indicates otherwise; furthermore, it should be understood that when the terms “comprising” and / or “including” are used in this specification, they indicate the presence of features, steps, operations, devices, components and / or combinations thereof.
[0038] Example 1
[0039] This embodiment discloses a human-computer dialogue method based on the comparison and selection of roles and knowledge information networks, such as... Figure 1 As shown, it includes:
[0040] Step S1: When engaging in dialogue with a user, the system takes the current user's dialogue history, known role information, and known knowledge information as input, and uses a trained role and knowledge information comparison and selection network to select the most suitable role candidate information and knowledge candidate information for the current context.
[0041] Specifically, in order to better select the candidate roles and knowledge information that best fit the current context, this embodiment proposes a role and knowledge information comparison and selection network (PKCSN). It is trained using predefined candidate roles and knowledge information. When generating a response, the PKCSN is first used to select the most suitable candidate role and knowledge information for the current context, and the selected information is used as the input to the dialogue generation network.
[0042] The human-computer dialogue model consists of a role-knowledge information comparison and selection network (PKCSN) and a dialogue generation network. The model structure is as follows: Figure 2As shown, the dialogue history information during the dialogue between user A and system B is as follows: in, It refers to the latest utterances in the dialogue history, and the known information about the user's role, i.e., the known role information is P = {P1, P2, ..., P}. L}, the prior knowledge of the topic being discussed, i.e., the known knowledge information, is K = {K1, K2, ..., K}. M When generating a response, the available candidate role information and candidate knowledge information are as follows:
[0043]
[0044] When people discuss topics requiring specialized knowledge, such as the Roman Colosseum or the Statue of Zeus, they refer to conversation history, prior knowledge of the other person's role, and prior knowledge of the topic. Using a role-knowledge comparison and selection network (PKCSN), they select the most suitable candidate role and knowledge information for the current context. The selected information, along with known information, is then integrated into the response generation process, making the model's response richer and more personalized. The role-knowledge comparison and selection network learns human thinking and intelligently selects the most suitable candidate role and knowledge information for the current context.
[0045] In the comparison and selection of roles and knowledge information in the PKCSN network, the specific processing steps are as follows:
[0046] (1) Preprocess the input information to obtain the information to be selected;
[0047] dialogue history information Known character information P and known knowledge information K are encoded using a GPT2 encoder and converted into vector representations. Since GPT2 is an autoregressive structure, the embedding representation of the last character in the last hidden layer is taken as the overall representation, and concatenated with the predefined candidate character Pc and knowledge information Kc respectively. This allows for the reference of more information when selecting the answer that best fits the current context from among many candidate information. The information to be selected is represented as follows:
[0048]
[0049]
[0050] Among them, P concat For the character information to be selected, K concat For the knowledge information to be selected, P and K represent the encoded dialogue history information, known role information, and known knowledge information, respectively. c K cFor predefined candidate roles and knowledge information.
[0051] (2) Perform a linear transformation on the information to be selected to obtain the classification result;
[0052] The information to be selected is first passed through a fully connected layer for linear transformation and pre-classification. The pre-classification result is used as the input to a second fully connected layer, which performs a linear transformation to obtain the classification result, as shown below:
[0053] Classification mid =FFN(P concat or K concat )
[0054] logits=FCN(Dropout(Classification mid ))
[0055] Among them, Classification mid This represents the pre-classification result of the first fully connected layer, where FFN is the linear transformation of the first fully connected layer, and p concat For the character information to be selected, K concat The knowledge information to be selected; logits represents the classification result of the second fully connected layer; FCN is the linear transformation of the second fully connected layer; tests show that the best results are achieved when the Dropout ratio is 0.1.
[0056] (3) Normalize the classification results to obtain the probability of each candidate information, and select the candidate information with the highest probability as the final output of the role and knowledge information comparison and selection network.
[0057] The logits are normalized using the softmax function to obtain the probability of each candidate message. The topk function is then used to select the candidate message with the highest probability as the final output, specifically defined as follows:
[0058] Answer=topk(softmax(logits))
[0059]
[0060] Where, x i With x j Let j be an element in the set, and let j take values from the entire set. Use the softmax function to normalize logits into measurable probabilities.
[0061] In order to better select role and knowledge candidates that fit the current context, this invention introduces supervised contrastive learning into the selection process. Its core idea is to reduce the distance between positive examples and increase the distance between positive and negative examples through a series of calculations.
[0062] In this embodiment, positive examples are the correct answers in the candidate role information and candidate knowledge information, and negative examples are the remaining information. However, since there is only one positive example, i.e., the correct answer, it is impossible to calculate the similarity between positive examples. Therefore, a set of linear transformations is used to construct a set of pseudo-positive examples that are similar to the correct answers in the candidate information. Each step in the construction process is defined as follows:
[0063]
[0064] Z = FCN(Dropout(Y))
[0065] The Dropout ratio is 0.1. As can be seen from the above formula, a fully connected layer is first used to transform the feature representation of the correct answer in the candidate information to another dimension, and then after Dropout, another fully connected layer is used to transform the feature dimension back to obtain pseudo-positive samples.
[0066] The obtained positive samples, constructed pseudo-positive samples, and negative samples are used as inputs to calculate the supervised contrastive loss:
[0067]
[0068] Where X is the data feature in each batch, i is the index of each data entry, and τ∈R + The temperature coefficient used to control the distance between two sets of samples is represented by Q(i), which represents the samples in the same category except for the i-th sample, and A(i) represents all samples in the batch except for the i-th sample.
[0069] In addition, the binary cross-entropy between the output logits of the last fully connected layer and the candidate information standard answer was calculated as the loss function of the role and knowledge information comparison and selection network:
[0070] L BCE ={l1…l N}
[0071] l n =-(y n ·log(σ(x n ))+(1-y n )·log(1-σ(x n )))
[0072] Where N is the number of predicted labels, σ(x n() is the sigmoid function. x can be mapped to the interval (0, 1).
[0073] Step S2: Concatenate the selected role candidate information, knowledge candidate information and dialogue history information, input them into the trained dialogue generation network, generate and output a response to the latest utterance in the dialogue history information.
[0074] The dialogue generation stage is a sequence-to-sequence prediction task. The pre-trained language model GPT2 is initialized as a dialogue generation network. In terms of model structure, GPT2 is not significantly different from GPT, but it expands the model size, increases the number of learnable parameters, and uses more training data, enabling the model to learn richer content during the pre-training stage.
[0075] GPT2 employs a 12-layer Transformer model with encoder and decoder structures to encode dialogue-related text information and generate responses. During response generation, it compares roles with knowledge information and selects the appropriate role information from the network. With knowledge and information and conversation history information The concatenated data is used as input in the generation process.
[0076] The top-p decoding method is used to decode the vocabulary embedding representation output by GPT2-Decoder, and the next word in the response sequence is selected from the vocabulary.
[0077] First, a probability threshold p is set, which is 0.9 in this embodiment, such that:
[0078]
[0079]
[0080] Wherein, P(x|x 1:i-1 Given that there are 1 to i-1 words already generated, V(p) represents the probability that the word in the vocabulary is selected. V(p) is the sampled word set consisting of words with a probability greater than p.
[0081] Top-p sampling accumulates the probability distribution of candidate words. Words whose accumulated probability exceeds a set threshold p are randomly sampled, while words whose accumulated probability is less than p are discarded with their probability set to 0.
[0082] The maximum sentence generation length is set, and the vocabulary embeddings output by GPT2-Decoder are used as input for autoregressive iterative generation. New words are continuously generated to form sentences until the sentence ends or the maximum sentence generation length is reached, resulting in the final dialogue response.
[0083] The human-computer dialogue model, consisting of a role-and-knowledge information comparison and selection network (PKCSN) and a dialogue generation network, is trained as a whole. The loss function during training consists of the following three parts:
[0084] (1) The supervised contrastive loss used in selecting candidate role information and candidate knowledge information is combined, and corresponding coefficients are set. During backpropagation, these coefficients are used to optimize the GPT2-encoder and the first fully connected layer. The supervised contrastive loss L SCL Represented as:
[0085]
[0086] in, These represent the supervised comparison loss when selecting candidate role information and the supervised comparison loss when selecting candidate knowledge information, respectively, with a coefficient of 0.8.
[0087] (2) For the binary cross-entropy loss when the selection of roles and knowledge information is completed, set its coefficient to 5 and add them together. The binary cross-entropy loss L BCE Represented as:
[0088]
[0089] in, These represent the binary cross-entropy loss when candidate role information selection is complete and the binary cross-entropy loss when candidate knowledge information selection is complete, respectively, with 5 being the coefficient.
[0090] (3) To better optimize the quality of the final generated response, the cross-entropy loss L is calculated between the predicted generated sentence and the standard answer. LM The coefficient is set to 10, the above losses are summed to obtain the final loss, and backpropagation is used to update the parameters:
[0091] L = L LM ·10+L SCL +L BCE
[0092] The human-computer dialogue model was initialized using the publicly available GPT2 base model, which consists of 12 attention modules with a hidden layer size of 768. The model was optimized using the Adam optimizer with a learning rate of 6.25e-5.
[0093] Example 2
[0094] This embodiment discloses a human-computer dialogue system based on a network that compares and selects roles and knowledge information;
[0095] like Figure 3As shown, a human-machine dialogue system based on a role and knowledge information comparison and selection network includes an information selection unit and a response generation unit:
[0096] The information selection unit is configured to: when having a dialogue with a user, take the dialogue history information of the current user, the known role information, and the known knowledge information as inputs, and use the trained role and knowledge information comparison and selection network to select the most suitable role candidate information and knowledge candidate information for the current context;
[0097] The response generation unit is configured to: splice the selected role candidate information, knowledge candidate information, and dialogue history information, input them into the trained dialogue generation network, and generate and output a response to the latest utterance in the dialogue history information.
[0098] Embodiment III
[0099] The purpose of this embodiment is to provide a computer-readable storage medium.
[0100] A computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the steps in the human-machine dialogue method based on a role and knowledge information comparison and selection network as described in Embodiment I of the present disclosure.
[0101] Embodiment IV
[0102] The purpose of this embodiment is to provide an electronic device.
[0103] An electronic device includes a memory, a processor, and a program stored on the memory and executable on the processor. When the processor executes the program, it implements the steps in the human-machine dialogue method based on a role and knowledge information comparison and selection network as described in Embodiment I of the present disclosure.
[0104] The above are only the preferred embodiments of the present invention and are not used to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. A human-computer dialogue method based on role and knowledge information comparison and selection network, characterized in that, include: When engaging in dialogue with a user, the system takes the current user's dialogue history, known role information, and known knowledge information as inputs, and uses a trained role and knowledge information comparison and selection network to select the most suitable role candidate information and knowledge candidate information for the current context. The selected role candidate information, knowledge candidate information and dialogue history information are concatenated and input into the trained dialogue generation network to generate and output a response to the latest utterance in the dialogue history information. The role-knowledge information comparison and selection network, based on the GPT2 encoder, has the following specific steps: The input information is preprocessed to obtain the information to be selected; A linear transformation is applied to the information to be selected to obtain the classification result; The classification results are normalized to obtain the probability of each candidate information. The candidate information with the highest probability is selected as the final output of the role and knowledge information comparison and selection network. The preprocessing specifically involves converting the dialogue history information, known role information, and known knowledge information into vector representations using GPT2-encoder, and then concatenating them with candidate role information and candidate knowledge information to obtain the information to be selected. The dialogue generation network, based on the GPT2 decoder, selects words from candidate words, sets the maximum sequence generation length, performs autoregressive iteration to generate a response sequence, and constructs a response to the latest utterance in the dialogue history based on the response sequence.
2. The human-computer dialogue method based on role and knowledge information comparison and selection network as described in claim 1, characterized in that, The role and knowledge information comparison and selection network adopts a supervised contrastive learning method, which uses correct answers in role candidate information and knowledge candidate information as positive examples and incorrect answers as negative examples. During the learning process, the distance between positive examples is gradually reduced and the distance between positive examples and negative examples is increased, so that the network can better identify and select the role information and knowledge information that are most suitable for the current context.
3. The human-computer dialogue method based on role and knowledge information comparison and selection network as described in claim 2, characterized in that, A set of pseudo-positive examples similar to the correct answers in the candidate information is constructed using a set of linear transformations, which are then used to calculate the similarity between the positive examples.
4. The human-computer dialogue method based on role and knowledge information comparison and selection network as described in claim 1, characterized in that, The role-knowledge information comparison selection network and the dialogue generation network are trained as a whole. The loss function during training consists of three parts: supervised contrastive loss, binary cross-entropy loss, and cross-entropy loss.
5. A human-computer dialogue system based on role and knowledge information comparison and selection network, characterized in that, The human-computer dialogue method based on role and knowledge information comparison and selection network as described in any one of claims 1-4 includes an information selection unit and a response generation unit: The information selection unit is configured to: when having a dialogue with a user, take the current user's dialogue history information, known role information and known knowledge information as input, and use a trained role and knowledge information comparison and selection network to select the most suitable role candidate information and knowledge candidate information for the current context. The response generation unit is configured to concatenate the selected role candidate information, knowledge candidate information and dialogue history information, input them into the trained dialogue generation network, generate and output a response to the latest utterance in the dialogue history information.
6. A computer-readable storage medium having a program stored thereon, characterized in that, When the program is executed by the processor, it implements the steps in the human-computer dialogue method based on the comparison and selection network of role and knowledge information as described in any one of claims 1-4.
7. An electronic device, comprising a memory, a processor, and a program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps in the human-computer dialogue method based on the comparison and selection network of role and knowledge information as described in any one of claims 1-4.