Conversation method and device, storage medium and program product

By using pre-trained embedded models in the dialogue system to extract emotional and semantic features and match them with background knowledge to generate emotionally rich dialogue responses, the problem of inability to effectively understand user emotions and generate emotional color responses in the prior art is solved, and the user experience of the dialogue system is improved.

CN119537550APending Publication Date: 2025-02-28CHINA MOBILE M2M +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411650650.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-19
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

Existing deep learning models cannot effectively understand and respond to user emotions in dialogue systems in the field of natural language processing, and it is difficult to generate rich and emotional responses based on background knowledge in specific fields.

Method used

The emotional features and context semantic features of the above conversation are extracted through the pre-trained embedding model, and matched with the feature vectors in the background knowledge document to obtain the most similar target background knowledge feature vectors, and generate the following dialogue with the decoder.

Benefits of technology

The dialogue system is able to recognize and understand user emotions, and generate emotional and content-rich responses based on background knowledge in specific fields, improving the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119537550A_ABST
    Figure CN119537550A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of artificial intelligence, and particularly provides a dialogue method and device, a storage medium and a program product. The method comprises the following steps: extracting emotional features of a previous dialogue text in a current dialogue round through a pre-trained first embedding model; through a pre-trained second embedding model and an encoder, extracting context semantic features of the previous text of the dialogue and background knowledge feature vectors of all background knowledge statements in a background knowledge document related to the subject of the previous text of the dialogue; obtaining a target background knowledge feature vector most similar to the context semantic feature from the background knowledge feature vectors; and decoding the context semantic feature, the emotion feature and the target background knowledge feature vector by adopting a pre-trained decoder to obtain a dialogue text of the current dialogue round. The dialogue system disclosed by the invention not only can identify and understand the emotion of the user, but also can generate the response with rich content and emotional colors according to the background knowledge in the specific field, so as to avoid replying cold ice or meaningless sentences.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of artificial intelligence technology, and in particular to a dialogue method, device, storage medium and program product. Background Art

[0002] In recent years, as deep learning models have become increasingly mature in natural language processing, they have been widely used in dialogue systems. According to the implementation method, dialogue systems can be divided into generative dialogue systems and retrieval dialogue systems. Generative dialogue systems construct response sentences based on user input sentences. Retrieval dialogue systems retrieve previous dialogue data sets based on user input sentences and select the most matching response sentence.

[0003] However, no matter which type, they are usually unable to effectively understand and respond to user emotions and provide in-depth information in specific fields. As users' requirements for intelligent dialogue continue to increase, dialogue systems need to not only be able to recognize and understand user emotions, but also generate rich and emotional responses based on background knowledge in specific fields to avoid cold or meaningless responses. Summary of the invention

[0004] The present disclosure is proposed in view of the above problems. The present disclosure provides a conversation method, device, storage medium and program product.

[0005] According to a first aspect of the present disclosure, a conversation method is provided, comprising:

[0006] Extracting sentiment features of the conversation context in the current conversation turn through a pre-trained first embedding model, and extracting contextual semantic features of the conversation context and background knowledge feature vectors of each background knowledge sentence in a background knowledge document related to the topic of the conversation context through a pre-trained second embedding model and an encoder;

[0007] Acquire a target background knowledge feature vector that is most similar to the context semantic feature from the background knowledge feature vector;

[0008] The context semantic features, the sentiment features and the target background knowledge feature vector are decoded using a pre-trained decoder to obtain the dialogue context of the current dialogue turn.

[0009] In addition, according to the dialogue method of the first aspect of the present disclosure, the contextual semantic features of the dialogue context and the background knowledge feature vectors of each background knowledge sentence in the background knowledge document related to the topic of the dialogue context are extracted through the pre-trained second embedding model and the encoder, including:

[0010] Inputting the disassembled words of the conversation context and the disassembled words of each of the background knowledge sentences into the second embedding model respectively, to obtain preliminary context features and preliminary background knowledge features of the conversation context;

[0011] The preliminary context features and the preliminary background knowledge features are respectively input into the encoder to obtain the context semantic features and the background knowledge feature vectors of each background knowledge sentence.

[0012] In addition, according to the dialogue method of the first aspect of the present disclosure, obtaining a target background knowledge feature vector that is most similar to the context semantic feature from the background knowledge feature vector includes:

[0013] Calculating the dot product of each of the background knowledge feature vectors and the context semantic feature;

[0014] Normalizing the dot product to obtain a normalized dot product;

[0015] The background knowledge feature vector corresponding to the normalized dot product with the largest value among the normalized dot products is used as the target background knowledge feature vector.

