Dialogue generation method and apparatus
By introducing imitation learning strategies and large-scale pre-trained language models, combined with document knowledge base and seed database, the accuracy and generalization of replies generated in dialogue systems are solved, and high-quality replies are generated and cost reduction.
Patent Information
- Application Number
- CN202310772066.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-27
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2043-06-27
AI Technical Summary
The replies generated by existing dialogue systems are not universal and accurate. The training process relies on a large amount of data and lacks the ability to understand universal natural language, so it cannot be effectively generalized to other knowledge fields. The knowledge selection process performs poorly in complex scenarios.
Large-scale pre-trained language model is adopted, combined with imitation learning strategies, and high-quality dialogue replies are generated by searching document knowledge bases and seed databases, and specific knowledge content and reply information are generated using knowledge documents and prompt sample-driven models.
It improves the accuracy and reply quality of the dialogue system in complex scenarios, reduces the training data requirements, reduces costs, and can quickly migrate to other knowledge areas.
Smart Images

Figure CN116860930B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and particularly relates to a dialogue generation method and device. Background Art
[0002] This section aims to provide background or context for the embodiments of the present invention described in the claims. The description herein is not admitted to be prior art merely by virtue of being included in this section.
[0003] With the rapid development of deep learning technology, the use frequency of dialogue systems in people's daily lives is getting higher and higher, and they have received more and more attention from researchers, manufacturers, and users. However, in many real scenarios, the responses generated by dialogue systems still have many defects. For example, it is easy to generate some general, meaningless, and factually incorrect response statements, such as general meaningless responses like "Okay" and "Got it", which cannot effectively identify the user's intention and accurately answer the questions raised by the user, affecting the user experience.
[0004] In addition, in the prior art, a large amount of training data is still required to train the dialogue system, and the quality of the training results also highly depends on the diversity and quality of the training data; not only is the operation process complex and costly, but also the trained dialogue system lacks the ability of general natural language understanding and cannot be effectively generalized to dialogue scenarios in other knowledge domains. Summary of the Invention
[0005] Embodiments of the present invention provide a dialogue generation method for generating high-quality dialogue response information applicable to various dialogue scenarios, improving the user experience, reducing sample construction, and reducing costs. The method includes:
[0006] Receiving the question information of the first dialogue input by the user;
[0007] Retrieving a document knowledge base according to the question information of the first dialogue to obtain a plurality of first knowledge documents;
[0008] Retrieving a first seed database according to the question information of the first dialogue to obtain a plurality of first prompt samples, where the first prompt samples include the question information of the dialogue, as well as the knowledge documents and knowledge content corresponding to the question information of the dialogue;
[0009] Inputting the question information of the first dialogue, the first knowledge documents, and the plurality of first prompt samples into a large-scale pre-trained language model to output first knowledge content, where the large-scale pre-trained language model is constructed based on an imitation learning strategy;
[0010] Retrieving a second seed database according to the question information of the first dialogue to obtain a plurality of second prompt samples, where the second prompt samples include the question information of the dialogue, as well as the knowledge content and response information corresponding to the question information of the dialogue;
[0011] Input the question information of the first conversation, the first knowledge content, and multiple second hint samples into a large-scale pre-trained language model to output the response information of the first conversation.
[0012] An embodiment of the present invention further provides a dialogue generation device for generating high-quality dialogue response information applicable to various dialogue scenarios, improving the user experience, reducing sample construction, and reducing costs. The device includes:
[0013] A question information receiving module for receiving the question information of the first conversation input by the user;
[0014] A document knowledge base retrieval module for retrieving a document knowledge base according to the question information of the first conversation to obtain multiple first knowledge documents;
[0015] A first seed database retrieval module for retrieving a first seed database according to the question information of the first conversation to obtain multiple first hint samples, where the first hint samples include the question information of the conversation, as well as the knowledge documents and knowledge content corresponding to the question information of the conversation;
[0016] A first knowledge content output module for inputting the question information of the first conversation, the first knowledge documents, and multiple first hint samples into a large-scale pre-trained language model to output the first knowledge content, and the large-scale pre-trained language model is constructed based on an imitation learning strategy;
[0017] A second seed database retrieval module for retrieving a second seed database according to the question information of the first conversation to obtain multiple second hint samples, where the second hint samples include the question information of the conversation, as well as the knowledge content and response information corresponding to the question information of the conversation;
[0018] A response information output module for inputting the question information of the first conversation, the first knowledge content, and multiple second hint samples into a large-scale pre-trained language model to output the response information of the first conversation.
[0019] An embodiment of the present invention further provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the above-mentioned dialogue generation method is implemented.
[0020] An embodiment of the present invention further provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned dialogue generation method is implemented.
[0021] An embodiment of the present invention further provides a computer program product, where the computer program product includes a computer program, and when the computer program is executed by a processor, the above-mentioned dialogue generation method is implemented.
[0022] In an embodiment of the present invention, problem information of a first conversation input by a user is received; a document knowledge base is retrieved according to the problem information of the first conversation to obtain a plurality of first knowledge documents; a first seed database is retrieved according to the problem information of the first conversation to obtain a plurality of first prompt samples, where the first prompt samples include the problem information of the conversation, as well as the knowledge documents and knowledge contents corresponding to the problem information of the conversation; the problem information of the first conversation, the first knowledge documents and the plurality of first prompt samples are input into a large-scale pre-trained language model to output first knowledge content, and the large-scale pre-trained language model is constructed based on an imitation learning strategy; a second seed database is retrieved according to the problem information of the first conversation to obtain a plurality of second prompt samples, where the second prompt samples include the problem information of the conversation, as well as the knowledge content and reply information corresponding to the problem information of the conversation; the problem information of the first conversation, the first knowledge content and the plurality of second prompt samples are input into the large-scale pre-trained language model to output the reply information of the first conversation.
[0023] By introducing knowledge and converting the knowledge selection process in knowledge-driven dialogue system related work into a knowledge generation task based on an imitation learning strategy, and constructing input prompts for the pre-trained language model based on the prompt samples retrieved from the seed database that are similar to the dialogue questions input by the user, it can motivate the model to reason based on the knowledge documents and generate specific knowledge content, improving the accuracy of knowledge selection in complex scenarios; in the reply generation stage of the conversation, an imitation learning strategy is adopted. In the case of only constructing a small amount of example sample data, the large-scale language model can generate high-quality replies containing correct knowledge according to the user input and the knowledge content obtained in the knowledge generation stage. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts. In the drawings:
[0025] Figure 1 is the processing flow chart of the dialogue generation method in the embodiment of the present invention;
[0026] Figure 2 is the method flow chart for retrieving a plurality of first prompt samples from the first seed database in the embodiment of the present invention;
[0027] Figure 3 is the method flow chart for retrieving a plurality of second prompt samples from the second seed database in the embodiment of the present invention;
[0028] Figure 4 Shows a schematic diagram of a specific example in the knowledge content generation stage of an embodiment of the present invention;
[0029] Figure 5 Shows a schematic diagram of a specific example in the response generation stage of an embodiment of the present invention;
[0030] Figure 6 Shows a schematic diagram of an overall process of a dialogue generation method in an embodiment of the present invention;
[0031] Figure 7 Is a schematic diagram of the structure of a dialogue generation device in an embodiment of the present invention;
[0032] Figure 8 Is a schematic diagram of the structure of a computer device in an embodiment of the present invention. Detailed implementation manners
[0033] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer and more understandable, the following further describes the embodiments of the present invention in detail with reference to the accompanying drawings. Herein, the illustrative embodiments of the present invention and their descriptions are used to explain the present invention, but do not limit the present invention.
[0034] First, introduce the technical terms in the embodiments of the present invention:
[0035] Prefix prompt: Also known as Prefix Prompt in the industry, it is a string input prefix used to stimulate the output of a generative pre-trained language model; the prefix prompt can guide the model to complete specific tasks by adding human-readable natural language instructions to the input; in the present invention, it is uniformly abbreviated as prompt.
[0036] Imitation learning: Also known as Demonstration Learning in the industry, adding a small number of similar samples as task prompts for a large-scale language model; for example, when performing sentiment analysis on the input prompt "I like the movies of a certain director. The sentiment of this sentence is: <language model output>", some example texts of similar scenarios can be concatenated before this prompt, such as: "This product is really convenient to use. The sentiment of this sentence is <positive>", "I am skeptical about this matter. The sentiment of this sentence is <negative>", etc. At this time, the large-scale language model can "imitate" and predict the result "<positive>" based on the two newly added example sentences.
[0037] Seed database: In the present invention, it is a small-scale sample library used to construct imitation learning examples, and there are mainly two types in this task field: knowledge generation database and response generation database.
[0038] The inventors found that, in order to enable the dialogue system to generate more satisfactory responses, an important aspect is to generate responses that conform to the dialogue context and are rich in knowledge by introducing knowledge. Especially when introducing human-computer interaction into the file system, the dialogue system needs to answer questions raised by users based on a large knowledge base stored in the form of files or documents, and the responses often need to incorporate appropriate knowledge from the documents. For the current research work on this kind of knowledge-driven dialogue generation task, the content in the document is mainly preprocessed into a set of knowledge entries, and the corresponding correct knowledge entries are annotated in the dialogue data as the training data for the dialogue to conduct training. The training process is used to model the knowledge selection and knowledge fusion capabilities of the dialogue system.
[0039] However, for the work related to the knowledge-driven dialogue system described above, it is necessary to prepare a high-quality set of knowledge entries in advance as the external knowledge base for the dialogue generation task, and a large amount of dialogue data in relevant knowledge fields needs to be annotated. Processing document information into a high-quality set of knowledge entries is a cumbersome task. The quality of the training results also highly depends on the diversity of the external knowledge base and the quality of the training data. It lacks the ability of general natural language understanding and cannot be effectively generalized to dialogue scenarios in other knowledge fields. Moreover, in the knowledge selection stage, the existing knowledge dialogue systems mainly retrieve knowledge entries related to the user input from the set of knowledge entries obtained by preprocessing the document. This method performs poorly when the user input involves complex logic, knowledge reasoning, etc., and often fails to locate the correct knowledge content. Based on this, the inventors of the present invention proposed a dialogue generation method to solve the foregoing technical problems.
[0040] Figure 1 It is a processing flow chart of the dialogue generation method in the embodiments of the present invention. As Figure 1 shown, the dialogue generation method in the embodiments of the present invention may include:
[0041] Step 101, receiving the question information of the first dialogue input by the user;
[0042] Step 102, retrieving the document knowledge base according to the question information of the first dialogue to obtain multiple first knowledge documents;
[0043] Step 103, retrieving the first seed database according to the question information of the first dialogue to obtain multiple first prompt samples, where the first prompt sample includes the question information of the dialogue, as well as the knowledge document and knowledge content corresponding to the question information of the dialogue;
[0044] Step 104, inputting the question information of the first dialogue, the first knowledge document, and multiple first prompt samples into a large-scale pre-trained language model, and outputting the first knowledge content. The large-scale pre-trained language model is constructed based on the imitation learning strategy;
[0045] Step 105: Retrieve a second sub-database according to the question information of the first conversation to obtain multiple second hint samples, where the second hint samples include the question information of the conversation, as well as the knowledge content and reply information corresponding to the question information of the conversation;
[0046] Step 106: Input the question information of the first conversation, the first knowledge content, and multiple second hint samples into a large-scale pre-trained language model, and output the reply information of the first conversation.
[0047] The following introduces the specific implementation steps of the conversation generation method in the embodiments of the present invention:
[0048] In specific implementation, first, the question information of the first conversation input by the user can be received, that is, the user can trigger the start of a conversation by asking a question.
[0049] Then, in step 102, a document knowledge base can be retrieved according to the question information of the first conversation to obtain multiple first knowledge documents, where the relevance of the multiple first knowledge documents to the question information of the first conversation is not less than a first preset threshold.
[0050] In one embodiment, before receiving the question information of the first conversation input by the user, it may further include: pre-establishing a document knowledge base, where the document knowledge base contains a large number of knowledge documents covering various types of knowledge.
[0051] In specific implementation, the size of the first preset threshold can be adjusted according to the actual situation. For example, if the number of knowledge documents related to the question information of the first conversation is small, in order to ensure the richness of the introduced knowledge, the first preset threshold can be set to 0, that is, all retrieved knowledge documents are used as the first knowledge documents; if the number of knowledge documents related to the question information of the first conversation is large, in order to avoid repeatedly introducing the same knowledge and causing a burden on the subsequent model processing process, the first preset threshold can be set to a higher value to appropriately reduce the number of the first knowledge documents.
[0052] It is also possible not to refer to the first preset threshold and directly retrieve the knowledge document with the highest relevance to the question information of the first conversation as the first knowledge document. For example, assume that the question information of the first conversation input by the user is q. First, perform a pre-retrieval on the external document knowledge base. According to the general full-text retrieval method, the knowledge document m with the highest relevance to q can be retrieved from the external document library.
[0053] Next, step 103 is executed. A first sub-database can be retrieved according to the question information of the first conversation to obtain multiple first hint samples, where the first hint samples include the question information of the conversation, as well as the knowledge documents and knowledge content corresponding to the question information of the conversation, and the similarity of the multiple first hint samples to the question information of the first conversation is not less than a second preset threshold.
[0054] In one embodiment, before receiving the question information of the first conversation input by the user, it may further include: pre - establishing a first seed database, where the first seed database contains prompt samples composed of question information of different conversations, as well as knowledge documents and knowledge content corresponding to the question information of different conversations.
[0055] The following illustrates how to specifically construct the prompt samples in the first seed database by way of examples:
[0056] The prompt samples in the first seed database can be constructed according to historical conversation data and labeled knowledge document information. For the knowledge generation stage, according to the user input q, the corresponding first knowledge document m, and the knowledge content k that needs to be predicted and generated by the model, the prompt samples in the first seed database are constructed. Hereinafter, the first seed database is referred to as the knowledge generation seed database D1, and the specific composition of each prompt sample d1 can be: m + q + k. The following is the constructed prompt template for knowledge generation:
[0057] [Knowledge document]m [User input]q => k
[0058] Figure 2 This is the flowchart of the method for retrieving multiple first prompt samples from the first seed database in the embodiment of the present invention. As Figure 2 shown, in one embodiment, the method for retrieving multiple first prompt samples from the first seed database may include:
[0059] Retrieve the first seed database according to the question information of the first conversation to obtain multiple first prompt samples, including:
[0060] Step 201: Use a pre - trained sentence encoder to obtain the vector corresponding to each prompt sample in the first seed database and the vector corresponding to the question information of the first conversation;
[0061] Step 202: Calculate the cosine similarity between the vector corresponding to each prompt sample in the first seed database and the vector corresponding to the question information of the first conversation;
[0062] Step 203: Take the calculated cosine similarity as the similarity between each prompt sample in the first seed database and the question information of the first conversation;
[0063] Step 204: Take the prompt samples in the first seed database whose similarity to the question information of the first conversation is not less than the second preset threshold as the first prompt samples.
[0064] After retrieving multiple first hint samples, step 104 is executed. The question information of the first conversation, the first knowledge document, and multiple first hint samples can be input into a large-scale pre-trained language model to output first knowledge content, where the large-scale pre-trained language model is constructed based on an imitation learning strategy.
[0065] In one embodiment, the knowledge content can be characterized as new knowledge inferred based on the question information of the conversation and the knowledge document related to the question information of the conversation. For example, assume the question information proposed by the user is: How many points are required to promote a certain membership level from level 5 to level 7? The relevant knowledge document obtained by retrieving the document knowledge base is: It takes 5 points to promote from level 5 to level 6, and 6 points to promote from level 6 to level 7; then the knowledge content that can be inferred based on the above-described question information and knowledge document is: It takes 11 points to promote from level 5 to level 7.
[0066] After outputting the knowledge content, to reply to the user in the form of a complete conversation, reply information also needs to be generated based on the knowledge content. In step 105, a second sub-database can be retrieved according to the question information of the first conversation to obtain multiple second hint samples, where the second hint samples include the question information of the conversation, as well as the knowledge content and reply information corresponding to the question information of the conversation, and the similarity between the multiple second hint samples and the question information of the first conversation is not less than a third preset threshold.
[0067] In one embodiment, before receiving the question information of the first conversation input by the user, it may further include: pre-establishing a second sub-database, where the second sub-database contains hint samples composed of the question information of different conversations, as well as the knowledge content and reply information corresponding to the question information of different conversations.
[0068] The following illustrates by way of example how to specifically construct the hint samples in the second sub-database:
[0069] For the reply generation stage, according to the user input, the corresponding knowledge content, and the knowledge reply statement r that needs to be predicted and generated by the model, construct the hint samples in the second sub-database. The following content refers to the second sub-database as the reply generation seed database D2, and the specific composition of each sample d2 is: k + q + r. The hint template for reply generation is constructed as follows:
[0070] [Knowledge content]k[User input]q => r
[0071] Under the limitation of limited annotation resources, the scale of the seed database can be small, but the diversity of knowledge should be pursued as much as possible.
[0072] Figure 3 This is the method flowchart for retrieving multiple second hint samples from the second sub-database in the embodiments of the present invention. AsFigure 3 As shown in the figure, in one embodiment, the method for retrieving a plurality of second prompt samples from the second seed database may include:
[0073] Step 301: Use a pre-trained sentence encoder to obtain the vector corresponding to each prompt sample in the second seed database and the vector corresponding to the question information of the first conversation.
[0074] Step 302: Calculate the cosine similarity between the vector corresponding to each prompt sample in the second seed database and the vector corresponding to the question information of the first conversation.
[0075] Step 303: Use the calculated cosine similarity as the similarity between each prompt sample in the second seed database and the question information of the first conversation.
[0076] Step 304: Use the prompt samples in the second seed database whose similarity to the question information of the first conversation is not less than the third preset threshold as the second prompt samples.
[0077] After obtaining a plurality of second prompt samples, step 106 can be executed. The question information of the first conversation, the first knowledge content, and the plurality of second prompt samples can be input into a large-scale pre-trained language model to output the response information of the first conversation.
[0078] In one embodiment, the large-scale pre-trained language model may include one of the following models: GPT-3 model, GLM model, or ERNIE model.
[0079] It should be noted that since the large-scale pre-trained language model in the embodiments of the present invention is constructed based on an imitation learning strategy, before applying the model, there is no need to train the model with a large amount of training data. Based on the imitation learning strategy, the first knowledge content can be output according to multiple first knowledge documents and first prompt samples, or the response information of the first conversation can be output according to the first knowledge content and multiple second prompt samples. That is to say, the large-scale pre-trained language models in steps 104 and 106 can be either the same model or different models, which can be set according to the actual situation. If cost savings are desired, only one large-scale pre-trained language model can be used to execute steps 104 and 106. If efficiency is to be improved, two large-scale pre-trained language models can also be separately set to execute steps 104 and 106.
[0080] The following combines Figure 4 、 Figure 5 and Figure 6 to provide a more complete description of the dialogue generation method of the present invention:
[0081] Figure 4Shows a schematic diagram of a specific example in the knowledge content generation stage of the present invention. As Figure 4 shown, in the knowledge generation stage, according to the user input q, similar samples are searched from the seed database D1 to construct an input prompt. To ensure that the selected samples are relevant to q, a pre-trained sentence encoder can be used to obtain the vector representations of q and q in each data sample, calculate the cosine similarity of the sentence vectors of q and q i as the similarity score, and select the n example samples with the highest scores to construct the input prompt Prompt. The prompt example sample i constructed by the i-th example sample is represented as follows: i The representation of
[0082] sample i =[Knowledge document]m i [User input]q i =>k i
[0083] Each sample is separated by the line break symbol "\n", and then the user input and the retrieved knowledge document are concatenated at the end. The specific composition of the prompt is as follows:
[0084] Prompt1 = sample1\n sample2\n.....sample n \n[Knowledge document]m[User input]q =>
[0085] The prompt is input into a pre-trained large language model (LM is the abbreviation for large pre-trained language model) to generate the knowledge content k':
[0086] k' = LM(Prompt1)
[0087] Figure 5 Shows a schematic diagram of a specific example in the response generation stage of the present invention. As Figure 5 shown, in the response generation stage, according to the user input q, similar samples are searched from the seed database D2 to construct an input prompt. Similar to step 4, a pre-trained sentence encoder can be used to obtain the vector representations of q and q in each data sample, calculate the cosine similarity of the sentence vectors of q and q i as the similarity score, and select the n example samples with the highest scores to construct the input prompt Prompt. The prompt example sample i constructed by the i-th example sample is represented as follows: i The representation of
[0088] sample i =[Knowledge content]k i [User input]q i =>ri
[0089] Each sample is separated by the line break symbol "\n", and then the user input and the retrieved knowledge document are concatenated at the end. The specific composition of the prompt is as follows:
[0090] Prompt2 = sample1\n sample2\n.....sample n \n[Knowledge content]k′[User input]q =>
[0091] Input the prompt into the pre-trained large-scale language model to generate a response statement r′:
[0092] r′ = LM(Prompt2)
[0093] Figure 6 Fig. shows an overall flowchart of the dialogue generation method in an embodiment of the present invention. As Figure 6 shown, given the user input, the entire process is divided into two stages: knowledge generation and response generation. During the knowledge generation process, first, relevant knowledge documents are retrieved from the document knowledge base according to the user input, then n example samples similar to the user input are retrieved from the knowledge generation seed database, and then an input prompt for the pre-trained language model is constructed based on these example samples and the knowledge documents, and input into the pre-trained model to generate knowledge content. In the response generation stage, similarly, n example samples are retrieved from the response generation seed database according to the user input, and an input prompt is constructed based on the example samples and the knowledge content generated in the previous stage to guide the prediction of the response statement in the pre-trained language model.
[0094] The beneficial effects of the dialogue generation method in the embodiments of the present invention are as follows:
[0095] (1) The present invention adopts a method based on a large-scale pre-trained language model. This method relies on the general natural language processing ability of the large-scale pre-trained language model and can quickly and efficiently migrate to dialogue scenarios in other knowledge fields based on the imitation learning strategy with a small amount of sample data, avoiding the need to reorganize the external knowledge base and dialogue data in the migration field and saving the steps of fine-tuning and retraining, thus saving the time and resource consumption brought by domain migration.
[0096] (2) Convert the knowledge selection process in the existing knowledge-driven dialogue system-related work into a knowledge generation task based on the model learning strategy. According to the example samples retrieved from the seed database that are similar to the user input, construct an input prompt for the pre-trained language model to encourage the model to infer and generate specific knowledge content based on the knowledge document, which can effectively improve the accuracy of knowledge selection in the knowledge document in complex scenarios and improve the response quality.
[0097] An embodiment of the present invention also provides a dialogue generation device as described in the following embodiments. Since the principle of solving problems by this device is similar to that of the dialogue generation method, the implementation of this device can refer to the implementation of the dialogue generation method, and the repeated parts will not be elaborated.
[0098] Figure 7 It is a structural schematic diagram of the dialogue generation device in an embodiment of the present invention. As Figure 7 shown, the dialogue generation device in an embodiment of the present invention may specifically include:
[0099] A problem information receiving module 701, configured to receive the problem information of the first dialogue input by the user;
[0100] A document knowledge base retrieval module 702, configured to retrieve a document knowledge base according to the problem information of the first dialogue to obtain multiple first knowledge documents, where the relevance of the multiple first knowledge documents to the problem information of the first dialogue is not less than a first preset threshold;
[0101] A first seed database retrieval module 703, configured to retrieve a first seed database according to the problem information of the first dialogue to obtain multiple first prompt samples, where the first prompt samples include the problem information of the dialogue, as well as the knowledge documents and knowledge content corresponding to the problem information of the dialogue, and the similarity of the multiple first prompt samples to the problem information of the first dialogue is not less than a second preset threshold;
[0102] A first knowledge content output module 704, configured to input the problem information of the first dialogue, the first knowledge documents, and the multiple first prompt samples into a large-scale pre-trained language model, and output first knowledge content, where the large-scale pre-trained language model is constructed based on an imitation learning strategy;
[0103] A second seed database retrieval module 705, configured to retrieve a second seed database according to the problem information of the first dialogue to obtain multiple second prompt samples, where the second prompt samples include the problem information of the dialogue, as well as the knowledge content and reply information corresponding to the problem information of the dialogue, and the similarity of the multiple second prompt samples to the problem information of the first dialogue is not less than a third preset threshold;
[0104] A reply information output module 706, configured to input the problem information of the first dialogue, the first knowledge content, and the multiple second prompt samples into a large-scale pre-trained language model, and output the reply information of the first dialogue.
[0105] In one embodiment, it further includes a document knowledge base establishment module, configured to: before the problem information receiving module 701 receives the problem information of the first dialogue input by the user:
[0106] A first seed database is established in advance, and the first seed database contains hint samples composed of question information of different conversations, as well as knowledge documents and knowledge content corresponding to the question information of different conversations.
[0107] In one embodiment, it further includes a first seed database establishment module, which is used before the question information receiving module 701 receives the question information of the first conversation input by the user:
[0108] A first seed database is established in advance, and the first seed database contains hint samples composed of question information of different conversations, as well as knowledge documents and knowledge content corresponding to the question information of different conversations.
[0109] In one embodiment, the first seed database retrieval module 703 is specifically used for:
[0110] Using a pre-trained sentence encoder, obtain the vector corresponding to each hint sample in the first seed database, and the vector corresponding to the question information of the first conversation;
[0111] Calculate the cosine similarity between the vector corresponding to each hint sample in the first seed database and the vector corresponding to the question information of the first conversation;
[0112] Take the calculated cosine similarity as the similarity between each hint sample in the first seed database and the question information of the first conversation;
[0113] Take the hint samples in the first seed database whose similarity to the question information of the first conversation is not less than the second preset threshold as the first hint samples.
[0114] In one embodiment, it further includes a second seed database establishment module, which is used before the question information receiving module 701 receives the question information of the first conversation input by the user:
[0115] A second seed database is established in advance, and the second seed database contains hint samples composed of question information of different conversations, as well as knowledge content and reply information corresponding to the question information of different conversations.
[0116] In one embodiment, the second seed database retrieval module 705 is specifically used for:
[0117] Using a pre-trained sentence encoder, obtain the vector corresponding to each hint sample in the second seed database, and the vector corresponding to the question information of the first conversation;
[0118] Calculate the cosine similarity between the vector corresponding to each hint sample in the second seed database and the vector corresponding to the question information of the first conversation;
[0119] Use the calculated cosine similarity as the similarity between each prompt sample in the second seed database and the question information of the first conversation;
[0120] Use the prompt samples in the second seed database whose similarity to the question information of the first conversation is not less than the third preset threshold as the second prompt samples.
[0121] In one embodiment, the knowledge content representation is new knowledge inferred based on the question information of the conversation and knowledge documents related to the question information of the conversation.
[0122] In one embodiment, the large-scale pre-trained language model includes one of the following models:
[0123] GPT-3 model, GLM model or ERNIE model.
[0124] Based on the foregoing inventive concept, as Figure 8 shown, the present invention also proposes a computer device 800, including a memory 810, a processor 820, and a computer program 830 stored in the memory 810 and operable on the processor 820. When the processor 820 executes the computer program 830, the foregoing conversation generation method is implemented.
[0125] The embodiment of the present invention also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the foregoing conversation generation method is implemented.
[0126] The embodiment of the present invention also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the foregoing conversation generation method is implemented.
[0127] In summary, in the embodiment of the present invention, the question information of the first conversation input by the user is received; a document knowledge base is retrieved according to the question information of the first conversation to obtain a plurality of first knowledge documents; a first seed database is retrieved according to the question information of the first conversation to obtain a plurality of first prompt samples, where the first prompt samples include the question information of the conversation, as well as the knowledge documents and knowledge content corresponding to the question information of the conversation; the question information of the first conversation, the first knowledge documents, and the plurality of first prompt samples are input into a large-scale pre-trained language model to output first knowledge content, and the large-scale pre-trained language model is constructed based on an imitation learning strategy; a second seed database is retrieved according to the question information of the first conversation to obtain a plurality of second prompt samples, where the second prompt samples include the question information of the conversation, as well as the knowledge content and reply information corresponding to the question information of the conversation; the question information of the first conversation, the first knowledge content, and the plurality of second prompt samples are input into the large-scale pre-trained language model to output the reply information of the first conversation.
[0128] By introducing knowledge and converting the knowledge selection process in knowledge-driven dialogue system related work into a knowledge generation task based on an imitation learning strategy, an input prompt for a pre-trained language model is constructed based on prompt samples retrieved from a seed database that are similar to the dialogue questions input by the user, motivating the model to reason based on knowledge documents and generate specific knowledge content, which can improve the accuracy of knowledge selection in complex scenarios; in the response generation stage of the dialogue, an imitation learning strategy is adopted, and in the case of only constructing a small amount of example sample data, a large-scale language model can generate high-quality responses containing correct knowledge according to the user input and the knowledge content obtained in the knowledge generation stage.
[0129] Those skilled in the art should understand that the embodiments of the present invention can be provided as a method, a system, or a computer program product. Therefore, the present invention can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0130] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate a device for implementing the functions specified in Figure 1 one or more of the flows Figure 1 or multiple flows and / or blocks
[0131] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured article including an instruction device, and the instruction device implements the functions specified in Figure 1 one or more of the flows Figure 1 or multiple flows and / or blocks
[0132] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide for implementing the functions in the processFigure 1 one process or multiple processes and / or boxes Figure 1 steps of functions specified in one box or multiple boxes.
[0133] In the specific embodiments described above, the purpose, technical solutions and beneficial effects of the present invention have been further described in detail. It should be understood that the above are only specific embodiments of the present invention and are not used to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A dialogue generation method, characterized in that, Including: Receiving the problem information of the first conversation input by the user; Retrieving the document knowledge base according to the problem information of the first conversation to obtain multiple first knowledge documents; Retrieving the first sub-database according to the problem information of the first conversation to obtain multiple first prompt samples, where the first prompt samples include the problem information of the conversation, as well as the knowledge documents and knowledge content corresponding to the problem information of the conversation; Inputting the problem information of the first conversation, the first knowledge documents, and multiple first prompt samples into a large-scale pre-trained language model to output the first knowledge content, and the large-scale pre-trained language model is constructed based on an imitation learning strategy; Retrieving the second sub-database according to the problem information of the first conversation to obtain multiple second prompt samples, where the second prompt samples include the problem information of the conversation, as well as the knowledge content and reply information corresponding to the problem information of the conversation; Inputting the problem information of the first conversation, the first knowledge content, and multiple second prompt samples into a large-scale pre-trained language model to output the reply information of the first conversation; The knowledge content represents new knowledge inferred based on the problem information of the conversation and the knowledge documents related to the problem information of the conversation.
2. The method according to claim 1, wherein The relevance between the multiple first knowledge documents and the problem information of the first conversation is not less than a first preset threshold; The similarity between the multiple first prompt samples and the problem information of the first conversation is not less than a second preset threshold; The similarity between the multiple second prompt samples and the problem information of the first conversation is not less than a third preset threshold.
3. The method according to claim 1, wherein Before receiving the problem information of the first conversation input by the user, it further includes: Pre-establishing a document knowledge base, which contains a large number of knowledge documents covering various types of knowledge.
4. The method according to claim 1, wherein Before receiving the problem information of the first conversation input by the user, it further includes: Pre-establishing a first sub-database, which contains prompt samples composed of the problem information of different conversations, as well as the knowledge documents and knowledge content corresponding to the problem information of different conversations.
5. The method according to claim 4, wherein Retrieving the first sub-database according to the problem information of the first conversation to obtain multiple first prompt samples, including: Using a pre-trained sentence encoder to obtain the vector corresponding to each prompt sample in the first sub-database, as well as the vector corresponding to the problem information of the first conversation; Calculating the cosine similarity between the vector corresponding to each prompt sample in the first sub-database and the vector corresponding to the problem information of the first conversation; Taking the calculated cosine similarity as the similarity between each prompt sample in the first sub-database and the problem information of the first conversation; Taking the prompt samples in the first sub-database whose similarity to the problem information of the first conversation is not less than the second preset threshold as the first prompt samples.
6. The method according to claim 1, characterized in that, Before receiving the problem information of the first conversation input by the user, it further includes: Pre-establishing a second sub-database, which contains prompt samples composed of the problem information of different conversations, as well as the knowledge content and reply information corresponding to the problem information of different conversations.
7. The method according to claim 6, wherein Retrieving the second sub-database according to the problem information of the first conversation to obtain multiple second prompt samples, including: Using a pre-trained sentence encoder, obtain the vectors corresponding to each prompt sample in the second sub-database and the vector corresponding to the question information of the first conversation; Calculate the cosine similarity between the vector corresponding to each prompt sample in the second sub-database and the vector corresponding to the question information of the first conversation; Use the calculated cosine similarity as the similarity between each prompt sample in the second sub-database and the question information of the first conversation; Use the prompt samples in the second sub-database whose similarity to the question information of the first conversation is not less than the third preset threshold as the second prompt samples.
8. The method according to claim 1, wherein The large-scale pre-trained language model includes one of the following models: GPT-3 model, GLM model or ERNIE model.
9. A dialogue generation device, characterized in that, Including: A question information receiving module, configured to receive the question information of the first conversation input by the user; A document knowledge base retrieval module, configured to retrieve a document knowledge base according to the question information of the first conversation to obtain a plurality of first knowledge documents; A first sub-database retrieval module, configured to retrieve a first sub-database according to the question information of the first conversation to obtain a plurality of first prompt samples, where the first prompt samples include the question information of the conversation, and the knowledge documents and knowledge contents corresponding to the question information of the conversation; A first knowledge content output module, configured to input the question information of the first conversation, the first knowledge documents and a plurality of first prompt samples into a large-scale pre-trained language model, and output first knowledge content, where the large-scale pre-trained language model is constructed based on an imitation learning strategy; A second sub-database retrieval module, configured to retrieve a second sub-database according to the question information of the first conversation to obtain a plurality of second prompt samples, where the second prompt samples include the question information of the conversation, and the knowledge content and reply information corresponding to the question information of the conversation; A reply information output module, configured to input the question information of the first conversation, the first knowledge content and a plurality of second prompt samples into a large-scale pre-trained language model, and output the reply information of the first conversation; The knowledge content representation is new knowledge inferred according to the question information of the conversation and the knowledge documents related to the question information of the conversation.
10. The device according to claim 9, characterized in that, The relevance between the plurality of first knowledge documents and the question information of the first conversation is not less than a first preset threshold; The similarity between the plurality of first prompt samples and the question information of the first conversation is not less than a second preset threshold; The similarity between the plurality of second prompt samples and the question information of the first conversation is not less than a third preset threshold.
11. The device according to claim 9, characterized in that It further includes a document knowledge base establishment module, configured to: before the question information receiving module receives the question information of the first conversation input by the user: Pre-establish a first sub-database, where the first sub-database contains prompt samples composed of question information of different conversations, and knowledge documents and knowledge contents corresponding to the question information of different conversations.
12. The device according to claim 9, characterized in that It further includes a first sub-database establishment module, configured to: before the question information receiving module receives the question information of the first conversation input by the user: Pre-establish a first sub-database, where the first sub-database contains prompt samples composed of question information of different conversations, and knowledge documents and knowledge contents corresponding to the question information of different conversations.
13. The device according to claim 12, wherein The first seed database retrieval module is specifically configured to: Use a pre-trained sentence encoder to obtain the vector corresponding to each prompt sample in the first seed database and the vector corresponding to the question information of the first conversation; Calculate the cosine similarity between the vector corresponding to each prompt sample in the first seed database and the vector corresponding to the question information of the first conversation; Take the calculated cosine similarity as the similarity between each prompt sample in the first seed database and the question information of the first conversation; Take the prompt samples in the first seed database whose similarity to the question information of the first conversation is not less than the second preset threshold as the first prompt samples.
14. The device according to claim 9, characterized in that, It further includes a second seed database establishment module, which is used before the question information receiving module receives the question information of the first conversation input by the user: Pre-establish a second seed database, where the second seed database contains prompt samples composed of question information from different conversations, as well as knowledge content and reply information corresponding to the question information of different conversations.
15. The device according to claim 14, wherein The second seed database retrieval module is specifically configured to: Use a pre-trained sentence encoder to obtain the vector corresponding to each prompt sample in the second seed database and the vector corresponding to the question information of the first conversation; Calculate the cosine similarity between the vector corresponding to each prompt sample in the second seed database and the vector corresponding to the question information of the first conversation; Take the calculated cosine similarity as the similarity between each prompt sample in the second seed database and the question information of the first conversation; Take the prompt samples in the second seed database whose similarity to the question information of the first conversation is not less than the third preset threshold as the second prompt samples.
16. The device according to claim 9, characterized in that The large-scale pre-trained language model includes one of the following models: GPT-3 model, GLM model or ERNIE model.
17. A computer device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that When the processor executes the computer program, it implements the method according to any one of claims 1 to 8.
18. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, it implements the method according to any one of claims 1 to 8.
19. A computer program product, characterized in that, The computer program product includes a computer program, and when the computer program is executed by the processor, it implements the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Model training method and device, dialogue system evaluation method and device, equipment and storage medium
CN110188331A
Question answering method and device, electronic equipment and computer readable storage medium
CN116244418A