Intelligent dialogue method, model training method, device, storage medium and equipment
By adding model-generated predicted reply text and using a measurement classifier during the training process of the chat-type dialogue robot, the problem of incoherent conversations of the chat-type dialogue robot was solved, and the coherence and consistency of the reply content were achieved.
Patent Information
- Application Number
- CN202111638883.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-29
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2041-12-29
AI Technical Summary
When used online, small talk bots often generate responses that are repetitive or contradictory to the previous text, resulting in incoherent conversations.
By adding the predicted response text generated by the dialogue model during the training process, simulating actual usage scenarios, and using a test classifier to evaluate the coherence of the response, we ensure that the response generated by the dialogue model is consistent with the previous response.
Improved the conversational coherence of chatbots, ensuring that replies are consistent with previous responses and enhancing the user experience.
Smart Images

Figure CN116414951B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of information processing technology, and specifically to an intelligent dialogue method, a model training method, an intelligent dialogue device, an intelligent dialogue model training device, a computer-readable storage medium, and a computer device. Background Art
[0002] Currently, small talk bots are widely used in various software. However, in actual online use, these bots often generate repetitive or contradictory responses, resulting in incoherent conversations between the bot and the user. Summary of the Invention
[0003] The embodiments of the present application provide an intelligent dialogue method, model training method, device, storage medium and equipment, which can ensure the continuity of the intelligent dialogue content.
[0004] On the one hand, an intelligent dialogue method is provided, which includes: obtaining a first historical dialogue to be replied; inputting the first historical dialogue into a trained dialogue model to generate a first reply text, wherein the dialogue model is pre-trained using real historical dialogues and predicted reply texts, and the predicted reply text is generated by the dialogue model; replying to the first historical dialogue according to the first reply text; obtaining a second historical dialogue to be replied, wherein the second historical dialogue includes at least the first reply text; inputting the second historical dialogue into the trained dialogue model to generate a second reply text; and replying to the second historical dialogue according to the second reply text.
[0005] On the other hand, a model training method for intelligent dialogue is provided, which includes: obtaining multiple rounds of real historical dialogues; obtaining dialogues to be replaced and sampling samples from the multiple rounds of real historical dialogues; inputting the sampling samples into the dialogue model to generate predicted reply texts; using the predicted reply texts to replace the dialogues to be replaced in the multiple rounds of real historical dialogues to obtain training samples; and pre-training the dialogue model based on the training samples to obtain a trained dialogue model.
[0006] On the other hand, an intelligent dialogue device is provided, comprising: a first acquisition unit for acquiring a first historical dialogue to be replied, and for acquiring a second historical dialogue to be replied, wherein the second historical dialogue at least includes the first reply text; a first generation unit for inputting the first historical dialogue into a trained dialogue model to generate a first reply text, and for inputting the second historical dialogue into the trained dialogue model to generate a second reply text, wherein the dialogue model is pre-trained using real historical dialogues and predicted reply texts, and the predicted reply text is generated by the dialogue model; and a reply unit for replying to the first historical dialogue according to the first reply text, and for replying to the second historical dialogue according to the second reply text.
[0007] On the other hand, a model training device for intelligent dialogue is provided, characterized in that the device includes: a second acquisition unit for acquiring multiple rounds of real historical dialogues; a sampling unit for acquiring dialogues to be replaced and sampling samples from multiple rounds of the real historical dialogues; a second generation unit for inputting the sampling samples into the dialogue model to generate predicted reply texts; a replacement unit for replacing the dialogues to be replaced in multiple rounds of the real historical dialogues with the predicted reply texts to obtain training samples; and a first training unit for pre-training the dialogue model based on the training samples to obtain a trained dialogue model.
[0008] On the other hand, a computer-readable storage medium is provided, which stores a computer program, and the computer program is suitable for loading by a processor to execute the steps in the intelligent dialogue method described in any of the above embodiments or the model training method for intelligent dialogue described in any of the above embodiments.
[0009] On the other hand, a computer device is provided, comprising a processor and a memory, wherein a computer program is stored in the memory, and the processor is configured to execute the steps of the intelligent dialogue method described in any of the above embodiments or the model training method for intelligent dialogue described in any of the above embodiments by calling the computer program stored in the memory.
[0010] On the other hand, a computer program product is provided, comprising computer instructions, which, when executed by a processor, implement the steps of the intelligent dialogue method described in any of the above embodiments or the model training method for intelligent dialogue described in any of the above embodiments.
[0011] The embodiment of the present application comprises obtaining a first historical conversation to be replied to; inputting the first historical conversation into a trained conversation model to generate a first reply text, wherein the conversation model is pre-trained using real historical conversations and predicted reply text, and the predicted reply text is generated by the conversation model; replying to the first historical conversation based on the first reply text; obtaining a second historical conversation to be replied to, wherein the second historical conversation includes at least the first reply text; inputting the second historical conversation into the trained conversation model to generate a second reply text; and replying to the second historical conversation based on the second reply text. In the embodiment of the present application, the first reply text can be considered as the historical reply text previously generated by the conversation model, the second historical conversation can be considered as the most recent text to be replied to, and the second reply text can be considered as the reply text generated by the conversation model this time, wherein the second historical conversation includes at least the first reply text. In this way, the text to be replied to input into the conversation model includes at least the historical reply text previously generated by the conversation model, so that the reply text generated by the conversation model this time is consistent with the content of the previous historical reply text, thereby ensuring the coherence of the intelligent conversation content. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0013] Figure 1 Schematic diagram of the application scenario of the intelligent dialogue method provided in the application embodiment.
[0014] Figure 2 A flowchart of the intelligent dialogue method provided in an embodiment of the present application.
[0015] Figure 3 A flowchart of the intelligent dialogue method provided in an embodiment of the present application.
[0016] Figure 4 A flowchart of the model training method for intelligent dialogue provided in an embodiment of the present application.
[0017] Figure 5 The scenario intention for the intelligent dialogue model training provided in the embodiments of the present application.
[0018] Figure 6 A flowchart of the model training method for intelligent dialogue provided in an embodiment of the present application.
[0019] Figure 7 The scenario intention for the intelligent dialogue model training provided in the embodiments of the present application.
[0020] Figure 8 A flowchart of the model training method for intelligent dialogue provided in an embodiment of the present application.
[0021] Figure 9 The scenario intention for the intelligent dialogue model training provided in the embodiments of the present application.
[0022] Figure 10 A flowchart of the model training method for intelligent dialogue provided in an embodiment of the present application.
[0023] Figure 11 A flowchart of the model training method for intelligent dialogue provided in an embodiment of the present application.
[0024] Figure 12 A flowchart of the model training method for intelligent dialogue provided in an embodiment of the present application.
[0025] Figure 13A flowchart of the model training method for intelligent dialogue provided in an embodiment of the present application.
[0026] Figure 14 This is a schematic diagram of the structure of the intelligent dialogue device provided in an embodiment of the present application.
[0027] Figure 15 This is a schematic diagram of the structure of the intelligent dialogue device provided in an embodiment of the present application.
[0028] Figure 16 A schematic diagram of the structure of the model training device for intelligent dialogue provided in an embodiment of the present application.
[0029] Figure 17 A schematic diagram of the structure of the model training device for intelligent dialogue provided in an embodiment of the present application.
[0030] Figure 18 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without making creative efforts are within the scope of protection of this application.
[0032] The embodiments of the present application provide an intelligent dialogue method, a model training method, an apparatus, a computer device, and a storage medium. Specifically, the intelligent dialogue method and the model training method of the embodiments of the present application can be executed by a computer device, wherein the computer device can be a terminal or a server. The terminal can be a smart phone, a tablet computer, a laptop computer, a smart TV, a smart speaker, a wearable smart device, a smart car terminal, and the like. The terminal can also include a client, which can be a video client, a browser client, or an instant messaging client, etc. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0033] The embodiments of the present application can be applied to various scenarios such as instant messaging (such as WeChat, QQ, robot chat, etc.), natural language processing, machine learning, deep learning, cloud technology, artificial intelligence, smart transportation, etc.
[0034] First, some nouns or terms that appear in the description of the embodiments of this application are explained as follows:
[0035] Artificial Intelligence (AI) is the theory, methods, techniques, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, to perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that seeks to understand the essence of intelligence and produce new intelligent machines that can respond in a manner similar to human intelligence. AI also studies the design principles and implementation methods of various intelligent machines, enabling them to possess the capabilities of perception, reasoning, and decision-making.
[0036] Machine Learning (ML) is a multidisciplinary field that encompasses probability theory, statistics, approximation theory, convex analysis, and algorithmic complexity theory. It specifically studies how computers can simulate or implement human learning behaviors to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is at the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications span all areas of AI. Machine learning and deep learning typically include techniques such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and self-learning.
[0037] Natural language processing (NLP) is a key area of research in computer science and artificial intelligence. It studies the theories and methods that enable effective communication between humans and computers using natural language. Natural language processing (NLP) integrates linguistics, computer science, and mathematics. Therefore, research in this field involves natural language—the language we use in everyday life—and is closely linked to the study of linguistics. Natural language processing technologies typically include text processing, semantic understanding, machine translation, robotic question answering, and knowledge graphs.
[0038] Deep learning (DL): A branch of machine learning, it is an algorithm that attempts to achieve high-level abstraction of data using multiple processing layers containing complex structures or multiple nonlinear transformations. Deep learning learns the inherent patterns and representational hierarchies of training sample data. The information gained from this learning process is highly helpful in interpreting data such as text, images, and sound. The ultimate goal of deep learning is to enable machines to have human-like analytical learning capabilities and to recognize data such as text, images, and sound. Deep learning is a complex machine learning algorithm that has achieved results in speech and image recognition that far surpass previous related technologies.
[0039] Smart transportation is to make full use of the Internet of Things, spatial perception, cloud computing, mobile Internet and other new generation information technologies in the entire transportation field, and comprehensively apply theories and tools such as transportation science, system methods, artificial intelligence, knowledge mining, etc., with the goals of comprehensive perception, deep integration, proactive service, and scientific decision-making. By building a real-time dynamic information service system, deeply mining transportation-related data, forming a problem analysis model, and realizing the improvement of the industry's resource allocation optimization capabilities, public decision-making capabilities, industry management capabilities, and public service capabilities, it will promote safer, more efficient, more convenient, more economical, more environmentally friendly, and more comfortable operation and development of transportation, and drive the transformation and upgrading of transportation-related industries.
[0040] Cloud technology: refers to a hosting technology that unifies hardware, software, network and other resources within a wide area network or local area network to achieve data computing, storage, processing and sharing. Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool that can be used on demand and is flexible and convenient. Cloud computing technology will become an important support. The backend services of technical network systems require a large amount of computing and storage resources, such as video websites, image websites and more portals. With the rapid development and application of the Internet industry, every item may have its own identification mark in the future, and all need to be transmitted to the backend system for logical processing. Data of different levels will be processed separately. All kinds of industry data require strong system support, which can only be achieved through cloud computing.
[0041] A blockchain system is a distributed system consisting of clients and multiple nodes (any type of computing device connected to the network, such as servers and user terminals) connected through network communications. The nodes form a peer-to-peer (P2P) network. The P2P protocol is an application layer protocol that runs on top of the Transmission Control Protocol (TCP). In a distributed system, any machine, such as a server or terminal, can become a node. Nodes are composed of hardware, middleware, operating system, and application layers.
[0042] With the development of end-to-end pre-trained language models, chatbots have achieved relatively satisfactory results on standard datasets. However, in actual online use, chatbots often generate replies that are repetitive or contradictory to previous responses. This is primarily due to a significant mismatch between the training and evaluation of current chatbots and actual online use. When training and evaluating models on standard datasets, the chatbot's conversational model is fed real conversation histories, which then generate predicted responses based on these real conversation histories. However, in actual use, the conversational history fed into the conversational model includes both user-entered responses and responses predicted by the model in previous rounds, potentially requiring the model to predict responses for conversations it has not been trained on. This inconsistency between the conversational history fed into the model during training and in actual use is a major cause of the model's unstable performance in real-world use. To alleviate this inconsistency, the present invention proposes a sampling-based strategy. During the training process, some model decoding—that is, the predicted responses generated by the conversational model—is added to the conversational history fed into the conversational model to simulate actual use scenarios. The present invention also proposes a measurement classifier that assesses the coherence between the responses generated by the conversational model and the conversational history.
[0043] The embodiments of this application can be implemented in conjunction with cloud technology or blockchain network technology. For example, the intelligent dialogue method and model training method disclosed in the embodiments of this application can store this data on a blockchain. For example, trained intelligent dialogue models, intelligent dialogue evaluation models, dialogue history, and evaluation results can all be stored on a blockchain.
[0044] In order to facilitate the storage and query of the trained dialogue model and the trained evaluation classifier, the intelligent dialogue method optionally further includes: sending the trained dialogue model and the trained evaluation classifier to the blockchain network, so that the nodes of the blockchain network fill the trained dialogue model and the trained evaluation classifier into a new block, and when consensus is reached on the new block, the new block is appended to the end of the blockchain. The embodiments of the present application can store the trained dialogue model and the trained evaluation and classification device on the chain to realize the backup of records. When it is necessary to use the trained dialogue model to generate a dialogue reply, for example, when the chat robot Tencent Xiaowei generates a dialogue reply based on the chat content input by the user, the corresponding trained dialogue model can be directly and quickly obtained from the blockchain, without the need to perform a series of processing on the dialogue model before obtaining the predicted reply content, thereby improving the efficiency of data analysis and processing and data acquisition; similarly, when it is necessary to use the trained evaluation and classification device to evaluate the coherence of the dialogue reply, the corresponding trained evaluation and classification device can be directly and quickly obtained from the blockchain, without the need to perform a series of processing on the evaluation and classification device before obtaining the predicted reply content, thereby improving the efficiency of data analysis and processing and data acquisition.
[0045] See also Figure 1 , Figure 1 Schematic diagram of an application scenario of the intelligent dialogue model provided in an embodiment of the present application. Taking the intelligent dialogue method executed by a computer device as an example, the computer device can be a terminal or server. During the training phase of the dialogue model, the computer device obtains training sample data, each training sample in the training sample data including multiple rounds of real historical dialogues; obtains dialogues to be replaced and sampled samples from the multiple rounds of real historical dialogues; inputs the sampled samples into the dialogue model to generate predicted reply text; replaces the dialogues to be replaced with the predicted reply text in the multiple rounds of real historical dialogues to obtain training samples; and pre-trains the dialogue model based on the training samples to obtain a trained dialogue model. During the conversation stage, the user can upload the conversation text to be replied through the client, browser client or instant messaging client installed in the computer device, such as the first historical conversation to be replied. After the computer device obtains the uploaded first historical conversation to be replied, the first historical conversation is input into the trained conversation model to generate a first reply text; the first historical conversation is replied according to the first reply text; the user can continue to upload the conversation text to be replied according to the first reply text, such as the second historical conversation to be replied, the second historical conversation at least includes the first reply text; the computer device obtains the uploaded second historical conversation to be replied; the second historical conversation is input into the trained conversation model to generate a second reply text; and the second historical conversation is replied according to the second reply text.
[0046] It should be noted that the process of generating the reply text can be completed on the server or on the terminal. When the conversation model training process and the intelligent conversation process are both completed on the server, if the trained conversation model is needed, the text to be replied to can be input into the server. After the server generates the corresponding reply text, the reply text is sent to the terminal for display. When the model training process and the intelligent conversation process are both completed on the terminal, if the trained conversation model is needed, the text to be replied to can be input into the terminal. After the terminal generates the corresponding reply text, the terminal displays the generated reply text. When the conversation model training process is completed on the server and the process of generating the reply text using the conversation model is completed on the terminal, if the trained conversation model is needed, the text to be replied to can be input into the terminal. After the terminal generates the corresponding reply text, the terminal displays the reply text. Optionally, the trained model file (model file) on the server can be ported to the terminal. If a reply to the text to be replied to is needed, the text to be replied to can be input into the trained model file (model file), and the corresponding reply text can be obtained through calculation.
[0047] It should be noted that the order of description of the following embodiments does not limit the priority order of the embodiments.
[0048] Each embodiment of the present application provides an intelligent dialogue method, which can be executed by a terminal or a server, or by a terminal and a server together; the embodiments of the present application take the intelligent dialogue method executed by a server as an example for illustration. Specifically, an artificial intelligence chat robot (hereinafter referred to as the chat robot) is provided in the terminal. For example, the chat robot is Tencent Xiaowei, and the user can have a conversation with the chat robot in the chat interface. The chat robot inputs the text to be replied entered by the user into the chat interface into the server. After the server generates the corresponding reply text, the obtained reply text is sent to the chat interface for display.
[0049] See also Figure 2 , Figure 2 This is a flow chart of an intelligent dialogue method provided in an embodiment of the present application, which includes:
[0050] Step 310: Obtain a first historical conversation to be replied to.
[0051] Optionally, the first historical conversation can be a conversation text entered by the user. For example, please combine Figure 3 In the chat interface between the user and the chat robot, the user can input the conversation text through the terminal in the chat interface by voice input, keyboard input, etc., or the user can copy the text in the clipboard from local files, web pages, cloud, etc. and paste it into the chat interface as the conversation text. There is no restriction here.
[0052] Optionally, the first historical conversation can be a conversation record between the user and the chatbot. For example, please combine Figure 3 After one or more rounds of conversation between the user and the chatbot, a conversation record is generated. The chatbot uses the conversation record as the first historical conversation to generate a corresponding reply text based on the first historical conversation.
[0053] Optionally, the first historical conversation may only include text messages sent by the user. For example, after multiple rounds of conversations between the user and the chatbot, the conversation record includes the text input by the user and the text replied by the chatbot. The chatbot only extracts the text input by the user as the first historical conversation and inputs it into the server.
[0054] Optionally, the first historical conversation may include text messages sent by the user and reply text generated by the conversation model. That is, the chatbot inputs both the user input text and the chatbot's reply text as the first historical conversation into the server, so that the server combines the user input text and the chatbot's own reply to generate the corresponding reply text.
[0055] Step 320: Input the first historical conversation into the trained conversation model to generate a first reply text. The conversation model is pre-trained using real historical conversations and predicted reply texts, and the predicted reply text is generated by the conversation model.
[0056] Optionally, in this example, the dialogue model is set on the server, and in other embodiments, the dialogue model may also be set on the terminal, which is not limited here.
[0057] Optionally, the trained dialogue model is a pre-trained model. In this example, the pre-training of the dialogue model is completed on the server. In other embodiments, the pre-training of the dialogue model can also be completed in the terminal, which is not limited here.
[0058] The pre-training of the conversation model uses real historical conversations and predicted responses as input. Real historical conversations can be conversations between real people, such as WeChat chat logs. These conversations include the actual reply text entered by the real person and the replies entered based on the actual reply text. For example, WeChat user A enters the reply text "Which team do you support?" and WeChat user B enters the reply text "I support the Lakers, what about you?" The predicted responses are generated by the conversation model based on real historical conversations. Predicted responses are generated based on the conversation model's prediction of a real person's likely response based on the content of the reply text. For example, if WeChat user A enters the reply text "Which team do you support?", the chatbot generates the predicted reply text "I support the Lakers, what about you?"
[0059] The pre-trained dialogue model can generate corresponding reply text based on the input text content. After the first historical dialogue is input into the dialogue model, the dialogue model generates a first reply text corresponding to the content of the first historical dialogue.
[0060] Step 330: Reply to the first historical conversation according to the first reply text.
[0061] Optionally, the chatbot obtains the first reply text from the dialogue model in the server and displays it in the chat interface between the user and the chatbot.
[0062] Step 340: Obtain a second historical conversation to be replied to, where the second historical conversation at least includes the first reply text.
[0063] For example, the second history dialogue is as follows:
[0064] WeChat user A: "Which team do you support?"
[0065] Chatbot: "I'm rooting for Team A, how about you?"
[0066] WeChat user A: "I don't like Team A, I like Team B!"
[0067] The first response the conversation model previously generated was "I support Team A, what about you?" In the second historical conversation, the user's input, "Which team do you support?", has already been responded to. Therefore, the response is the user's last input, "I don't like Team A, I like Team B!" If the conversation model generates responses based solely on the user inputs "Which team do you support?" and "I don't like Team A, I like Team B!", it is likely to generate content that contradicts the first response. For example, it might generate "I don't like Team A either, and like you, I support Team B!", which contradicts the chatbot's previous response.
[0068] The intelligent conversation method of the embodiment of the present application inputs previously generated reply texts into the conversation model, combining the reply text input by the real person and the content of the conversation model's own reply to generate a corresponding reply text. This ensures that the reply text generated by the conversation model is consistent with the reply text previously generated by the conversation model, ensuring the coherence of the conversation between the human and the chatbot. For example, when the second historical conversation is input into the conversation model, the conversation model generates a logically consistent reply text based on the content of the first reply text "I support Team A": "B is also a good team, but I still support Team A."
[0069] In the above-mentioned conversation record, the chatbot only responded once before generating the second reply text. Therefore, the first reply text in the above-mentioned embodiment is only a reply to one conversation. In other embodiments, when there are multiple rounds of conversations between the user and the chatbot, the first reply text can be one or more conversation records among all the replies of the chatbot in the multiple rounds of conversations. For example, if the second historical conversation includes ten reply texts replied by the chatbot, all ten reply texts can be input into the conversation model as the first reply text; or one, two, three, four, five, six, seven, eight, or nine of the ten reply texts can be selected as the first reply text and input into the conversation model, for example, the three most recent replies of the chatbot in the second historical conversation can be input into the conversation model as the first reply text.
[0070] Step 350: Input the second historical conversation into the trained conversation model to generate a second reply text.
[0071] Optionally, step 350 is similar to step 320. In this example, the terminal inputs the second historical conversation into the trained conversation model in the server to generate a second reply text.
[0072] Step 360: Reply to the second historical conversation according to the second reply text.
[0073] Optionally, step 360 is similar to step 33. In this example, the terminal obtains the second reply text from the server and displays the second reply text in the chat interface to reply to the second historical conversation.
[0074] Optional, see Figure 3 , the intelligent dialogue method also includes:
[0075] Step 370: Obtain the trained evaluation classifier.
[0076] The evaluation classifier uses an evaluation model of intelligent dialogue to evaluate the intelligent dialogue, and the trained evaluation classifier is a classifier using the trained evaluation model.
[0077] Optionally, the evaluation classifier includes any one of a coherence classifier, a safety classifier, and a legality classifier. The coherence classifier is used to evaluate the coherence between replies generated by the dialogue model, for example, evaluating whether the logic between the first and second reply texts generated by the dialogue model is consistent. The higher the degree of consistency, the higher the coherence. Similarly, the safety classifier is used to evaluate the safety of the reply content generated by the dialogue model, for example, evaluating whether the reply content contains dirty words, insulting or offensive statements, etc. The "cleaner" the reply content, the higher the safety. Similarly, the legality classifier is used to evaluate the legality of the reply content generated by the dialogue model, for example, evaluating whether the reply content contains illegal information. The less illegal information in the reply content, the higher the legality.
[0078] Optional, see Figure 3 , the intelligent dialogue method also includes:
[0079] Step 380: Input the second historical conversation and the second reply text into an evaluation classifier to obtain an evaluation score for the second reply text.
[0080] Optionally, the following description uses the example of a coherence classifier as the evaluation classifier. Because the second historical conversation contains at least the first reply text, the evaluation classifier can determine the coherence between the first reply text and the second reply text based on the context of the second historical conversation. A higher score assigned by the coherence classifier to the second reply text indicates a higher level of logical consistency between the first and second reply texts; a lower score indicates a lower level of logical consistency between the first and second reply texts.
[0081] Optional, see Figure 3 , the intelligent dialogue method also includes:
[0082] Step 390: Obtain a preset score threshold.
[0083] Optionally, a score threshold is used to evaluate the score of the second reply text and can be used as an evaluation criterion. For example, if the score of the coherence classifier is greater than the score threshold, the evaluation result is "coherent"; if the score is less than the score threshold, the evaluation result is "incoherent".
[0084] Step 3100: When the evaluation score of the second reply text is less than the score threshold, the trained dialogue model is retrained.
[0085] Alternatively, for example, if the score assigned by the coherence classifier is less than a threshold, the evaluation result is "incoherent," indicating that the second reply text generated by the trained dialogue model is still incoherent with the first reply text. The trained dialogue model can be retrained to improve the coherence of the replies generated by the dialogue model. Retraining the trained dialogue model can involve increasing the number of training cycles based on the dialogue model's existing parameters to update the parameters. For example, if the current dialogue model undergoes 1000 training cycles (iterations) to obtain first parameters, retraining the model using the first parameters as initial parameters and then undergoing another 1000 training cycles to obtain second parameters. The first parameters are then updated using the second parameters, resulting in a total of 2000 training cycles for the dialogue model. Retraining the trained dialogue model can also involve resetting the dialogue model's parameters to the initial parameters and restarting training, although this is not a limitation.
[0086] Optionally, when training a conversational model, you can integrate the conversational model with a coherence classifier, using the coherence classifier's evaluation results as the termination condition for model training. For example, you can repeatedly train the conversational model until the coherence classifier scores the response text output by the conversational model above a threshold, at which point training stops.
[0087] All of the above technical solutions can be combined in any way to form optional embodiments of the present application, and will not be described in detail here.
[0088] In summary, in the intelligent dialogue method of the embodiments of the present application, the first reply text can be considered as the historical reply text previously generated by the dialogue model, the second historical dialogue can be considered as the most recent text to be replied to, and the second reply text can be considered as the reply text generated by the dialogue model this time. The second historical dialogue at least includes the first reply text. In this way, the reply text input to the dialogue model includes at least the historical reply text previously generated by the dialogue model, so that the reply text generated by the dialogue model this time is consistent with the content of the previous historical reply text, thereby ensuring the coherence of the intelligent dialogue content. The intelligent dialogue method can also evaluate the replies generated by the dialogue model to intuitively assess the content of the replies generated by the dialogue model, for example, obtaining an evaluation of the coherence of the reply text generated by the dialogue model to intuitively reflect the effectiveness of the dialogue model generation.
[0089] See also Figure 4 , Figure 4 This is a flow chart of a method for training a model for intelligent dialogue provided in an embodiment of the present application. The method includes:
[0090] Step 510: Acquire multiple rounds of real historical conversations.
[0091] Optionally, a real historical conversation is a conversation record involving at least two people. A round of real historical conversation may include one or more sentences, which is not limited here.
[0092] Optionally, real historical conversations include real replies, which are responses from real people based on real historical conversations. The conversation model can learn from real people's responses to real historical conversations to predict the real person's response to a given reply upon receiving it, generating a predicted reply. However, in conjunction with the foregoing, in actual intelligent conversations, the second historical conversation input into the conversation model includes the first reply previously generated by the conversation model. Therefore, during conversation model training, the predicted reply generated by the conversation model is fed into the conversation model along with the real historical conversations to ensure logical coherence between the predicted reply generated by the conversation model and the previously generated predicted reply.
[0093] Step 520: Acquire the conversation to be replaced and the sample from multiple rounds of real historical conversations.
[0094] Step 530: Input the sampled text into the dialogue model to generate a predicted reply text.
[0095] Step 540 : Use the predicted reply text to replace the conversation to be replaced in multiple rounds of real historical conversations to obtain training samples.
[0096] Optionally, the sampled sample is a portion of a conversation from multiple rounds of real historical conversations. By sequentially executing steps 520, 530, and 540, the model training method provided in this embodiment of the application replaces a round of conversation from multiple rounds of real historical conversations with the predicted response text generated by the conversation model, and uses the replaced multiple rounds of real historical conversations as training samples, so that the training samples can simulate a real intelligent conversation scenario, that is, simulate an application scenario in which the second historical conversation contains the first response text previously generated by the conversation model.
[0097] Step 550: pre-train the dialogue model based on the training samples to obtain a trained dialogue model.
[0098] In this way, when pre-training the dialogue model, the training samples input to the dialogue model include predicted responses generated by the dialogue model, so that the pre-trained dialogue model can generate a second response text corresponding to the second historical dialogue based on a real intelligent dialogue scenario.
[0099] Optionally, pre-training can use end-to-end pre-training models such as BART, DialogueGPT, and Blender.
[0100] Optional, please combine Figure 5Taking the BART model as an example, the conversation model consists of an encoder and a decoder. After the encoder inputs real historical conversations, the decoder generates corresponding decodings, that is, corresponding predicted response text. During the conversation model training process, multiple rounds of real historical conversations are sampled to obtain the conversation to be replaced and the sampled samples. The predicted response text generated by the conversation model based on the sampled samples replaces the conversation to be replaced. In other words, the decoding generated by the conversation model replaces part of the real text input to the decoder. This achieves noise reduction on the decoding end and simulates real intelligent conversation scenarios.
[0101] Optional, please combine Figure 6 Step 520, obtaining the dialogue to be replaced and the sample from multiple rounds of real historical dialogues, further includes:
[0102] Step 521 : Sample the i-th round of real historical dialogue from k rounds of real historical dialogue according to geometric distribution, i∈[1,k].
[0103] Optionally, the sampling distribution may also be linear distribution.
[0104] Step 522: Use the i-th round of real historical dialogue as the dialogue to be replaced.
[0105] Step 523: Use the real historical conversations from round 1 to round i-1 as sampling samples.
[0106] Optional, please combine Figure 5 and Figure 7 , the real historical dialogue includes k rounds, k>1. Let the input k rounds of real historical dialogue be U k , U k ={u1, ...u k-1 ,…u k}, where u i Denotes the i-th round of dialogue, i∈[1, k-1]. Among them, the real dialogue history is U k Dialogue with U from real history k-1 With real reply text u k Composition, U k-1 ={u1,…,u k-1}, that is, the real reply text u k For the real history dialogue U k-1 The corresponding reply.
[0107] Please combine Figure 5 and Figure 7 The sampling process is to select the k-round real dialogue history U according to the set distribution k Select the i-th round of real historical dialogue u i As the dialogue to be replaced, and the real historical dialogue U from round 1 to round i-1 i-1 As a sampling sample, Ui-1 ={u1, ..., u i-1 After executing step 523, the sample U can be i-1 Input the dialogue model to generate the corresponding predicted reply text r i , and in step 540, in the k-round real history dialogue U k Predicted response r i Replace the real historical dialogue u in round i i , to obtain the training sample U' k For example, a k-round real history dialogue U k ={u1, u2, ..., u i ,…u k-1 ,u k}, then the training sample U' obtained after replacement k ={u1, u2, ..., r i ,…u k-1 ,u k}. Training sample U' k Used as input sample of the encoder in the pre-training of the dialogue model, in the training sample U' k It contains both the real reply text and the predicted reply text r generated by the dialogue model i , which can simulate real intelligent dialogue scenarios. Dialogue model
[0108] Optional, please combine Figure 8 In step 530, the sampled text is input into the dialogue model to generate a predicted reply text, including:
[0109] Step 531: Input the sample and the first n words of the conversation to be replaced into the conversation model to generate a predicted reply text. The first n words of the predicted reply text are the same as the first n words of the conversation to be replaced, n∈[0,m].
[0110] Please combine Figure 5 、 Figure 7 、 Figure 9 , let the conversation to be replaced u i Includes m words, namely: u i ={x1,…,x m}, x j It's a dialogue i The jth word in, j∈[1,m]; predict the reply text r i Including t words, predict the reply text r i ={y1,…,y t},y s is the predicted reply text r i The sth word in , s∈[1, t]. In order to predict the reply text r iThe content is closer to the real person's reply and can be replaced by the conversation u i The first n words {x1, ..., x n} as the predicted reply text r i The first n words {y1, ..., y n}, the dialogue model generates the predicted reply text r i The n+1th to tth words in {y n+1 ,…,y t}, the predicted reply text generated is:
[0111] r i ={x1,…,x n ,y n+1 ,……y t}.
[0112] Among them, the larger the value of n, the more likely the predicted reply text r is. i The closer the content is to the real person's reply, the smaller the value of n is, and the more likely the reply text r is to be predicted. i The more it can simulate a real intelligent dialogue scenario. When n=0, the predicted reply text r i ={y1,…,y t}, that is, the dialogue model is only based on the sample U i-1 ={u1, ..., u i-1}Generate predicted reply text r i , which is equivalent to the chatbot generating a reply based only on the text to be replied in the intelligent dialogue scenario. When n = m, the predicted reply text r i ={x1,…,x m}, that is, the reply text r i Talk to real history i-1 Corresponding reply text u i It is completely consistent, which is equivalent to the chat robot in the intelligent dialogue scenario replying to the text to be replied with the real person's reply content word for word.
[0113] Optional, please combine Figure 10 , step 550, pre-training the dialogue model based on the training sample, including:
[0114] Step 551: Input the training sample into the dialogue model to generate training response text.
[0115] Step 552 : Calculate a first cross entropy loss based on the training samples and the training reply text.
[0116] Step 553: repeatedly obtain training samples and training reply texts corresponding to the training samples, and repeatedly calculate the first cross entropy loss, and complete the pre-training when the first cross entropy loss is minimized.
[0117] Cross-entropy measures the difference between two probability distributions for the same random variable. In machine learning, this is expressed as the difference between the true and predicted probability distributions. The smaller the cross-entropy value, the better the model's predictions. In the embodiments of this application, the conversation model is pre-trained while minimizing the first cross-entropy loss, ensuring that the trained conversation model optimizes its predictions of actual responses.
[0118] Please combine Figure 5 , let the training reply text be r k+1 , represents the training sample U' k The response can be obtained based on the training sample U' k and training reply text r k+1 Construct the corresponding cross entropy loss function:
[0119]
[0120] Among them, y s is the training reply text r k+1 The sth word in , s∈[1, t]. The training sample U' can be obtained by the cross entropy loss function k With training reply text r k+1 During the pre-training process, the first cross entropy loss is back-propagated, and the training samples and the training response texts corresponding to the training samples are repeatedly input into the pre-training model for training.
[0121] Optionally, in step 553, pre-training is completed when the first cross entropy loss is minimized. In one embodiment, the first cross entropy loss can be iterated multiple times by a gradient descent method until convergence to determine the minimized first cross entropy loss. In another embodiment, the first cross entropy loss function can be converted into a corresponding log-likelihood function, the log-likelihood function is differentiated to obtain its maximum likelihood estimate, and the corresponding minimized first cross entropy loss is determined based on the maximum likelihood estimate.
[0122] Optional, please combine Figure 11 Step 553: repeatedly obtain training samples and training reply texts corresponding to the training samples, and repeatedly calculate the first cross entropy loss, and complete pre-training when the first cross entropy loss is minimized, including:
[0123] Step 5531, obtaining a first threshold; and
[0124] Step 5532: Complete pre-training when the first cross entropy loss is less than a first threshold.
[0125] Optionally, the first threshold is a convergence value of the first cross entropy loss obtained by the gradient descent method. If the first cross entropy loss obtained by pre-training is less than the first threshold, it is considered that the first cross entropy loss is minimized and the pre-training can be completed.
[0126] Optional, please combine Figure 12 , the model training method of intelligent dialogue also includes:
[0127] Step 560: Input multiple rounds of real historical conversations into the conversation model to generate scoring reply text.
[0128] Step 570: train the evaluation classifier based on the real reply texts and the scored reply texts in the real historical conversations to obtain a trained evaluation classifier.
[0129] Optionally, the evaluation classifier uses an evaluation model of intelligent dialogue to evaluate the intelligent dialogue. As an example, the evaluation model can use the RoBERTa model. When using the evaluation model, multiple rounds of real historical dialogues U k And real historical dialogue U k Corresponding rating reply text r k Transformed into input "[CLS]U k [SEP]r k [SEP]” format, and the real historical dialogue U k And score reply text k Input the evaluation model for evaluation. [CLS] is used to mark the first position of the input sequence, and [SEP] is used to separate the two input dialogues.
[0130] Optionally, taking the coherence classifier as an example, in the real historical dialogue U k And score reply text k With "[CLS]U k [SEP]r k After the coherence classifier is fed into the format of [SEP]", the last hidden layer state corresponding to the position of [CLS] is fed into the fully connected layer with softmax for coherence scoring. The coherence score is used to evaluate the response text r k Participate in real historical dialogue k The coherence in .
[0131] Optional, please combine Figure 13 Step 570: Training the evaluation classifier based on the real reply text and the rated reply text in the real historical conversation to obtain a trained evaluation classifier, including:
[0132] Step 571: Input the real historical conversation and the real reply text in the real historical conversation into the evaluation classifier to obtain a first score.
[0133] Step 572: Input the real historical conversation and the scored reply text into the evaluation classifier to obtain a second score.
[0134] Step 573: Calculate a second cross entropy loss based on the first score and the second score.
[0135] Step 574 , repeatedly obtain the first score and the second score, and repeatedly calculate the corresponding second cross entropy loss, and complete the training of the assessment classifier when the second cross entropy loss is minimized.
[0136] Alternatively, for example, if the test classifier is a coherence classifier, the first score is used to evaluate the coherence of the actual reply text in the real historical conversation, and the second score is used to evaluate the coherence of the scored reply text in the real historical conversation. During training, the coherence classifier is optimized by calculating the cross-entropy between the first score and the second score. In the embodiment of the present application, pre-training of the coherence classifier is completed while minimizing the loss of the second cross-entropy, so that the scoring effect of the trained coherence classifier is optimized.
[0137] Optionally, in conjunction with step 553, the second cross entropy loss can be minimized using a similar optimization method as the first cross entropy loss, and the convergence value of the second cross entropy loss obtained by the gradient descent method can be used as the second threshold. If the second cross entropy loss obtained in pre-training is less than the second threshold, the second cross entropy loss is considered to be minimized, and pre-training of the assessment classifier can be completed.
[0138] To better illustrate the model training method for intelligent dialogue provided by the embodiment of this application, please refer to Figure 11 and Figure 13 The process of the intelligent dialogue model training method provided in the embodiment of the present application can be summarized into the following steps:
[0139] Step 510: Acquire multiple rounds of real historical conversations.
[0140] Step 522: Use the i-th round of real historical dialogue as the dialogue to be replaced.
[0141] Step 523: Use the real historical conversations from round 1 to round i-1 as sampling samples.
[0142] Step 531: Input the sample and the first n words of the conversation to be replaced into the conversation model to generate a predicted reply text. The first n words of the predicted reply text are the same as the first n words of the conversation to be replaced, n∈[0,m].
[0143] Step 540 : Use the predicted reply text to replace the conversation to be replaced in multiple rounds of real historical conversations to obtain training samples.
[0144] Step 551: Input the training sample into the dialogue model to generate training response text.
[0145] Step 552 : Calculate a first cross entropy loss based on the training samples and the training reply text.
[0146] Step 5531, obtain the first threshold.
[0147] Step 5532: Complete pre-training when the first cross entropy loss is less than a first threshold.
[0148] Step 560: Input multiple rounds of real historical conversations into the conversation model to generate scoring reply text.
[0149] Step 571: Input the real historical conversation and the real reply text in the real historical conversation into the evaluation classifier to obtain a first score.
[0150] Step 572: Input the real historical conversation and the scored reply text into the evaluation classifier to obtain a second score.
[0151] Step 573: Calculate a second cross entropy loss based on the first score and the second score.
[0152] Step 574 , repeatedly obtain the first score and the second score, and repeatedly calculate the corresponding second cross entropy loss, and complete the training of the assessment classifier when the second cross entropy loss is minimized.
[0153] Among them, steps 510, 522, 523, 531, 540, 551, 552, 5531, and 5532 belong to the method for training the dialogue model; steps 560, 571, 572, 573, and 574 belong to the method for training the measurement classifier. During the model training process for intelligent dialogue, the dialogue model training method and / or the measurement classifier training method can be selectively executed to respectively implement pre-training of the dialogue model and / or the measurement classifier. In one embodiment, step 560 can be initiated after step 5532 is completed, i.e., training of the measurement classifier can be initiated after dialogue model training is completed. In another embodiment, steps 510 and 560 can be initiated separately, i.e., training of the dialogue model and measurement classifier can be initiated separately. In other embodiments, the steps in the dialogue model training method and the measurement classifier training method can be executed in any combination, without limitation herein.
[0154] All of the above technical solutions can be combined in any way to form optional embodiments of the present application, and will not be described in detail here.
[0155] The embodiment of the present application obtains multiple rounds of real historical conversations; obtains the conversations to be replaced and sample samples from the multiple rounds of real historical conversations; inputs the sample samples into the conversation model to generate predicted reply text; uses the predicted reply text to replace the conversations to be replaced in the multiple rounds of real historical conversations to obtain training samples; and pre-trains the conversation model based on the training samples to obtain a trained conversation model. In this way, the conversation model simulates actual intelligent conversation scenarios during training, enabling the trained conversation model to not only generate reply text that is consistent with the real historical conversation based on the real historical conversation, but also generate reply text that is consistent with the historical conversation based on the historical conversation (e.g., the second historical conversation) containing the reply text generated by the conversation model. This can alleviate the problem of inconsistent application scenarios during chatbot training and actual use (inconsistent historical text types), ensuring that the reply text generated by the conversation model is consistent with the input historical text.
[0156] In an embodiment of the present application, multiple rounds of real historical conversations are input into a conversation model to generate scored reply texts; based on the real reply texts and scored reply texts in the real historical conversations, a test classifier is trained to obtain a trained test classifier. By training the test classifier, the test classifier can be adapted to actual intelligent conversation scenarios, so as to facilitate the evaluation of the reply texts generated by the trained conversation model. In the case where the test classifier is a coherence classifier, it can help intuitively judge the coherence between the reply text generated by the conversation model and the input historical text; in the case where the test classifier is other types of classifiers, it can also help intuitively determine other characteristics of the reply text generated by the conversation model, such as security, legality, etc.
[0157] In order to better implement the intelligent dialogue method of the embodiment of the present application, the embodiment of the present application also provides an intelligent dialogue device 600. Figure 14 , Figure 14 This is a schematic diagram of the structure of the intelligent dialogue device 600 provided in an embodiment of the present application. The intelligent dialogue device 600 may include:
[0158] The first acquisition unit 601 is used to acquire a first historical conversation to be replied to, and to acquire a second historical conversation to be replied to, where the second historical conversation at least includes a first reply text.
[0159] The first generation unit 602 is used to input the first historical conversation into the trained conversation model to generate a first reply text, and to input the second historical conversation into the trained conversation model to generate a second reply text. The conversation model is pre-trained using real historical conversations and predicted reply texts, and the predicted reply texts are generated by the conversation model.
[0160] The reply unit 603 is used to reply to the first historical conversation according to the first reply text, and to reply to the second historical conversation according to the second reply text.
[0161] Optional, please combine Figure 15 , the first obtaining unit 601 may also be used to:
[0162] Get the trained test classifier and the preset score threshold.
[0163] The intelligent dialogue device 600 may further include:
[0164] The scoring unit 604 is used to input the second historical conversation and the second reply text into the evaluation classifier to obtain an evaluation score for the second reply text.
[0165] The retraining unit 605 is used to obtain a retrained dialogue model when the evaluation score of the second reply text is less than the score threshold.
[0166] Optionally, the retraining unit 605 may obtain the retrained dialogue model from the intelligent dialogue model training device 700 .
[0167] Optionally, the embodiment of the present application further provides a model training device 700 for intelligent dialogue. Figure 16 As shown, Figure 16 Schematic diagram of the structure of the model training device 700 for intelligent dialogue provided in an embodiment of the present application. The model training device 700 for intelligent dialogue includes:
[0168] The second acquisition unit 701 is configured to acquire multiple rounds of real historical conversations and real reply texts corresponding to the multiple rounds of real historical conversations.
[0169] The sampling unit 702 is configured to obtain conversations to be replaced and sampling samples from multiple rounds of real historical conversations.
[0170] The second generating unit 703 is configured to input the sample into the dialogue model to generate a predicted reply text.
[0171] The replacement unit 704 is configured to replace the to-be-replaced conversation with the predicted reply text in multiple rounds of the real historical conversations to obtain training samples.
[0172] The first training unit 705 is used to pre-train the dialogue model according to the training samples and the real reply text to obtain a trained dialogue model.
[0173] Optionally, the sampling unit 702 can be used to sample the i-th round of real historical dialogue from k rounds of real historical dialogue according to a geometric distribution, i∈[1, k]; use the i-th round of real historical dialogue as the dialogue to be replaced; and use the 1st to i-1th rounds of real historical dialogue as sampling samples.
[0174] Optionally, the second generation unit 703 can be used to input the sample and the first n words of the conversation to be replaced into the conversation model to generate a predicted reply text, where the first n words of the predicted reply text are the same as the first n words of the conversation to be replaced, n∈[0,m].
[0175] Optionally, the first training unit 705 can be used to input training samples into the dialogue model to generate training reply text; calculate the first cross entropy loss based on the training samples and the training reply text; repeatedly obtain the training samples and the training reply text corresponding to the training samples, and repeatedly calculate the first cross entropy loss, completing the pre-training when the first cross entropy loss is minimized.
[0176] Optionally, the first training unit 705 may also be configured to obtain a first threshold value; and complete pre-training when the first cross entropy loss is less than the first threshold value.
[0177] Optional, please combine Figure 17 The model training device 700 for intelligent dialogue further includes: a third generation unit 706, which is used to input multiple rounds of real historical dialogues into the dialogue model to generate scoring reply texts.
[0178] Optional, please combine Figure 17 The model training device 700 for intelligent dialogue also includes: a second training unit 707, which is used to train the evaluation classifier based on the real reply text and the scored reply text in the real historical dialogue to obtain the trained evaluation classifier.
[0179] Optional, please combine Figure 17 The second training unit 707 is further used to input the real historical conversation and the real reply text in the real historical conversation into the test classifier to obtain a first score; input the real historical conversation and the scored reply text into the test classifier to obtain a second score; calculate the second cross-entropy loss according to the first score and the second score; repeatedly obtain the first score and the second score, and repeatedly calculate the corresponding second cross-entropy loss, and complete the training of the test classifier when the second cross-entropy loss is minimized.
[0180] It should be noted that the functions of each module in the intelligent dialogue device 600 and the intelligent dialogue model training device 700 in the embodiment of the present application can correspond to the specific implementation methods of any embodiment in the above-mentioned method embodiments, and will not be repeated here.
[0181] Each unit in the above-mentioned apparatus may be implemented in whole or in part by software, hardware, or a combination thereof. Each unit may be embedded in or independent of a processor in a computer device in the form of hardware, or may be stored in a memory in the computer device in the form of software, so that the processor can call and execute the corresponding operations of each unit.
[0182] For example, the intelligent dialogue device 600 and the intelligent dialogue model training device 700 can be integrated into a terminal or server that has a storage device and a processor and has computing capabilities, or the intelligent dialogue device 600 and the intelligent dialogue model training device 700 are the terminal or server.
[0183] Optionally, the present application also provides a computer device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.
[0184] Figure 18 A schematic structural diagram of a computer device provided in an embodiment of the present application, such as Figure 8 As shown, computer device 800 may include: a communication interface 801, a memory 802, a processor 803, and a communication bus 804. Communication interface 801, memory 802, and processor 803 communicate with each other via communication bus 804. Communication interface 801 is used for data communication between device 800 and external devices. Memory 802 may be used to store software programs and modules. Processor 803 executes software programs and modules stored in memory 802, such as the software programs for corresponding operations in the aforementioned method embodiments.
[0185] Optionally, the processor 803 can call the software program and module stored in the memory 802 to perform the following operations: obtain a first historical conversation to be replied; input the first historical conversation into the trained conversation model to generate a first reply text, the conversation model is pre-trained using real historical conversations and predicted reply texts, and the predicted reply text is generated by the conversation model; reply to the first historical conversation according to the first reply text; obtain a second historical conversation to be replied, the second historical conversation includes at least the first reply text; input the second historical conversation into the trained conversation model to generate a second reply text; and reply to the second historical conversation according to the second reply text.
[0186] Optionally, the processor 803 can call the software program and module stored in the memory 802 to perform the following operations: obtain multiple rounds of real historical conversations; obtain conversations to be replaced and sampling samples from multiple rounds of real historical conversations; input the sampling samples into the conversation model to generate predicted reply text; use the predicted reply text to replace the conversations to be replaced in multiple rounds of real historical conversations to obtain training samples; and pre-train the conversation model based on the training samples to obtain a trained conversation model.
[0187] Optionally, the computer device 800 may be integrated into a terminal or server that has a storage device and a processor and has computing capabilities, or the computer device 800 may be the terminal or server.
[0188] This application also provides a computer-readable storage medium for storing a computer program. This computer-readable storage medium can be applied to a computer device, and the computer program causes the computer device to execute the corresponding processes in the above-mentioned methods in the embodiments of this application. For the sake of brevity, it is not further described here.
[0189] This application also provides a computer program product, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the corresponding processes of the above-described methods in the embodiments of this application. For the sake of brevity, these processes are not further described here.
[0190] This application also provides a computer program comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the corresponding processes of the above-described methods in the embodiments of this application. For the sake of brevity, these processes are not further described here.
[0191] It should be understood that the processor of the embodiments of the present application may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method embodiment can be completed by hardware integrated logic circuits in the processor or software instructions. The above processor can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The various methods, steps, and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of the present application can be directly implemented as a hardware decoding processor, or can be implemented by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium mature in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.
[0192] It is understood that the memory in the embodiments of the present application may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct RAM bus random access memory (DR RAM). It should be noted that the memory of the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0193] It should be understood that the above-mentioned memories are exemplary but not restrictive. For example, the memories in the embodiments of the present application may also be static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct RAM RAM (DR RAM), etc. In other words, the memories in the embodiments of the present application are intended to include, but are not limited to, these and any other suitable types of memories.
[0194] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0195] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0196] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0197] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0198] In addition, each functional unit in the embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0199] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a ROM, a RAM, a magnetic disk, or an optical disk.
[0200] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present application should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.
Claims
1. An intelligent dialogue method, characterized in that: include: Get the first historical conversation to be replied; Inputting the first historical conversation into a trained conversation model to generate a first reply text, wherein the conversation model is pre-trained using real historical conversations and predicted reply texts, and the predicted reply text is generated by the conversation model; Replying to the first historical conversation according to the first reply text; Obtaining a second historical conversation to be replied to, where the second historical conversation at least includes the first reply text; Inputting the second historical dialogue into the trained dialogue model to generate a second reply text; and Replying to the second historical conversation according to the second reply text; Get the trained test classifier; and The second historical conversation and the second reply text are input into the evaluation classifier to obtain an evaluation score for the second reply text.
2. The intelligent dialogue method according to claim 1, characterized in that: The evaluation classifier includes any one of a consistency classifier, a security classifier, and a legality classifier.
3. The intelligent dialogue method according to claim 1, characterized in that: The intelligent dialogue method further includes: Get the preset score threshold; When the evaluation score of the second reply text is less than the score threshold, the trained dialogue model is retrained.
4. A model training method for intelligent dialogue, characterized in that: include: Get multiple rounds of real historical conversations; Obtaining conversations to be replaced and sampling samples from multiple rounds of real historical conversations; Inputting the sampled text into the dialogue model to generate a predicted reply text; Using the predicted reply text to replace the to-be-replaced conversation in multiple rounds of the real historical conversation to obtain training samples; and Pre-training the dialogue model according to the training samples to obtain a trained dialogue model; Inputting multiple rounds of the real historical conversations into the conversation model to generate scoring reply texts; The evaluation classifier is trained based on the real historical conversation and the scoring reply text to obtain a trained evaluation classifier.
5. The model training method for intelligent dialogue according to claim 4, characterized in that: The real historical conversation includes k rounds, k>1, and obtaining the conversation to be replaced and the sampling sample from the multiple rounds of the real historical conversation includes: Sample the real historical dialogue in round i from the real historical dialogue in round k according to geometric distribution, i∈[1,k-1]; Using the real historical dialogue in round i as the dialogue to be replaced; and The real historical conversations from round 1 to round i-1 are used as the sampling samples.
6. The model training method for intelligent dialogue according to claim 5, characterized in that: The dialogue to be replaced includes m words, and the step of inputting the sampled words into the dialogue model to generate a predicted reply text includes: The sampling sample and the first n words of the dialogue to be replaced are input into the dialogue model to generate the predicted reply text, where the first n words of the predicted reply text are the same as the first n words of the dialogue to be replaced, n∈[0,m].
7. The model training method for intelligent dialogue according to claim 4, characterized in that: The pre-training of the dialogue model according to the training sample includes: Inputting the training sample into the dialogue model to generate training response text; Calculating a first cross entropy loss based on the training sample and the training reply text; and Repeatedly obtain the training samples and the training reply texts corresponding to the training samples, and repeatedly calculate the first cross entropy loss, and complete the pre-training when the first cross entropy loss is minimized.
8. The model training method for intelligent dialogue according to claim 7, characterized in that: Repeatedly obtaining the training samples and the training reply texts corresponding to the training samples, and repeatedly calculating the first cross entropy loss, and completing the pre-training when the first cross entropy loss is minimized, including: Obtaining a first threshold; The pre-training is completed when the first cross entropy loss is less than the first threshold.
9. The model training method for intelligent dialogue according to claim 4, characterized in that: The evaluation classifier is trained based on multiple rounds of the real historical conversations and the scored response texts, including: Inputting the real historical conversation and the real reply text in the real historical conversation into the evaluation classifier to obtain a first score; Inputting the real historical conversation and the scoring reply text into the evaluation classifier to obtain a second score; Calculating a second cross entropy loss based on the first score and the second score; and Repeatedly obtain the first score and the second score, and repeatedly calculate the corresponding second cross entropy loss, and complete the training of the evaluation classifier when the second cross entropy loss is minimized.
10. An intelligent dialogue device, characterized in that: The device comprises: A first acquiring unit, configured to acquire a first historical conversation to be replied to, and to acquire a second historical conversation to be replied to, wherein the second historical conversation at least includes the first reply text; a first generating unit, configured to input the first historical conversation into a trained conversation model to generate a first reply text, and to input the second historical conversation into the trained conversation model to generate a second reply text, wherein the conversation model is pre-trained using real historical conversations and predicted reply texts, and the predicted reply texts are generated by the conversation model; and a reply unit, configured to reply to the first historical conversation according to the first reply text, and to reply to the second historical conversation according to the second reply text; The first acquisition unit is further configured to acquire a trained evaluation classifier; and The scoring unit is used to input the second historical conversation and the second reply text into the evaluation classifier to obtain an evaluation score for the second reply text.
11. A model training device for intelligent dialogue, characterized in that: The device comprises: The second acquisition unit is used to acquire multiple rounds of real historical conversations; A sampling unit, configured to obtain the conversation to be replaced and sampling samples from multiple rounds of real historical conversations; A second generating unit, configured to input the sampled text into a dialogue model to generate a predicted reply text; a replacement unit, configured to replace the to-be-replaced conversation with the predicted reply text in multiple rounds of the real historical conversation to obtain training samples; and a first training unit, configured to pre-train the dialogue model according to the training sample to obtain a trained dialogue model; A third generating unit, configured to input multiple rounds of the real historical conversations into the conversation model to generate a scoring reply text; The second training unit is used to train the evaluation classifier based on the real historical conversation and the scoring reply text to obtain a trained evaluation classifier.
12. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which is suitable for loading by a processor to execute the steps in the intelligent dialogue method as described in any one of claims 1 to 3, or to execute the steps in the model training method for intelligent dialogue as described in any one of claims 4 to 9.
13. A computer device, characterized in that: The computer device includes a processor and a memory, wherein a computer program is stored in the memory. The processor is used to execute the steps in the intelligent dialogue method described in any one of claims 1 to 3, or execute the steps in the model training method for intelligent dialogue described in any one of claims 4 to 9 by calling the computer program stored in the memory.
14. A computer program product comprising computer instructions, characterized in that When the computer instructions are executed by the processor, the steps in the intelligent dialogue method as described in any one of claims 1 to 3, or the steps in the model training method for intelligent dialogue as described in any one of claims 4 to 9 are implemented.
Citation Information
Patent Citations
Question and answer model training method and device, question and answer method and device, equipment and storage medium
CN113033664A