[0016] In addition, according to the dialogue method of the first aspect of the present disclosure, a pre-trained decoder is used to decode the context semantic feature, the emotion feature and the target background knowledge feature vector to obtain the dialogue context of the current dialogue turn, including:

[0017] Based on the context semantic features, the sentiment features, the target background knowledge features and the hidden state of the i-th time step, the hidden state of the i+1-th time step is obtained; the hidden state of the 1st time step is obtained by concatenating the context semantic features, the sentiment features and the target background knowledge features;

[0018] Using the decoder to decode the hidden state of the i-th time step to obtain the predicted character of the i-th time step;

[0019] When the predicted character at the i-th time step does not belong to the preset end character, update i=i+1;

[0020] In a case where the predicted character at the i-th time step belongs to a preset end character, the dialogue context of the current dialogue turn is obtained based on the predicted character at the i-th time step.

[0021] In addition, according to the dialogue method of the first aspect of the present disclosure, the decoder is used to decode the hidden state of the i-th time step to obtain the predicted character of the i-th time step, including:

[0022] Using a multilayer perceptron in the encoder to perform probability prediction on the hidden state of the i-th time step to obtain a first probability distribution and a second probability distribution, wherein the first probability distribution is used to characterize the probability distribution of generating characters through a vocabulary, and the second probability distribution is used to characterize the probability distribution of selecting characters from the background knowledge document, wherein the vocabulary is obtained based on a training data set of the encoder, the first embedding model, the second embedding model, and the decoder;

[0023] Calculate a final probability distribution based on the first probability distribution and the second probability distribution;

[0024] Based on the final probability distribution, the predicted character for the i-th time step is determined.

[0025] In addition, according to the dialogue method of the first aspect of the present disclosure, determining the predicted character of the i-th time step based on the final probability distribution includes:

[0026] Obtain the character index with the highest probability value in the final probability distribution;

[0027] Using the character index to query the mapping relationship between the index pre-established based on the vocabulary and the decomposed words, to obtain the target character corresponding to the character index;

[0028] The target character is used as the predicted character at the i-th time step.

[0029] According to a second aspect of the present disclosure, there is provided a dialogue device, comprising:

[0030] An extraction module, configured to extract the sentiment features of the conversation context in the current conversation turn through a pre-trained first embedding model, and to extract the contextual semantic features of the conversation context and the background knowledge feature vector of each background knowledge sentence in the background knowledge document related to the topic of the conversation context through a pre-trained second embedding model and an encoder;

[0031] An acquisition module, used for acquiring a target background knowledge feature vector that is most similar to the context semantic feature from the background knowledge feature vector;

[0032] A decoding module is used to decode the context semantic features, the emotional features and the target background knowledge feature vector using a pre-trained decoder to obtain the dialogue context of the current dialogue turn.

[0033] According to a third aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, the steps of the method described in the first aspect are implemented.

[0034] According to a fourth aspect of the present disclosure, there is provided a computer program product, comprising a computer program / instruction, which implements the steps of the method described in the first aspect when executed by a processor.

[0035] As will be described in detail below, according to the dialogue method of the embodiment of the present disclosure, when predicting the context of the dialogue context of the current dialogue turn, the prediction is made by combining the emotional features of the dialogue context, the contextual semantic features and the background knowledge feature vector of the background knowledge sentences in the background knowledge document. This enables the dialogue system to not only recognize and understand user emotions, but also generate content-rich and emotional responses based on background knowledge in a specific field, so as to avoid replying with cold or meaningless sentences.

[0036] It is to be understood that both the foregoing general description and the following detailed description are exemplary, and are intended to provide further explanation of the technology as claimed. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] The above and other purposes, features and advantages of the present disclosure will become more apparent by describing the embodiments of the present disclosure in more detail in conjunction with the accompanying drawings. The accompanying drawings are used to provide a further understanding of the embodiments of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the present disclosure and do not constitute a limitation of the present disclosure. In the accompanying drawings, the same reference numerals generally represent the same components or steps.

[0038] Figure 1 is a flowchart illustrating an application of a conversation method according to an embodiment of the present disclosure.

[0039] Figure 2 is a flowchart illustrating an application of a conversation method according to an embodiment of the present disclosure.

[0040] Figure 3 2 is a structural diagram illustrating an application of a conversation device according to an embodiment of the present disclosure.

[0041] Figure 4 is a hardware block diagram illustrating an electronic device according to an embodiment of the present disclosure.

[0042] Figure 5 is a schematic diagram illustrating a computer-readable storage medium according to an embodiment of the present disclosure. DETAILED DESCRIPTION

[0043] In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.

[0044] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0045] The term "and / or" herein only describes an association relationship, indicating that three relationships may exist. For example, A and / or B may represent the following three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C may represent including any one or more elements selected from the set consisting of A, B, and C.

[0046] In related technologies, deep learning-based dialogue systems are unable to recognize and understand users' emotions, and cannot generate content-rich, emotional responses based on background knowledge in specific fields. They often reply with cold or meaningless sentences, resulting in poor user experience.

[0047] In order to alleviate the technical problems existing in the related art, the embodiments of the present disclosure provide a dialogue method, device, storage medium and computer program product. When predicting the context of the previous dialogue of the current dialogue round, the method combines the emotional features of the previous dialogue, the context semantic features and the background knowledge feature vector of the background knowledge sentence in the background knowledge document to make predictions, so that the dialogue system can not only recognize and understand the user's emotions, but also generate rich and emotional responses based on the background knowledge of a specific field, so as to avoid replying cold or meaningless sentences.

[0048] To facilitate understanding of this embodiment, a conversation method disclosed in the embodiment of the present disclosure is first introduced in detail. The execution subject of the conversation method provided in the embodiment of the present disclosure is generally an electronic device with certain computing capabilities, and the electronic device includes, for example, a terminal device or a server or other processing device. In some possible implementations, the conversation method can be implemented by a processor calling a computer-readable instruction stored in a memory.

[0049] See also Figure 1 FIG. 1 is a flowchart of a conversation method provided by an embodiment of the present disclosure, and the method comprises the following steps:

[0050] Step 101: extract the sentiment features of the conversation context in the current conversation turn through a pre-trained first embedding model, and extract the contextual semantic features of the conversation context and the background knowledge feature vector of each background knowledge sentence in the background knowledge document related to the topic of the conversation context through a pre-trained second embedding model and an encoder.

[0051] In this embodiment, the current conversation turn refers to the context content of the conversation turn, which usually includes a preceding text and a following text, so as to ensure that the extraction of emotional features can accurately reflect the conversation emotion of the turn.

[0052] In this embodiment, the first embedding model includes but is not limited to the RoBERTa pre-trained model. After the conversation context in the current conversation round is input into the RoBERTa pre-trained model, the output of the last hidden layer of the RoBERTa pre-trained model is extracted as the sentiment feature of the conversation context through processing by the RoBERTa pre-trained model.

[0053] In one or more embodiments, extracting the contextual semantic features of the conversation context and the background knowledge feature vector of each background knowledge sentence in the background knowledge document related to the topic of the conversation context by using the pre-trained second embedding model and the encoder may include the following steps:

[0054] Input the disassembled words of the previous conversation and the disassembled words of each background knowledge sentence into the second embedding model respectively to obtain the preliminary context features and preliminary background knowledge features of the previous conversation;

[0055] The preliminary context features and preliminary background knowledge features are respectively input into the encoder to obtain context semantic features and background knowledge feature vectors of each background knowledge sentence.

[0056] In this embodiment, stop words and low-frequency words can be removed from the conversation context. Removing stop words can reduce irrelevant interference information, while removing low-frequency words (such as words that appear less than 5 times) can further optimize the computational efficiency of the model while focusing on high-frequency important words. Subsequently, the text is intercepted and segmented, and the text is decomposed into a collection of words and phrases to obtain the decomposed words of the conversation context.

[0057] It should be understood that in order to adapt to the input limitations of the embedded model, longer texts are appropriately truncated to control the length within 512 words to meet the maximum input length of the RoBERTa model.

[0058] It should be understood that the decomposition of the background knowledge sentences in the background knowledge document is similar to the decomposition of the above conversation text. To avoid redundancy, it will not be described in detail here.

[0059] In actual application, the second embedding model can first convert the decomposed words in the conversation into a dense word vector sequence, then generate preliminary context features based on the dense word vector sequence, input the preliminary context features into the encoder, and use the encoder's time dependency and context capture capabilities to encode context semantic features.

[0060] It should be understood that the process of generating background knowledge feature vectors is similar to that of generating preliminary context features, so it will not be described in detail here to avoid redundancy. Through this dual encoding mechanism, each background knowledge sentence in the background knowledge document is independently represented as a background knowledge feature vector, so that the system can more accurately calculate the relevance of these sentences to the current round of dialogue in subsequent processing, thereby better selecting background knowledge that is highly relevant to the current dialogue content and enhancing the system's knowledge integration and response capabilities.

[0061] Step 102: Obtain a target background knowledge feature vector that is most similar to the context semantic feature from the background knowledge feature vector.

[0062] In some embodiments, step 102 may include the following steps:

[0063] Calculate the dot product of each background knowledge feature vector and the context semantic feature;

[0064] Normalize the dot product to obtain a normalized dot product;

[0065] The background knowledge feature vector corresponding to the normalized dot product with the largest value in the normalized dot product is taken as the target background knowledge feature vector.

[0066] In the step of selecting the target background knowledge feature vector, the similarity score between the contextual semantic features of the previous conversation and each background knowledge feature vector is calculated through a dot product operation. After calculating the similarity scores, these similarity scores are normalized using the Softmax function, and each normalized similarity score is the attention score of the corresponding sentence. In this way, the system can calculate the relevance weight of each background knowledge sentence with the previous conversation. Finally, the background knowledge feature vector with the highest attention score is selected as the target background knowledge feature vector for the current conversation round.

[0067] Step 103: Use a pre-trained decoder to decode the context semantic features, sentiment features, and target background knowledge feature vectors to obtain the conversation context of the current conversation turn.

[0068] In some embodiments, step 103 may include the following steps:

[0069] Based on the context semantic features, sentiment features, target background knowledge features and the hidden state of the i-th time step, the hidden state of the i+1-th time step is obtained; the hidden state of the 1st time step is obtained by concatenating the context semantic features, sentiment features and target background knowledge features;

[0070] Use the decoder to decode the hidden state of the i-th time step to obtain the predicted character of the i-th time step;

[0071] When the predicted character at the i-th time step does not belong to the preset end character, update i=i+1;

[0072] When the predicted character at the i-th time step belongs to the preset end character, the dialogue context of the current dialogue turn is obtained based on the predicted character at the i-th time step.

[0073] Wherein, i≥1, and i is a positive integer.

[0074] It should be understood that when the predicted character at the i-th time step belongs to the preset end character, the predicted characters at the previous i time steps are combined to form the conversation context of the current conversation round.

[0075] In some embodiments, using a decoder to decode the hidden state of the i-th time step to obtain the predicted character of the i-th time step may include the following steps:

[0076] A multilayer perceptron in the encoder is used to perform probability prediction on the hidden state of the i-th time step to obtain a first probability distribution and a second probability distribution, wherein the first probability distribution is used to characterize the probability distribution of generating characters through a vocabulary, and the second probability distribution is used to characterize the probability distribution of selecting characters from a background knowledge document, wherein the vocabulary is obtained based on a training data set of the encoder, the first embedding model, the second embedding model, and the decoder;

[0077] Based on the first probability distribution and the second probability distribution, calculating a final probability distribution;

[0078] Based on the final probability distribution, determine the predicted character for the i-th time step.

[0079] It should be understood that the final probability distribution includes probability prediction values ​​of multiple characters, that is, the probability of the predicted character at the i-th time step being a certain character. When determining the predicted character at the i-th time step based on the final probability distribution, the probability character with the largest probability prediction value in the final probability distribution can be used as the predicted character at the i-th time step.

[0080] Specifically, during implementation, determining the predicted character of the i-th time step based on the final probability distribution may include the following steps:

[0081] Get the character index with the highest probability value in the final probability distribution;

[0082] Using character index query to find the mapping relationship between the index pre-established in the vocabulary and the decomposed words, the target character corresponding to the character index is obtained;

[0083] The target character is taken as the predicted character at the i-th time step.

[0084] In this embodiment, in order to improve the prediction efficiency, a vocabulary is established in advance based on the training data, and an index is established for the decomposed words in the vocabulary. The character index of the character with the highest probability value of the final probability distribution output by the decoder is obtained by querying the mapping relationship between the index established in advance based on the vocabulary and the decomposed words, the target character corresponding to the character index can be obtained, that is, the predicted character at the i-th time step.

[0085] In the solution provided in this embodiment, when predicting the context of the previous conversation of the current conversation round, the prediction is made by combining the emotional features of the previous conversation, the contextual semantic features and the background knowledge feature vectors of the background knowledge sentences in the background knowledge document. This enables the dialogue system to not only recognize and understand user emotions, but also generate content-rich and emotional responses based on background knowledge in a specific field, so as to avoid replying with cold or meaningless sentences.

[0086] The disclosed embodiment also provides a dialogue method, such as Figure 2As shown, the method may include the following steps:

[0087] Step 201: perform text preprocessing on the conversation text input by the user and perform text preprocessing on the background knowledge document related to the topic of the conversation text.

[0088] In the text preprocessing stage, the conversation context and background knowledge documents are subjected to a series of preprocessing operations. The background knowledge documents come from online documents of Baidu Encyclopedia, which are external information sources related to the current conversation topic, ensuring that the system has sufficient domain knowledge when generating responses to meet the knowledge requirements of different scenarios.

[0089] In the text preprocessing of the conversation context and background knowledge documents, stop words and low-frequency words are first removed from the text content. Removing stop words can reduce irrelevant interference information, while removing low-frequency words (such as words that appear less than 5 times) can further optimize the model's computational efficiency while focusing on high-frequency important words. Subsequently, the text is truncated and segmented to break the text into a collection of words and phrases. In order to adapt to the input restrictions of the pre-trained model, longer texts are appropriately truncated to control the length within 512 words to meet the maximum input length of the RoBERTa model. On this basis, a dictionary (vocabulary) is constructed to assign a unique number to each word. By establishing a bidirectional mapping relationship from word to index and from index to word, it is ensured that the model can quickly find and map each word during processing. The indexed word representation not only speeds up the computational speed of large-scale text processing, but also ensures the standardization of subsequent model inputs. In the feature extraction stage, the indexed words are input into the RoBERTa model to generate a dense word vector sequence. The vector length of each word is 768 dimensions, which fully captures the contextual information and background knowledge characteristics of the conversation text, and provides efficient and accurate support for subsequent sentiment understanding and knowledge integration.

[0090] Step 202: Encoding.

[0091] The word vector sequences of the conversation context and background knowledge document obtained by text preprocessing in step 201 are respectively input into the RoBERTa pre-trained model and the GRU encoder for encoding to obtain contextual semantic features and background knowledge feature vectors of background knowledge sentences (the background knowledge document has been truncated into multiple background knowledge sentences in the preprocessing stage, and each background knowledge sentence is regarded as an independent candidate knowledge item. The model needs to select the sentence most relevant to the current conversation turn as the background knowledge sentence).

[0092] Specifically, the word vector sequences of the conversation context and background knowledge documents are first input into the RoBERTa model to generate context features and preliminary background knowledge feature vectors. Subsequently, these feature vectors are further input into the GRU encoder, which uses the GRU's time dependency and context capture capabilities to encode context semantic features containing context semantic relationships and background knowledge feature vectors of candidate knowledge document sentences after sentence processing. Through this dual encoding mechanism, each sentence in the background knowledge document is independently represented as a candidate knowledge document sentence feature, allowing the system to more accurately calculate the relevance of these sentences to the current conversation in subsequent processing, thereby better selecting background knowledge that is highly relevant to the current conversation content and enhancing the system's knowledge integration and response capabilities.

[0093] Step 203: Select a background knowledge statement.

[0094] In the step of selecting background knowledge sentences, the similarity score between the contextual semantic features of the dialogue context and the background knowledge feature vector of each candidate knowledge document sentence is calculated through dot product operation. After calculating the similarity score, these similarity scores are normalized using the Softmax function. Each normalized similarity score is the attention score of the corresponding sentence. In this way, the system can calculate the relevance weight of each candidate knowledge sentence with the dialogue context. Finally, the candidate knowledge sentence feature vector with the highest attention score is selected as the background knowledge feature vector H of the current dialogue round. k .

[0095] Step 204: Extract emotional features.

[0096] In the emotion feature extraction step, the RoBERTa pre-trained model is used to extract the emotion features of the current conversation context. Specifically, the context is used as input, and the output of the last hidden layer is extracted through the processing of the RoBERTa model and used as the emotion feature H e , capturing the emotional state of the current turn of conversation. This emotional feature is then combined with the background knowledge feature vector and contextual semantic features to generate a response that better matches the user's emotional state.

[0097] Step 205: Decoding.

[0098] Use the GRU decoder to decode and convert the context semantic feature vector H of the current dialogue round into x , background knowledge feature vector H k , emotional characteristics H eAfter concatenation, it is used as the decoder's initial hidden state S0 to integrate the information of the conversation context, knowledge content, and emotional characteristics. The decoder will gradually generate characters or words in the process of generating responses. Each time a character is generated, it enters the next time step and updates the hidden state S in each time step. y Finally, the probability P of generating a response character is obtained through the Softmax function to guide the generation of each character until the final complete response is generated.

[0099] The emotion-enhanced knowledge dialogue system obtained through the above process can generate a response that contains background knowledge, is full of emotion, and is fluent and coherent based on the user's dialogue. The entire dialogue system model can be roughly divided into four modules: (1) an encoding module, which is used to encode the dialogue context and the matched knowledge documents; (2) a knowledge selection module, which selects the one that best matches the context from the background knowledge document sentence feature vectors as the background knowledge feature vector for the current dialogue round; (3) an emotion feature extraction module, which is used to extract the emotion feature vector of the current dialogue context; (4) a decoder, which is used to decode and generate a character at each time step, and finally generate a complete response. The following is a brief description of each module in the present invention:

[0100] (1) Encoder: First, use the RoBERTa pre-trained model to convert the conversation context and background knowledge documents into a sequence of word vectors for context information. First, convert the input text information into an input format that the model can accept. Then, add a special tag <cls>Add to the beginning of the input sentence to extract contextual information from the context. The whole process is as follows, where H kn Represents the word vector sequence of the i-th sentence in the conversation, H x Represents the word vector sequence of the i-th sentence in the background knowledge document:

[0101]

[0102] in, represents the i-th sentence in the conversation above, Represents the i-th sentence in the background knowledge document.

[0103] Then use the GRU encoder to encode the word vector sequence. The GRU encoder can capture the temporal information of the text very well. The process is as follows: represents the background knowledge feature vector of the current t-th dialogue round, Represents the context feature vector of the current t-th dialogue round:

[0104]

[0105] Among them, e(k k ) is the preliminary context feature, e(k x ) is the preliminary background knowledge feature.

[0106] (2) Knowledge selection module: The knowledge selection module selects the background knowledge feature vector of the current round through dot product calculation and attention score. First, the similarity score between the context and each candidate background knowledge sentence can be defined, and then the dot product budget calculation is used. Indicates the score of the mth candidate knowledge sentence in the current nth round:

[0107]

[0108] Then, these similarity measures are normalized by applying the Softmax function to calculate the attention score of each candidate knowledge item. Finally, the background knowledge feature representation H of the current round is determined by selecting the candidate knowledge item with the highest attention score. k , argmax represents the maximum value selection function,

[0109]

[0110] (3) Emotional feature extraction module: The RoBERTa pre-trained model is used to extract emotional feature vectors from the conversation context. First, the input text information is converted into an input form acceptable to the model. Then, a special tag is added. <cls>Add to the beginning of the input sentence to mark the beginning of the sentence. Then input the RoBERTa pre-trained model and take the last hidden layer output as the emotional feature vector H of the conversation. e The whole process is as follows:

[0111]

[0112] (4) Decoder: The decoder uses a GRU decoder with a replication mechanism for decoding. The initial decoding state S0 is composed of the feature vector H of the conversation context. x and the feature vector H of the selected knowledge k And the sentiment feature vector H e Then update the hidden state at each time step to get S t And according to the hidden state, two probability distributions P are obtained through a multi-layer perceptron Generate ,P Copy ; where P Generate represents the probability distribution of generating a character from the vocabulary, P Copy The probability distribution that the response is to select a character from the currently selected knowledge document. The vocabulary comes from the training data set of the dialogue system (obtained in step 1), which contains commonly used words and phrases in the system and can cover regular dialogue requirements; while the background knowledge document (obtained in step 1) contains knowledge content in a specific field, which is used to provide rich contextual information and field-specific knowledge points. The final probability distribution P Final By combining the two, we can get Final Represents the final generation possibility of candidate words at each time step (vocabulary comparison). The system selects the word with the highest probability on this probability distribution as the output of the current time step, allowing the system to flexibly choose to generate new characters or copy characters from knowledge documents when generating responses. Final The calculation formula is as follows:

[0113] P Generate =MLP(S t )

[0114] P Copy =MLP′(S t )

[0115] P Final =αP Generate +(1-α)P Copy

[0116] Where MLP represents multi-layer perceptron computing, S t represents the final hidden state of the decoder, and α is a Generate and P Copy A learnable soft gate that switches between the two. Each character of the response tends to be generated from the vocabulary or copied from the background knowledge. Finally, the probability of each step is used to generate the final response of the dialogue system.

[0117] The present disclosure also provides a dialogue device for executing the dialogue method provided in any of the above embodiments. Figure 3 As shown, the device comprises:

[0118] An extraction module 31 is used to extract the sentiment features of the conversation context in the current conversation turn through a pre-trained first embedding model, and to extract the contextual semantic features of the conversation context and the background knowledge feature vector of each background knowledge sentence in the background knowledge document related to the topic of the conversation context through a pre-trained second embedding model and an encoder;

[0119] An acquisition module 32, configured to acquire a target background knowledge feature vector that is most similar to the context semantic feature from the background knowledge feature vector;

[0120] The decoding module 33 is used to decode the context semantic features, the emotional features and the target background knowledge feature vector using a pre-trained decoder to obtain the dialogue context of the current dialogue turn.

[0121] In some embodiments, the extraction module 31 is used to:

[0122] Inputting the disassembled words of the conversation context and the disassembled words of each of the background knowledge sentences into the second embedding model respectively, to obtain preliminary context features and preliminary background knowledge features of the conversation context;

[0123] The preliminary context features and the preliminary background knowledge features are respectively input into the encoder to obtain the context semantic features and the background knowledge feature vectors of each background knowledge sentence.

[0124] In some embodiments, the acquisition module 32 is used to:

[0125] Calculating the dot product of each of the background knowledge feature vectors and the context semantic feature;

[0126] Normalizing the dot product to obtain a normalized dot product;

[0127] The background knowledge feature vector corresponding to the normalized dot product with the largest value among the normalized dot products is used as the target background knowledge feature vector.

[0128] In some embodiments, the decoding module 33 is used to:

[0129] Based on the context semantic features, the sentiment features, the target background knowledge features and the hidden state of the i-th time step, the hidden state of the i+1-th time step is obtained; the hidden state of the 1st time step is obtained by concatenating the context semantic features, the sentiment features and the target background knowledge features;

[0130] Using the decoder to decode the hidden state of the i-th time step to obtain the predicted character of the i-th time step;

[0131] When the predicted character at the i-th time step does not belong to the preset end character, update i=i+1;

[0132] In a case where the predicted character at the i-th time step belongs to a preset end character, the dialogue context of the current dialogue turn is obtained based on the predicted character at the i-th time step.

[0133] In some embodiments, the decoding module 33 is used to:

[0134] Using a multilayer perceptron in the encoder to perform probability prediction on the hidden state of the i-th time step to obtain a first probability distribution and a second probability distribution, wherein the first probability distribution is used to characterize the probability distribution of generating characters through a vocabulary, and the second probability distribution is used to characterize the probability distribution of selecting characters from the background knowledge document, wherein the vocabulary is obtained based on a training data set of the encoder, the first embedding model, the second embedding model, and the decoder;

[0135] Calculate a final probability distribution based on the first probability distribution and the second probability distribution;

[0136] Based on the final probability distribution, the predicted character for the i-th time step is determined.

[0137] In some embodiments, the decoding module 33 is used to:

[0138] Obtain the character index with the highest probability value in the final probability distribution;

[0139] Using the character index to query the mapping relationship between the index pre-established based on the vocabulary and the decomposed words, to obtain the target character corresponding to the character index;

[0140] The target character is used as the predicted character at the i-th time step.

[0141] The dialogue device provided in the embodiment of the present disclosure and the dialogue method provided in the embodiment of the present disclosure are based on the same inventive concept and have the same beneficial effects as the methods adopted, operated or implemented therein.

[0142] The present disclosure also provides an electronic device to perform the above-mentioned conversation method. Figure 4 It shows a schematic diagram of an electronic device provided by some embodiments of the present disclosure. Figure 4 As shown, the electronic device 8 includes: a processor 800, a memory 801, a bus 802 and a communication interface 803, wherein the processor 800, the communication interface 803 and the memory 801 are connected via the bus 802; the memory 801 stores a computer program that can be run on the processor 800, and when the processor 800 runs the computer program, the dialogue method provided in any of the aforementioned embodiments of the present disclosure is executed.

[0143] The memory 801 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the device network element and at least one other network element is realized through at least one communication interface 803 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.

[0144] The bus 802 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The memory 801 is used to store programs, and the processor 800 executes the programs after receiving execution instructions. The dialogue method disclosed in any implementation of the aforementioned embodiment of the present disclosure may be applied to the processor 800, or implemented by the processor 800.

[0145] The processor 800 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 800 or the instruction in the form of software. The above processor 800 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as a hardware decoding processor to be executed, or the hardware and software modules in the decoding processor can be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 801, and the processor 800 reads the information in the memory 801 and completes the steps of the above method in combination with its hardware.

[0146] The electronic device provided by the embodiment of the present disclosure and the conversation method provided by the embodiment of the present disclosure are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by them.

[0147] The present disclosure also provides a computer-readable storage medium corresponding to the conversation method provided in the above-mentioned embodiment. Figure 5 The computer-readable storage medium shown is a CD 30 on which a computer program (ie, a program product) is stored. When the computer program is run by a processor, the dialogue method provided by any of the aforementioned embodiments will be executed.

[0148] It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical or magnetic storage media, which are not listed here one by one.

[0149] The computer-readable storage medium provided by the above-mentioned embodiments of the present disclosure and the dialogue method provided by the embodiments of the present disclosure are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by the application programs stored therein.

[0150] It should be noted that:

[0151] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present disclosure can be practiced without these specific details. In some instances, well-known structures and technologies are not shown in detail so as not to obscure the understanding of this description.

[0152] Similarly, it should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present disclosure, the various features of the present disclosure are sometimes grouped together into a single embodiment, figure, or description thereof. However, the disclosed method should not be interpreted as reflecting the following schematic diagram: the claimed disclosure requires more features than the features explicitly recited in each claim. More specifically, as reflected in the claims below, the inventive aspects lie in less than all the features of the single embodiment disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present disclosure.

[0153] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of this disclosure and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.

[0154] The above is only a preferred specific implementation of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any changes or substitutions that can be easily thought of by any technician familiar with the technical field within the technical scope disclosed in the present disclosure should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.< / cls> < / cls>

Claims

1. A conversation method, characterized in that: include: Extracting sentiment features of the conversation context in the current conversation turn through a pre-trained first embedding model, and extracting contextual semantic features of the conversation context and background knowledge feature vectors of each background knowledge sentence in a background knowledge document related to the topic of the conversation context through a pre-trained second embedding model and an encoder; Acquire a target background knowledge feature vector that is most similar to the context semantic feature from the background knowledge feature vector; The context semantic features, the sentiment features and the target background knowledge feature vector are decoded using a pre-trained decoder to obtain the dialogue context of the current dialogue turn.

2. The method according to claim 1, characterized in that Extracting contextual semantic features of the conversation context and background knowledge feature vectors of each background knowledge sentence in a background knowledge document related to the topic of the conversation context through a pre-trained second embedding model and an encoder, including: Inputting the disassembled words of the conversation context and the disassembled words of each of the background knowledge sentences into the second embedding model respectively, to obtain preliminary context features and preliminary background knowledge features of the conversation context; The preliminary context features and the preliminary background knowledge features are respectively input into the encoder to obtain the context semantic features and the background knowledge feature vectors of each background knowledge sentence.

3. The method according to claim 1, characterized in that Acquiring a target background knowledge feature vector that is most similar to the context semantic feature from the background knowledge feature vector includes: Calculating the dot product of each of the background knowledge feature vectors and the context semantic feature; Normalizing the dot product to obtain a normalized dot product; The background knowledge feature vector corresponding to the normalized dot product with the largest value among the normalized dot products is used as the target background knowledge feature vector.

4. The method according to claim 1, characterized in that: The pre-trained decoder is used to decode the context semantic feature, the emotion feature and the target background knowledge feature vector to obtain the dialogue context of the current dialogue turn, including: Based on the context semantic features, the sentiment features, the target background knowledge features and the hidden state of the i-th time step, the hidden state of the i+1-th time step is obtained; the hidden state of the 1st time step is obtained by concatenating the context semantic features, the sentiment features and the target background knowledge features; Using the decoder to decode the hidden state of the i-th time step to obtain the predicted character of the i-th time step; When the predicted character at the i-th time step does not belong to the preset end character, update i=i+1; In a case where the predicted character at the i-th time step belongs to a preset end character, the dialogue context of the current dialogue turn is obtained based on the predicted character at the i-th time step.

5. The method according to claim 4, characterized in that The decoder is used to decode the hidden state of the i-th time step to obtain the predicted character of the i-th time step, including: Using a multilayer perceptron in the encoder to perform probability prediction on the hidden state of the i-th time step to obtain a first probability distribution and a second probability distribution, wherein the first probability distribution is used to characterize the probability distribution of generating characters through a vocabulary, and the second probability distribution is used to characterize the probability distribution of selecting characters from the background knowledge document, wherein the vocabulary is obtained based on a training data set of the encoder, the first embedding model, the second embedding model, and the decoder; Calculate a final probability distribution based on the first probability distribution and the second probability distribution; Based on the final probability distribution, the predicted character for the i-th time step is determined.

6. The method according to claim 5, characterized in that Determining the predicted character of the i-th time step based on the final probability distribution includes: Obtain the character index with the highest probability value in the final probability distribution; Using the character index to query the mapping relationship between the index pre-established based on the vocabulary and the decomposed words, to obtain the target character corresponding to the character index; The target character is used as the predicted character at the i-th time step.

7. A conversation device, characterized in that: include: An extraction module, configured to extract the sentiment features of the conversation context in the current conversation turn through a pre-trained first embedding model, and to extract the contextual semantic features of the conversation context and the background knowledge feature vector of each background knowledge sentence in the background knowledge document related to the topic of the conversation context through a pre-trained second embedding model and an encoder; An acquisition module, used for acquiring a target background knowledge feature vector that is most similar to the context semantic feature from the background knowledge feature vector; A decoding module is used to decode the context semantic features, the emotional features and the target background knowledge feature vector using a pre-trained decoder to obtain the dialogue context of the current dialogue turn.

8. An electronic device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.