Method, device and storage medium for generating reply text
By obtaining the first latent variable and state structure of the historical dialogue text and combining it with the second latent variable to generate the response text, the problem of insufficient accuracy of response text in the existing technology is solved, and more efficient and interpretable response text generation is achieved.
Patent Information
- Application Number
- CN202210179625.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-25
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2042-02-25
AI Technical Summary
In existing technologies, the accuracy of determining the corresponding response text based on keywords is insufficient.
By acquiring historical dialogue text, the first latent variable and state structure are determined. Response text is generated based on the first and second latent variables. Considering the personalized information and state transition information of the dialogue, explicit variables are introduced to improve the interpretability and accuracy of the generation process.
It improves the accuracy and efficiency of response text generation, reduces parameter requirements during sentence processing, and enhances the interpretability of the generated response text.
Smart Images

Figure CN114595317B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, and particularly relates to a reply text generation method and device, equipment and a storage medium. BACKGROUND
[0002] Task-oriented dialogue refers to an automatic communication dialogue between artificial intelligence and a user.
[0003] In related technologies, in the application process of the task-oriented dialogue, an automatic answering system determines fixed reply texts in advance, and then determines keywords in dialogue texts input by a user according to pre-set keyword extraction rules, determines a next sentence reply text corresponding to the keywords in the dialogue texts based on the keywords in the dialogue texts, and displays the next sentence reply text to the user, so as to realize automatic dialogue.
[0004] However, in the above related technologies, only the keywords cannot accurately determine the reply texts corresponding to the dialogue texts. SUMMARY
[0005] Embodiments of the present application provide a reply text generation method, device, equipment and storage medium, which can improve the reply accuracy of the reply texts. The technical solution is as follows.
[0006] According to an aspect of an embodiment of the present application, a reply text generation method is provided, and the method comprises the following steps:
[0007] Obtaining historical dialogue texts, the historical dialogue texts comprising at least one sentence;
[0008] Determining a first hidden variable and a state structure of the historical dialogue texts based on the sentences contained in the historical dialogue texts; wherein the first hidden variable is used to indicate text personality information of the historical dialogue texts and object personality information of a participant object of the historical dialogue texts; the state structure comprises state information of each of the sentences, and the state information is used to indicate a dialogue intention of the sentence;
[0009] Determining predicted state information of a reply text corresponding to the historical dialogue texts according to the state structure;
[0010] Determining a second hidden variable according to the predicted state information, the second hidden variable being used to indicate predicted sentence personality information of the reply text;
[0011] Generating the reply text based on the first hidden variable and the second hidden variable.
[0012] According to an aspect of some embodiments of the present application, a method for training a reply text generation model is provided, the method comprising the steps of:
[0013] obtaining sample dialogue text, the sample dialogue text comprising at least one sample sentence;
[0014] encoding each of the sample sentences to obtain a first encoded representation and a second encoded representation of each of the sample sentences;
[0015] determining a first latent variable based on the first encoded representation of each of the sample sentences, the first latent variable being used to indicate text personality information of the sample dialogue text and object personality information of a participating object of the sample dialogue text;
[0016] determining state information of each of the sample sentences based on the second encoded representation of each of the sample sentences, wherein the state information is used to indicate a dialogue intent of the sample sentence;
[0017] determining a second latent variable of each of the sample sentences based on the first encoded representation of each of the sample sentences and the state information of each of the sample sentences, wherein the second latent variable is used to indicate sentence feature information of the sample sentence;
[0018] training the reply text generation model according to the first latent variable, the state information of each of the sample sentences, and the second latent variable of each of the sample sentences.
[0019] According to an aspect of some embodiments of the present application, a device for generating a reply text is provided, the device comprising the following modules:
[0020] a text obtaining module configured to obtain historical dialogue text, the historical dialogue text comprising at least one sentence;
[0021] a structure determining module configured to determine a first latent variable and a state structure of the historical dialogue text based on the sentence included in the historical dialogue text, wherein the first latent variable is used to indicate text personality information of the historical dialogue text and object personality information of a participating object of the historical dialogue text, and the state structure comprises state information of each of the sentences, the state information being used to indicate a dialogue intent of the sentence;
[0022] a state predicting module configured to determine predicted state information of a reply text corresponding to the historical dialogue text according to the state structure;
[0023] a variable determining module configured to determine a second latent variable according to the predicted state information, the second latent variable being used to indicate predicted sentence personality information of the reply text;
[0024] a reply generation module configured to generate the reply text based on the first latent variable and the second latent variable.
[0025] According to an aspect of some embodiments of the present application, there is provided a device for training a reply text generation model, the device comprising the following modules:
[0026] a sample obtaining module configured to obtain a sample dialogue text, the sample dialogue text comprising at least one sample sentence;
[0027] a sample encoding module configured to encode each of the sample sentences to obtain a first encoded representation and a second encoded representation of each of the sample sentences;
[0028] a first determining module configured to determine a first latent variable based on the first encoded representation of each of the sample sentences, the first latent variable being used to indicate text personality information of the sample dialogue text and object personality information of a participant of the sample dialogue text;
[0029] an information determining module configured to determine state information of each of the sample sentences based on the second encoded representation of each of the sample sentences, the state information being used to indicate a dialogue intention of the sample sentence;
[0030] a second determining module configured to determine a second latent variable of each of the sample sentences based on the first encoded representation of each of the sample sentences and the state information of each of the sample sentences, the second latent variable being used to indicate sentence feature information of the sample sentence;
[0031] a model training module configured to train the reply text generation model according to the first latent variable, the state information of each of the sample sentences and the second latent variable of each of the sample sentences.
[0032] According to an aspect of some embodiments of the present application, there is provided a computer device, comprising a processor and a memory, the memory storing at least one instruction, at least one program, a code set or an instruction set, the at least one instruction, the at least one program, the code set or the instruction set being loaded and executed by the processor to implement the above-mentioned method for generating a reply text, or to implement the above-mentioned method for training a reply text generation model.
[0033] According to an aspect of some embodiments of the present application, a computer readable storage medium is provided, and the computer readable storage medium stores at least one instruction, at least one program, a code set or an instruction set. The at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by a processor to implement the reply text generation method or the training method of the reply text generation model.
[0034] According to an aspect of some embodiments of the present application, a computer program product or a computer program is provided, and the computer program product or the computer program 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 the processor executes the computer instructions to enable the computer device to implement the reply text generation method or the training method of the reply text generation model.
[0035] The technical solutions provided by the embodiments of the present application can bring the following beneficial effects:
[0036] The first hidden variable is used to indicate the text personality information of the historical dialogue text and the object personality information of the participating object of the historical dialogue text, and the second hidden variable is used to indicate the predicted sentence personality information of the reply text. When generating the reply text, the personalized information of the overall dialogue, the personalized information of the participating object, and the personalized information of the individual sentence are considered, so as to improve the reply accuracy of the reply text. Moreover, the predicted state information of the reply text is predicted based on the state structure of the historical dialogue text. On the one hand, the state structure includes the state information of each sentence, and the state transition information of the historical dialogue text can be considered based on the state structure, so as to improve the accuracy of state prediction. On the other hand, the state information is an explicit variable relative to the first hidden variable and the second hidden variable, and is used to indicate the dialogue intention of the sentence. The explicit variable is introduced in the reply text generation process, so as to improve the interpretability of the reply text generation process, reduce the required parameters in the sentence processing, and improve the generation efficiency of the reply text. BRIEF DESCRIPTION OF DRAWINGS
[0037] Figure 1 FIG. 1 is a schematic diagram of a reply text generation system according to an embodiment of the present application;
[0038] Figure 2 FIG. 1 is a schematic diagram of a reply text generation system according to an embodiment of the present application;
[0039] Figure 3 FIG. 1 is a schematic diagram of a reply text generation system according to an embodiment of the present application;
[0040] Figure 4is a flowchart of a reply text generation method provided by an embodiment of the present application;
[0041] Figure 5 An exemplary schematic diagram of a reply text generation method is shown;
[0042] Figure 6 is a flowchart of a reply text generation model training method provided by an embodiment of the present application;
[0043] Figure 7 An exemplary schematic diagram of a state and hidden variable acquisition method in a model training process is shown;
[0044] Figure 8 is a block diagram of a reply text generation apparatus provided by an embodiment of the present application;
[0045] Figure 9 is a block diagram of a reply text generation apparatus provided by another embodiment of the present application;
[0046] Figure 10 is a block diagram of a reply text generation model training apparatus provided by an embodiment of the present application;
[0047] Figure 11 is a block diagram of a reply text generation model training apparatus provided by another embodiment of the present application;
[0048] Figure 12 is a structural block diagram of a computer device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solutions and advantages of the present application clearer, the embodiments of the present application will be further described in detail below with reference to the drawings.
[0050] The reply text generation method and the reply text generation model training method in the present application involve the following technologies:
[0051] Artificial intelligence (AI) is the theory, method, technology and application system of using digital computers or digital computer controlled machines to simulate, extend and expand human intelligence, perceive environment, acquire knowledge and use knowledge to obtain optimal results. In other words, artificial intelligence is a comprehensive technology of computer science, which attempts to understand the essence of intelligence and produce a new intelligent machine that can react in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines, so that machines have the functions of perception, reasoning and decision-making.
[0052] Artificial intelligence technology is a comprehensive discipline, involving a wide range of fields, both hardware and software level technology. Artificial intelligence basic technology generally includes, such as sensors, special artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction system, mechatronics and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology and machine learning / deep learning and other major directions.
[0053] Machine learning (ML) is a multi-disciplinary subject, involving probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It is a specialized study of how computers simulate or implement human learning behavior to acquire new knowledge or skills, reorganize existing knowledge structure to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental approach to making computers intelligent, and its applications are widespread in various fields of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and teaching learning.
[0054] With the research and progress of artificial intelligence technology, artificial intelligence technology has been researched and applied in many fields, such as common smart home, smart wearable devices, virtual assistants, smart speakers, smart marketing, unmanned vehicles, autonomous vehicles, drones, robots, smart medical care, smart customer service, etc. It is believed that with the development of technology, artificial intelligence technology will be applied in more fields and play an increasingly important role.
[0055] The scheme provided by the embodiments of the present application relates to machine learning and other technologies of artificial intelligence. In the following, the technical scheme of the present application will be introduced and described in combination with several embodiments.
[0056] Please refer to Figure 1 which shows a schematic diagram of an automatic reply system provided by an embodiment of the present application. The automatic reply system can include a terminal 10 and a server 20.
[0057] The terminal 10 can be an electronic device such as a mobile phone, a tablet computer, a game console, an e-book reader, a multimedia playback device, a wearable device, a PC (Personal Computer), a smart voice interaction device, a smart home appliance, a vehicle-mounted terminal, and an aircraft, etc. The embodiments of the present application do not limit this. Optionally, the terminal 10 includes a client of an application program. The application program can be any application program with an automatic reply function, such as a social application program, a shopping application program, a reading application program, etc. Optionally, the above-mentioned application program can be an application program that needs to be downloaded and installed, or an application program that can be used immediately, and the embodiments of the present application do not limit this.
[0058] The server 20 is configured to provide background services for the terminal 10. The server 20 can be a single server, a server cluster composed of multiple servers, or a cloud computing service center. Alternatively, the server 20 can be a background server of the client of the application program described above. In the exemplary embodiment, the server 20 provides background services for multiple terminals 10.
[0059] The terminal 10 and the server 20 described above transmit data through a network.
[0060] Alternatively, in the embodiment of the present application, the server 20 includes a reply text generation model, and the server 20 generates a reply text based on historical dialogue text. As shown in Figure 2 For example, the terminal 10 obtains and displays at least one sentence input by the first object, generates historical dialogue text based on the at least one sentence, and sends the historical dialogue text to the server 20. Correspondingly, after obtaining the historical dialogue text, the server 20 encodes the sentences in the historical dialogue text using a K-layer encoding network through the encoding network of the reply text generation model, to obtain a first encoding representation of each sentence, and encodes the sentences in the historical dialogue text using an L-layer encoding network, to obtain a second encoding representation of each sentence. Then, the server 20 determines a first latent variable based on the second encoding representation of each sentence through the feature extraction network of the reply text generation model, determines a state structure of the historical dialogue text based on the second encoding representation of each sentence, wherein the state structure includes state information of each sentence, and determines predicted state information of the reply text according to the state information of each sentence; further, the server 20 determines a second latent variable of the reply text based on the first encoding representation of each sentence, the state information of each sentence, and the predicted state information. Then, the server 20 generates a reply text based on the first latent variable and the second latent variable through the generator of the reply text generation model, and sends the reply text to the terminal 10, so that the terminal 10 displays the reply text.
[0061] Alternatively, as shown in Figure 1 The automatic reply system further includes a model training device configured to train the reply text generation model. For example, as shown in Figure 3As shown, after obtaining the sample dialogue text, the model training device encodes the sample sentences in the sample dialogue text by using a K-layer encoding network of the reply text generation model to obtain a first encoding representation of each sample sentence, and encodes the sample sentences in the sample dialogue text by using an L-layer encoding network to obtain a second encoding representation of each sample sentence. Then, the model training device determines the state information of each sample sentence based on the first encoding representation of each sample sentence by using a feature extraction network of the reply text generation model, determines the first hidden variable based on the second encoding representation of each sample sentence, and determines the second hidden variable of each sample sentence based on the state information of each sample sentence and the second encoding representation of each sample sentence. Then, the model training device trains the reply text generation model based on the first hidden variable, the second hidden variable of each sample sentence, and the state information of each sample sentence.
[0062] It should be noted that the above Figure 2 and Figure 3 are only exemplary and explanatory. In exemplary embodiments, the functions of the terminal 10, the server 20, and the model training device can be flexibly set and adjusted, and the embodiments of the present application do not limit this. Alternatively, the server 20 and the model training device are the same device.
[0063] For reference Figure 4 , which shows a flowchart of a reply text generation method provided by an embodiment of the present application. The method can be applied to Figure 1 the server 20 of the automatic reply system as shown, and the execution subject of each step can be the server 20 (hereinafter referred to as "computer device"). The method can include at least one of the following steps (401-405):
[0064] Step 401, obtaining historical dialogue text.
[0065] The historical dialogue text refers to the text generated by at least one user in the dialogue process. In the embodiments of the present application, the computer device obtains the historical dialogue text during the automatic reply process, and then determines the corresponding reply text based on the historical dialogue text. The historical dialogue text includes at least one sentence.
[0066] Optionally, the historical dialogue text includes all or part of the sentences generated in the dialogue process.
[0067] In a possible implementation, the historical dialogue text includes all sentences generated in a dialogue process. Optionally, to improve the accuracy of the reply text, for a dialogue process, the computer device obtains all sentences generated in the dialogue process, and determines the all sentences as the historical dialogue text, and then generates the corresponding reply text based on the historical dialogue text.
[0068] In another possible implementation, the historical dialogue text includes part of the sentences generated in the dialogue process. Optionally, to improve the generation efficiency of the reply text, for a dialogue process, the computer device obtains all sentences generated in the dialogue process, and further extracts part of the sentences from the all sentences to determine the historical dialogue text based on the generator of the sentences, and then generates the corresponding reply text based on the historical dialogue text. For example, if the dialogue process includes a participant who asks questions and an automatic answering robot who replies to the questions, after obtaining the all sentences, the computer device obtains the sentences generated when the participant asks questions from the all sentences, and then determines the historical dialogue text according to the sentences generated by the participant. In an example embodiment, for the case where there are multiple participants, the computer device can generate different historical dialogue texts according to different participants, or can generate a common historical dialogue text without distinguishing the participants, which is not limited in the embodiment of the present application.
[0069] Optionally, the computer device can obtain the historical dialogue text in real time, or obtain the historical dialogue text at a certain time interval.
[0070] In a possible implementation, the computer device obtains the historical dialogue text in real time. Optionally, in a dialogue process, the computer device detects the dialogue process in real time to obtain the sentences in the dialogue and generate the historical dialogue text. In this case, the computer device can process the historical dialogue text in real time to generate the reply text, which is suitable for real-time dialogue scenarios.
[0071] In another possible implementation, the computer device obtains the historical dialogue text at a certain time interval. Optionally, the computer device processes one or more dialogue processes at a certain time interval, and correspondingly generates one or more historical dialogue texts and generates the reply text corresponding to each historical dialogue text. In this case, the computer device can flexibly adjust the time interval according to its own load, which is suitable for non-real-time dialogue scenarios. Optionally, the time interval can be 1 hour, 1 day, 1 week, etc., which is not limited in the embodiment of the present application.
[0072] Optionally, the computer device obtains the historical dialogue text based on continuous dialogues; or the computer device obtains the historical dialogue text based on a target time period.
[0073] In a possible implementation, the computer device obtains the historical dialogue text based on continuous dialogues. Optionally, for adjacent sentences in a dialogue process, if a time interval between the adjacent sentences is less than a target value, the adjacent sentences are determined as continuous dialogues and belong to the same historical dialogue text. The time interval can be 1 minute, 5 minutes or 10 minutes, which is not limited in the embodiments of the present application.
[0074] In another possible implementation, the computer device obtains the historical dialogue text based on a target time period. Optionally, when obtaining the historical dialogue text, the computer device determines a target time period by pushing a fixed time length forward from a generation time of a last sentence, and determines that sentences generated in the target time period belong to the same historical dialogue text. In this case, the historical dialogue text is generated based on the target time period, so that the historical dialogue text includes more rich sentence content, and an accurate reply text can be determined based on the historical dialogue text. The fixed time length can be 1 day, 2 days or 3 days, which is not limited in the embodiments of the present application.
[0075] It should be noted that the above problem refers to a sentence or text corresponding to a reply, and not only to a sentence or text asking a question.
[0076] In step 402, a first hidden variable and a state structure of the historical dialogue text are determined based on sentences included in the historical dialogue text.
[0077] In the embodiments of the present application, after obtaining the historical dialogue text, the computer device determines a first hidden variable and a state structure of the historical dialogue text based on sentences included in the historical dialogue text. The first hidden variable is used to indicate text personality information (such as a dialogue theme) of the historical dialogue text and object personality information (such as speaking habits of a participant) of a participant of the historical dialogue text. The state structure includes state information of each sentence, and the state information is used to indicate a dialogue intention (such as asking a question or expressing agreement) of the sentence. Optionally, in the embodiments of the present application, the text personality information is used to represent a feature of the historical dialogue text as a whole, and the object personality information is used to represent a personality habit of the participant in the dialogue.
[0078] It should be noted that, in the embodiments of the present application, for the historical dialogue text, the first hidden variable is information that does not change over time, that is, the first hidden variables of different sentences in the same historical dialogue text are the same.
[0079] The first hidden variable and the obtaining manner of the state structure are described below and will not be repeated here.
[0080] In step 403, the predicted state information of the reply text corresponding to the historical dialogue text is determined according to the state structure.
[0081] In the embodiment of the present application, after obtaining the state structure, the computer device determines the predicted state information of the reply text corresponding to the historical dialogue text according to the state structure. For example, assuming that the state structure c <n = [c1, c2, ……c n-1 ], the predicted state information c n corresponding to the predicted manner is as follows:
[0082]
[0083] Wherein, W c and b c are trainable parameters, h c n-1 is defined as the representation of the state information c n-1 , and n-1 is used to indicate the number of sentences in the historical dialogue text.
[0084] In step 404, the second hidden variable is determined according to the predicted state information.
[0085] In the embodiment of the present application, after obtaining the predicted state information, the computer device determines the second hidden vector according to the predicted state information. The second hidden variable is used to indicate the predicted sentence individual information (such as dialogue logic, dialogue behavior, etc.) of the reply text.
[0086] The obtaining manner of the second hidden variable is described below and will not be repeated here.
[0087] In step 405, the reply text is generated based on the first hidden variable and the second hidden variable.
[0088] In the embodiment of the present application, after obtaining the first hidden variable and the second hidden variable, the computer device generates the reply text. Optionally, the reply text includes a sentence.
[0089] For example, as shown in Figure 5 , taking the historical dialogue text including three sentences u1, u2 and u3 as an example, the computer device obtains u1, u2 and u3, determines the first hidden variable z s and the state information c1 of u1, the state information c2 of u2, and the state information c3 of u3 according to the u1, u2 and u3, further determines the predicted state information c4 of the reply text u4 based on c1, c2 and c3, and determines the target hidden variable z I1. determining a target latent variable z of u2 based on c2 I 2. determining a target latent variable z of u3 based on c3 I 3. determining a target latent variable z of u4 based on c4 and z I 1. z I 2. and z I 3. determining a second latent variable z I 4. determining a reply text u4 based on the first latent variable and the second latent variable
[0090] In the technical scheme provided in the embodiments of the present application, the first latent variable and the second latent variable are used to determine the reply text of the historical dialogue text, the first latent variable is used to indicate the text personality information of the historical dialogue text and the object personality information of the participating object of the historical dialogue text, and the second latent variable is used to indicate the predicted sentence personality information of the reply text. When the reply text is generated, the personalized information of the overall dialogue, the personalized information of the participating object, and the personalized information of the individual sentence are considered, so that the reply accuracy of the reply text is improved. Moreover, the predicted state information of the reply text is predicted based on the state structure of the historical dialogue text. On the one hand, the state structure includes the state information of each sentence, and the state transition information of the historical dialogue text can be considered based on the state structure, so that the accuracy of state prediction is improved. On the other hand, the state information is an explicit variable relative to the first latent variable and the second latent variable, and is used to indicate the dialogue intention of the sentence. The explicit variable is introduced in the reply text generation process, so that the explainability in the reply text generation process is improved, the parameters required in the sentence processing are reduced, and the generation efficiency of the reply text is improved.
[0091] Next, the acquisition method of the first latent variable and the state structure is introduced.
[0092] In the example embodiments, the step 402 includes at least one of the following steps:
[0093] 1. The two encoding methods are used to encode each sentence in the historical dialogue text respectively, to obtain the first encoding representation and the second encoding representation of each sentence.
[0094] In the embodiments of the present application, after the computer device acquires the historical dialogue text, the two different encoding methods are used to encode each sentence in the historical dialogue text respectively, to obtain the first encoding representation and the second encoding representation of each sentence.
[0095] Optionally, for each sentence, the computer device encodes the sentence by using a K-layer encoding network to obtain a first encoding representation of the sentence; and encodes the sentence by using an L-layer encoding network to obtain a second encoding representation of the sentence. K is less than L, and K and L are both positive integers. Optionally, in the embodiment of the present application, the K-layer encoding network is in the L-layer encoding network, and the K-layer encoding network is the first K-layer encoding network in the L-layer encoding network.
[0096] Optionally, in the embodiment of the present application, when the computer device obtains the first encoding representation, for a target word in a target sentence of the historical dialogue text, the computer device obtains a preceding word corresponding to the target word from the target sentence, and then encodes the target word and the preceding word by using the K-layer encoding network to obtain a first encoding representation corresponding to the target word, and splices the first encoding representations corresponding to the respective words in the target sentence to obtain the first encoding representation of the target sentence. The preceding word refers to a word before the target word in the target sentence.
[0097] Optionally, in the embodiment of the present application, when the computer device obtains the second encoding representation, for a target word in a target sentence of the historical dialogue text, the computer device obtains a preceding word corresponding to the target word from the target sentence, and then encodes the target word and the preceding word by using the L-layer encoding network to obtain a second encoding representation corresponding to the target word, and splices the second encoding representations corresponding to the respective words in the target sentence to obtain the second encoding representation of the target sentence.
[0098] 2. Determine a first latent variable based on the first encoding representation of each sentence.
[0099] In the embodiment of the present application, after the computer device obtains the first encoding representation of each sentence, the computer device determines the first latent variable based on the first encoding representation of each sentence.
[0100] Optionally, in the embodiment of the present application, when the computer device obtains the first latent variable, the computer device determines a sampling range of the first latent variable based on the first encoding representation of each sentence, and then samples from the sampling range to determine the first latent variable. Optionally, the probability distribution of the sampling range conforms to a Gaussian distribution, and the computer device determines the first latent variable by Gaussian sampling.
[0101] 3. Determine state information of each sentence based on the second encoding representation of each sentence.
[0102] In the embodiment of the present application, after the computer device obtains the second encoding representation, the computer device determines the state information of each sentence based on the second encoding representation of each sentence.
[0103] 4. Generate a state structure of the historical dialogue text according to the state information of each sentence.
[0104] In the embodiment of the present application, after obtaining the state information of each sentence, the computer device generates a state structure of the historical dialogue text according to the state information of each sentence.
[0105] It should be noted that, in the embodiment of the present application, the state structure includes the state information of each sentence, that is, the state structure can represent the state transition of each sentence in the historical dialogue text.
[0106] To sum up, in the technical scheme provided in the embodiment of the present application, the first hidden variable is determined by the first encoding vector, the state information is determined by the second encoding vector, the difference between the first hidden variable and the state information is considered, different encoding methods are used to determine the first encoding representation and the second encoding representation, and the accuracy of the encoding representation is improved. Moreover, the first hidden vector is a hidden vector, and a lower-layer encoding network can be used to encode the sentence, the state information is an explicit vector, and a higher-layer encoding network needs to be used to encode the sentence, the encoding layers are flexibly configured, the encoding efficiency is improved, the device load is reduced, and the acquisition efficiency of the first hidden vector is improved.
[0107] Next, the acquisition method of the second hidden variable is introduced.
[0108] In the exemplary embodiment, the step 404 includes at least one of the following steps:
[0109] 1. Obtain the first encoding representation of the last sentence in the historical dialogue text;
[0110] 2. Determine the target hidden variable of the reply text based on the predicted state information and the first encoding representation of the last sentence;
[0111] 3. Determine the target hidden variable of each sentence based on the state information and the first encoding representation of each sentence in the historical dialogue text;
[0112] 4. Determine the second hidden variable according to the target hidden variable of the reply text and the target hidden variable of each sentence in the historical dialogue text.
[0113] In the embodiments of the present application, the computer device first acquires the first encoded representation of the last sentence in the historical dialogue text when acquiring the second hidden variable. Further, the computer device determines the target hidden variable of the reply text based on the predicted state information and the first encoded representation of the last sentence after acquiring the first encoded representation of the last sentence, and determines the target hidden variable of each sentence based on the state information and the first encoded representation of each sentence in the historical dialogue text. The target hidden variable of the reply text refers to the second hidden variable preliminarily predicted for the reply text, and the target hidden variable of the sentence is used to indicate the sentence individuality information of the sentence, which can also be referred to as the second hidden variable of the sentence.
[0114] In the embodiments of the present application, the computer device determines the second hidden variable based on the target hidden variable of the reply text and the target hidden variable of each sentence in the historical dialogue text after acquiring the target hidden variable of the reply text and the target hidden variable of each sentence in the historical dialogue text. Alternatively, the computer device performs product processing on the target hidden variable of the reply text and the target hidden variable of each sentence in the historical dialogue text to determine the second hidden variable.
[0115] For example, it is assumed that the first encoded representation of each sentence is n-1 represents the number of sentences in the historical dialogue text, and the second hidden variable z I n The acquisition formula of z is as follows:
[0116]
[0117]
[0118]
[0119] wherein u represents the sentence in the historical dialogue text, μ represents the mean, σ represents the square difference, z I i represents the second hidden variable of the i th sentence in the historical dialogue text (which can also be referred to as the target hidden variable of the i th sentence in the present application), c i represents the state information of the i th sentence in the historical dialogue text, and I represents the unit matrix. Alternatively, the sampling process of c i in the embodiments of the present application can solve the problem that the sampling process of c
[0120] To sum up, in the technical scheme provided by the embodiments of the present application, for a known sentence in historical dialogue text, an accurate target latent vector is determined according to the state information and the first encoding representation of the sentence, and for a reply text to be generated, the target latent vector is preliminarily predicted based on the predicted state information and the first encoding representation of the last sentence, thereby improving the accuracy of the second latent vector acquisition.
[0121] Next, the generation manner of the reply text is introduced.
[0122] In the example embodiments, the step 405 includes at least one of the following steps:
[0123] 1. determining a first logical vector based on the second encoding representation of the last word in the historical dialogue text;
[0124] 2. projecting the first latent variable to the space in which the second encoding representation of the last word is located to determine a second logical vector;
[0125] 3. projecting the second latent variable to the space in which the second encoding representation of the last word is located to determine a third logical vector;
[0126] 4. generating the reply text according to the first logical vector, the second logical vector and the third logical vector.
[0127] In the embodiments of the present application, when generating the reply text, the computer device acquires the second encoding representation of the last word in the historical dialogue text, determines a first logical vector based on the second encoding representation of the last word, projects the first latent variable to the space in which the second encoding representation of the last word is located to determine a second logical vector, and projects the second latent variable to the space in which the second encoding representation of the last word is located to determine a third logical vector, and then generates the reply text according to the first logical vector, the second logical vector and the third logical vector.
[0128] Optionally, in the embodiments of the present application, after the computer device acquires the first logical vector, the second logical vector and the third logical vector, the computer device determines the athword in the reply text according to the first logical vector, the second logical vector and the third logical vector. Wherein a is a positive integer. Then, in the case that the athword is a terminal word, the reply text is generated based on the first athword; in the case that the athword is not a terminal word, the athword is concatenated to the last sentence in the historical dialogue text as the last word in the historical dialogue text, a concatenated historical dialogue text is generated, and the step of determining the first latent variable and the state structure of the historical dialogue text based on the sentences contained in the historical dialogue text is executed again with the concatenated historical dialogue text as the new historical dialogue text, to obtain the ath+1word in the reply text, until the terminal word is obtained.
[0129] Exemplarily, assuming the second encoding representation h n of the jth word w j in the reply text u n j n , the first logic vector p j n is:
[0130]
[0131] The second logic vector p I n is:
[0132]
[0133] The third logic vector p S is:
[0134]
[0135] Then, the generation probability of the j+1th word w n in the reply text u j+1 n is defined as:
[0136]
[0137] where W v , W I v , W S v are trainable parameters.
[0138] In summary, in the technical solution provided by the embodiments of the present application, when generating a reply text, the next word is determined based on the previous word, the reply text is generated in word units, and the accuracy of the reply text is improved.
[0139] Optionally, in the embodiments of the present application, the reply text can be generated by a reply text generation model, which includes an encoding network, a feature extraction network and a generator. The encoding network is configured to encode each sentence in the historical dialogue text respectively to obtain the first encoding representation and the second encoding representation of each sentence. The feature extraction network is configured to determine the predicted state information, the first hidden variable and the second hidden variable of the reply text based on the first encoding representation and the second encoding representation of each sentence. The generator is configured to generate the reply text based on the first hidden variable and the second hidden variable.
[0140] Please refer to Figure 6 , which shows a flowchart of a training method of a reply text generation model provided by an embodiment of the present application. The method can be applied toFigure 1 The model training device 30 of the automatic reply system shown, such as the execution subject of each step, can be the model training device 30 (hereinafter referred to as a "computer device"). The method can include at least one of the following steps (601-606):
[0141] Step 601, obtaining sample dialogue text.
[0142] The sample dialogue text refers to the text used to train the reply text generation model. The sample dialogue text includes at least one sample sentence. In an embodiment of the present application, the computer device obtains the sample dialogue text for the reply text generation model before training the reply text generation model.
[0143] Step 602, respectively encoding each sample sentence to obtain a first encoding representation and a second encoding representation of each sample sentence.
[0144] In an embodiment of the present application, the computer device respectively encodes each sample sentence to obtain a first encoding representation and a second encoding representation of each sample sentence after obtaining the sample dialogue text.
[0145] Optionally, in an embodiment of the present application, the computer device respectively encodes each sample sentence using different encoding methods to obtain a first encoding representation and a second encoding representation of each sample sentence. For example, for each sample sentence, the computer device encodes the sample sentence using a K-layer encoding network to obtain a first encoding representation of the sample sentence; and encodes the sample sentence using an L-layer encoding network to obtain a second encoding representation of the sample sentence. Wherein K is less than L, and K and L are positive integers. Optionally, in an embodiment of the present application, the K-layer encoding network is in the L-layer encoding network, and the K-layer encoding network is the first K-layer encoding network in the L-layer encoding network.
[0146] Step 603, determining a first hidden variable based on the first encoding representation of each sample sentence.
[0147] In an embodiment of the present application, the computer device determines a first hidden variable based on the first encoding representation of each sample sentence when the first encoding representation of each sample sentence is obtained. Wherein the first hidden variable is used to indicate the text individual information of the sample dialogue text and the object individual information of the participating object of the sample dialogue text.
[0148] It should be noted that the first hidden variable is information that does not change over time, i.e., the first hidden variable of different sentences in the same sample dialogue text is the same.
[0149] Step 604: Determine the state information of each sample sentence based on the second encoded representation of each sample sentence.
[0150] In this embodiment, after acquiring the second encoded representation of each sample sentence, the computer device determines the state information of each sample sentence based on the second encoded representation. The state information is used to indicate the dialogue intent of the sample sentence.
[0151] Step 605: Based on the first encoded representation of each sample sentence and the state information of each sample sentence, determine the second latent variable of each sample sentence.
[0152] In this embodiment, after acquiring the first encoded representation and state information of each sample sentence, the computer device determines the second latent variable of each sample sentence based on the first encoded representation and state information. The second latent variable indicates the sentence feature information of the sample sentence.
[0153] It should be noted that the second latent variable is information that changes over time; that is, the second latent variable is different for different sentences in the same sample dialogue text.
[0154] Step 606: Train the response text generation model based on the first latent variable, the state information of each sample sentence, and the second latent variable of each sample sentence.
[0155] In this embodiment of the application, after obtaining the first latent variable, the state information of each sample sentence, and the second latent variable of each sample sentence, the computer device trains the response text generation model based on the first latent variable, the state information of each sample sentence, and the second latent variable of each sample sentence.
[0156] It should be noted that, in this embodiment of the application, since the sentences in the sample dialogue text are all known sentences, during the model training process, the above... Figure 5 Different, such as Figure 7 As shown, the state information c1 and the second latent variable z of the sample sentence u1 can be directly determined from the sample sentence u1. I 1. Similarly, based on the sample sentence u2, the state information c2 and the second latent variable z of the sample sentence u2 can be directly determined. I 2. Based on the sample sentence u3, the state information c3 and the second latent variable z of the sample sentence u3 can be directly determined. I 3.
[0157] In the technical solution provided in the embodiments of the present application, the reply text generation model can determine the reply text based on the historical dialogue text, and provides an automatic reply manner. The first hidden variable is used to indicate the text personality information of the historical dialogue text and the object personality information of the participating object of the historical dialogue text, and the second hidden variable is used to indicate the predicted sentence personality information of the reply text. In the model training process, the personalized information of the overall dialogue, the personalized information of the participating object, and the personalized information of the individual sentence are considered, so as to improve the accuracy of the reply text generation model. Moreover, the state information of each sample sentence is used in the training process. The state information of each sentence is associated with each other and can reflect the state transition information of the overall dialogue, so as to improve the accuracy of the reply text generation model.
[0158] Next, the training process of the reply text generation model is introduced.
[0159] In the example embodiment, the step 706 includes at least one of the following steps:
[0160] 1. Determine the first loss of the reply text generation model according to the first hidden variable, the state information of each sample sentence, and the second hidden variable of each sample sentence.
[0161] Optionally, in the embodiments of the present application, the first loss is introduced in the model training process, and the first loss is used to measure the accuracy of the reply text generation model outputting the reply text. In the embodiments of the present application, after the computer device obtains the first hidden variable, the state information of each sample sentence, and the second hidden variable of each sample sentence, the computer device determines the first loss of the reply text generation model according to the first hidden variable, the state information of each sample sentence, and the second hidden variable of each sample sentence.
[0162] Optionally, the first loss includes a first sub-loss, a second sub-loss, a third sub-loss, and a fourth sub-loss.
[0163] Optionally, in the embodiments of the present application, the computer device determines the first sub-loss according to the joint probability distribution of the first hidden variable and the second hidden variable, and the target probability distribution of the first hidden variable and the target probability distribution of the second hidden variable. For example, it is assumed that the target probability distribution of the first hidden variable is The target probability distribution of the second hidden variable is Then, the first sub-loss L1 is:
[0164]
[0165]
[0166] Wherein, n represents the number of sample sentences in the sample dialogue text, u trepresents the t th sample sentence in the sample dialogue text, m represents the number of words in the sample sentence, and X represents the posterior condition.
[0167] Optionally, in the embodiment of the present application, the second hidden variable of each sample sentence corresponds to the same target probability distribution.
[0168] Optionally, in the embodiment of the present application, the computer device determines a second sub-loss according to the predicted probability distribution of the state information of each sample sentence and the target probability distribution of the state information of each sample sentence. For example, it is assumed that the target probability distribution of the state information is Then the second sub-loss L2 is:
[0169]
[0170] where D KL (||) represents the KL divergence.
[0171] Optionally, in the embodiment of the present application, the computer device determines a third sub-loss according to the predicted probability distribution of the first hidden variable and the target probability distribution of the first hidden variable. For example, the third sub-loss L3 is:
[0172]
[0173] Optionally, in the embodiment of the present application, the state information of each sample sentence corresponds to the same target probability distribution.
[0174] Optionally, in the embodiment of the present application, the computer device determines a fourth sub-loss according to the predicted probability distribution of the second hidden variable of each sample sentence and the target probability distribution of the second hidden variable of each sample sentence. For example, the fourth sub-loss L4 is:
[0175]
[0176] Optionally, in the embodiment of the present application, the computer device determines the first loss of the reply text generation model according to the first sub-loss, the second sub-loss, the third sub-loss and the fourth sub-loss. For example, the first loss L elob is:
[0177] L elob =-L1+L2+L3+L4.
[0178] 2. Determine the second loss of the reply text generation model according to the first hidden variable.
[0179] Optionally, in the embodiment of the present application, a second loss is introduced in the model training process, and the second loss is used to measure the consistency of the first hidden variables obtained based on different manners. In the embodiment of the present application, the computer device determines the second loss of the reply text generation model according to the first hidden variables.
[0180] Optionally, in the embodiment of the present application, when obtaining the second loss, the computer device rearranges the sentence order in the sample dialogue text to obtain a rearranged sample dialogue text; extracts a dialogue segment from the sample dialogue text to obtain a sample dialogue text segment; obtains a perturbed hidden variable and a random hidden variable based on the rearranged sample dialogue text and the sample dialogue text segment; wherein the perturbed hidden variable refers to the first hidden variable corresponding to the rearranged sample dialogue text, and the random hidden variable refers to the first hidden variable corresponding to the sample dialogue text segment; and determines the second loss according to the first hidden variable, the perturbed hidden variable and the random hidden variable.
[0181] Exemplarily, assuming that z S represents the first hidden vector, represents the perturbed hidden variable, represents the random hidden variable, and the second loss L scc is:
[0182]
[0183] wherein sim() represents the dot product between two vectors.
[0184] 3. Determine the third loss of the reply text generation model according to the second hidden variables of each sample sentence.
[0185] Optionally, in the embodiment of the present application, a third loss is introduced in the model training process, and the third loss is used to measure the accuracy of the second hidden variables. In the embodiment of the present application, the computer device determines the third loss of the reply text generation model according to the second hidden variables of each sample sentence.
[0186] Optionally, in the embodiment of the present application, the computer device performs verb prediction on each sample sentence based on the second hidden variable of the sample sentence to obtain a verb prediction result corresponding to each sample sentence; and determines the third loss according to the verb prediction result corresponding to each sample sentence.
[0187] Exemplarily, the third loss L dyn is:
[0188]
[0189] wherein when , is a verb.
[0190] 4. Determine a fourth loss of the reply text generation model according to the first latent variable and the second latent variable of each sample sentence.
[0191] Optionally, in the embodiment of the present application, the fourth loss is introduced in the model training process, and the fourth loss is used to measure the decoupling of the first latent variable and the second latent variable. In the embodiment of the present application, the fourth loss of the reply text generation model is determined according to the first latent variable and the second latent variable of each sample sentence.
[0192] Optionally, in the embodiment of the present application, the computer device determines the information entropy of the first latent variable according to the predicted probability distribution of the first latent variable; determines the information entropy of the second latent variable according to the predicted probability distribution of the second latent variable of each sample sentence; determines the joint entropy of the first latent variable and the second latent variable according to the predicted probability distribution of the first latent variable and the predicted probability distribution of the second latent variable of each sample sentence; and determines the fourth loss based on the information entropy of the first latent variable, the information entropy of the second latent variable, and the joint entropy.
[0193] Exemplarily, assuming that the information entropy of the first latent variable is H(z S ), the information entropy of the second latent variable is H(z i I ), and the joint entropy is H(z S , z i I , the fourth loss L mi is:
[0194]
[0195] 5. Adjust the parameters of the reply text generation model according to the first loss, the second loss, the third loss, and the fourth loss.
[0196] In the embodiment of the present application, after the computer device obtains the first loss, the second loss, the third loss, and the fourth loss, the computer device adjusts the parameters of the reply text generation model according to the first loss, the second loss, the third loss, and the fourth loss.
[0197] Optionally, in the embodiment of the present application, after the computer device obtains the first loss, the second loss, the third loss, and the fourth loss, the computer device determines a final loss of the reply text generation model based on the first loss, the second loss, the third loss, and the fourth loss, and adjusts the parameters of the reply text generation model based on the final loss until the final loss converges. Exemplarily, the final loss L is:
[0198] L = L elob + α (L scc + L dyn + L mi );
[0199] wherein, a is a hyperparameter.
[0200] It should be noted that in the embodiments of the present application, the specific processing manner of the reply text generation model for the sample dialogue text has a corresponding relationship with the above-mentioned reply text generation method, and the specific details of the reply text generation model can be referred to the above-mentioned reply text generation method side.
[0201] Next, the related experimental data of the reply text generation model in the present application are compared with the related experimental data of other models used in the automatic dialogue scenario.
[0202] In the zero-resource scenario, the above-mentioned reply text generation model can be directly used after training; in the full-resource scenario, the above-mentioned reply text generation model needs to be adjusted again by the downstream task after training.
[0203] The experimental results on two open field multi-turn dialogue data sets DailyDialog and ConvAI2 (Tables 1 and 2) show that although the model proposed in the present application is much smaller than the baseline (control group) model in parameters, it achieves much better results than the baseline model in the relevance indicators (i.e. BLEU-1 / 2 / 3 / 4, ROUGE-1 / 2 / L and METEOR), and achieves comparable results with the baseline model in the specificity indicators (i.e. Distinct-1 / 2).
[0204] Table 1 Results of automatic evaluation indicators on the test set of DailyDialog
[0205]
[0206]
[0207] Table 2 Results of automatic evaluation indicators on the test set of ConvAI2
[0208]
[0209] In addition, it can be known from Table 3 that the reply text generation model provided in the present application is much better than the baseline model in Relevance and Engagement; and it can be known from Table 4 that the reply text generation model provided in the present application is much better than the baseline model in decoding speed.
[0210] Table 3 Human evaluation results on DailyDialog and ConvAI2
[0211]
[0212]
[0213] Table 4 Test results on decoding speed
[0214]
[0215] It can be understood that in the specific embodiments of the present application, related data such as user information is involved, and when the above embodiments of the present application are applied to specific products or technologies, user permission or consent needs to be obtained, and the collection, use and processing of related data need to comply with relevant laws, regulations and standards of the country and region; for example, the historical dialogue text, sample dialogue text and other aspects involved in the present application are collected in the case of user permission and compliance with relevant laws, regulations and standards.
[0216] It should be further pointed out that the introduction of the present application by the above embodiments is only exemplary and explanatory, and any combination of the steps in the above embodiments to form new embodiments is also within the protection scope of the present application.
[0217] The following is an apparatus embodiment of the present application, which can be used to execute the method embodiments of the present application. For details not disclosed in the apparatus embodiments of the present application, please refer to the method embodiments of the present application.
[0218] Please refer to Figure 8 , which shows a block diagram of a reply text generation apparatus provided by an embodiment of the present application. The apparatus has the function of implementing the above-mentioned reply text generation method, which can be realized by hardware or corresponding software executed by hardware. The apparatus can be a computer device or can be arranged in a computer device. The apparatus 800 can include a text acquisition module 810, a structure determination module 820, a state prediction module 830, a variable determination module 840 and a reply generation module 850.
[0219] The text acquisition module 810 is configured to acquire historical dialogue text, wherein the historical dialogue text includes at least one sentence.
[0220] The structure determination module 820 is configured to determine a first hidden variable and a state structure of the historical dialogue text based on the sentences included in the historical dialogue text; wherein the first hidden variable is used to indicate text personality information of the historical dialogue text and object personality information of a participant object of the historical dialogue text; and the state structure includes state information of each of the sentences, and the state information is used to indicate a dialogue intent of the sentence.
[0221] The state prediction module 830 is configured to determine predicted state information of a reply text corresponding to the historical dialogue text according to the state structure.
[0222] The variable determination module 840 is configured to determine a second latent variable according to the predicted state information, where the second latent variable is used to indicate predicted sentence personality information for the reply text.
[0223] The reply generation module 850 is configured to generate the reply text based on the first latent variable and the second latent variable.
[0224] In an example embodiment, as shown in FIG. 8, the structure determination module 820 includes a sentence encoding unit 821, a first determination unit 822, a state determination unit 823, and a structure generation unit 824. Figure 9
[0225] The sentence encoding unit 821 is configured to encode each of the sentences in the historical dialogue text in two encoding manners to obtain a first encoding representation and a second encoding representation of each of the sentences.
[0226] The first determination unit 822 is configured to determine the first latent variable based on the first encoding representation of each of the sentences.
[0227] The state determination unit 823 is configured to determine state information of each of the sentences based on the second encoding representation of each of the sentences.
[0228] The structure generation unit 824 is configured to generate a state structure of the historical dialogue text according to the state information of each of the sentences.
[0229] In an example embodiment, the sentence encoding unit 821 is configured to, for each of the sentences, encode the sentence by using a K-layer encoding network to obtain the first encoding representation of the sentence, and encode the sentence by using an L-layer encoding network to obtain the second encoding representation of the sentence, where K is less than L, and K and L are positive integers.
[0230] In an example embodiment, the sentence encoding unit 821 is further configured to, for a target word in a target sentence of the historical dialogue text, obtain a preceding word corresponding to the target word from the target sentence, where the preceding word is a word located before the target word in the target sentence, encode the target word and the preceding word by using the K-layer encoding network to obtain a first encoding representation corresponding to the target word, and concatenate the first encoding representation corresponding to each word in the target sentence to obtain the first encoding representation of the target sentence.
[0231] In an example embodiment, the first determination unit 822 is configured to determine a sampling range of the first latent variable based on the first encoding representation of each of the sentences, and sample from the sampling range to determine the first latent variable.
[0232] In an example embodiment, the variable determination module 840 is configured to obtain a first encoded representation of a last sentence in the historical dialogue text; determine a target latent variable of the reply text based on the predicted state information and the first encoded representation of the last sentence, wherein the target latent variable of the reply text refers to a second latent variable preliminarily predicted for the reply text; determine a target latent variable of each of the sentences in the historical dialogue text based on the state information and the first encoded representation of each of the sentences, wherein the target latent variable of the sentence is used to indicate sentence personality information of the sentence; and determine the second latent variable based on the target latent variable of the reply text and the target latent variables of the sentences in the historical dialogue text.
[0233] In an example embodiment, as shown in FIG. 8, the reply generation module 850 includes a vector obtaining unit 851 and a text generation unit 852. Figure 9
[0234] The vector obtaining unit 851 is configured to determine a first logical vector based on a second encoded representation of a last word in the historical dialogue text; project the first latent variable to a space where the second encoded representation of the last word is located to determine a second logical vector; and project the second latent variable to the space where the second encoded representation of the last word is located to determine a third logical vector.
[0235] The text generation unit 852 is configured to generate the reply text based on the first logical vector, the second logical vector, and the third logical vector.
[0236] In an example embodiment, the text generation unit 852 is configured to determine an athword in the reply text based on the first logical vector, the second logical vector, and the third logical vector, wherein a is a positive integer; generate the reply text based on the first athword in a case where the athword is a terminal word; in a case where the athword is not the terminal word, concatenate the athword to a last sentence in the historical dialogue text as a last word in the historical dialogue text to generate a concatenated historical dialogue text; and perform steps of determining the first latent variable and the state structure of the historical dialogue text based on the sentences included in the concatenated historical dialogue text as a new historical dialogue text, to obtain an ath+1word in the reply text, until the terminal word is obtained.
[0237] In an example embodiment, the reply text is generated by a reply text generation model, the reply text generation model comprising an encoding network, a feature extraction network and a generator; wherein the encoding network is configured to encode each of the sentences in the historical dialogue text to obtain a first encoding representation and a second encoding representation of each of the sentences; the feature extraction network is configured to determine the predicted state information of the reply text, the first hidden variable and the second hidden variable based on the first encoding representation and the second encoding representation of each of the sentences; and the generator is configured to generate the reply text based on the first hidden variable and the second hidden variable.
[0238] In summary, in the technical scheme provided by the embodiments of the present application, the first hidden variable and the second hidden variable are used to determine the reply text of the historical dialogue text, the first hidden variable is used to indicate the text individuality information of the historical dialogue text and the object individuality information of the participating object of the historical dialogue text, and the second hidden variable is used to indicate the predicted sentence individuality information of the reply text. When generating the reply text, the individuality information of the overall dialogue, the individuality information of the participating object, and the individuality information of the individual sentence are considered, so as to improve the reply accuracy of the reply text. Moreover, the predicted state information of the reply text is predicted based on the state structure of the historical dialogue text. On the one hand, the state structure includes the state information of each sentence, and the state structure can consider the state transition information of the historical dialogue text, so as to improve the accuracy of state prediction. On the other hand, the state information is an explicit variable relative to the first hidden variable and the second hidden variable, and is used to indicate the dialogue intention of the sentence. The explicit variable is introduced in the reply text generation process, so as to improve the explainability in the reply text generation process, reduce the required parameters in the sentence processing, and improve the generation efficiency of the reply text.
[0239] Please refer to Figure 10 which shows a block diagram of a training device of a reply text generation model provided by an embodiment of the present application. The device has the function of implementing the training method of the above-mentioned reply text generation model, which can be realized by hardware, or the corresponding software can be executed by hardware. The device can be a computer device, or can be arranged in a computer device. The device 1000 can include a sample obtaining module 1010, a sample encoding module 1020, a first determining module 1030, an information determining module 1040, a second determining module 1050 and a model training module 1060.
[0240] The sample obtaining module 1010 is configured to obtain a sample dialogue text, the sample dialogue text comprising at least one sample sentence.
[0241] The sample encoding module 1020 is configured to encode each of the sample sentences to obtain a first encoding representation and a second encoding representation of each of the sample sentences.
[0242] The first determining module 1030 is configured to determine a first hidden variable based on the first encoded representation of each of the sample sentences, where the first hidden variable is used to indicate the text personality information of the sample dialogue text and the object personality information of the participating object of the sample dialogue text.
[0243] The information determining module 1040 is configured to determine state information of each of the sample sentences based on the second encoded representation of each of the sample sentences, where the state information is used to indicate the dialogue intention of the sample sentence.
[0244] The second determining module 1050 is configured to determine a second hidden variable of each of the sample sentences based on the first encoded representation of each of the sample sentences and the state information of each of the sample sentences, where the second hidden variable is used to indicate the sentence feature information of the sample sentence.
[0245] The model training module 1060 is configured to train the reply text generation model according to the first hidden variable, the state information of each of the sample sentences and the second hidden variable of each of the sample sentences.
[0246] In an example embodiment, as shown in Figure 11 The model training module 1060 includes a first obtaining unit 1061, a second obtaining unit 1062, a third obtaining unit 1063, a fourth obtaining unit 1064 and a parameter adjusting unit 1065.
[0247] The first obtaining unit 1061 is configured to determine a first loss of the reply text generation model according to the first hidden variable, the state information of each of the sample sentences and the second hidden variable of each of the sample sentences, where the first loss is used to measure the accuracy of the reply text generation model in outputting the reply text.
[0248] The second obtaining unit 1062 is configured to determine a second loss of the reply text generation model according to the first hidden variable, where the second loss is used to measure the consistency of the first hidden variable obtained in different ways.
[0249] The third obtaining unit 1063 is configured to determine a third loss of the reply text generation model according to the second hidden variable of each of the sample sentences, where the third loss is used to measure the accuracy of the second hidden variable.
[0250] The fourth obtaining unit 1064 is configured to determine a fourth loss of the reply text generation model according to the first hidden variable and the second hidden variable of each of the sample sentences, where the fourth loss is used to measure the decoupling of the first hidden variable and the second hidden variable.
[0251] The parameter adjusting unit 1065 is configured to adjust parameters of the reply text generation model according to the first loss, the second loss, the third loss, and the fourth loss.
[0252] In an example embodiment, the first obtaining unit 1061 is configured to determine a first sub-loss according to a joint probability distribution of the first hidden variable and the second hidden variable, and a target probability distribution of the first hidden variable and a target probability distribution of the second hidden variable; determine a second sub-loss according to a predicted probability distribution of state information of each sample sentence, and a target probability distribution of state information of each sample sentence; determine a third sub-loss according to a predicted probability distribution of the first hidden variable, and a target probability distribution of the first hidden variable; determine a fourth sub-loss according to a predicted probability distribution of the second hidden variable of each sample sentence, and a target probability distribution of the second hidden variable of each sample sentence; and determine the first loss of the reply text generation model according to the first sub-loss, the second sub-loss, the third sub-loss, and the fourth sub-loss.
[0253] In an example embodiment, the second obtaining unit 1062 is configured to rearrange the order of sentences in the sample dialogue text to obtain a rearranged sample dialogue text; extract a dialogue segment from the sample dialogue text to obtain a sample dialogue text segment; obtain a perturbed hidden variable and a random hidden variable based on the rearranged sample dialogue text and the sample dialogue text segment; the perturbed hidden variable refers to a first hidden variable corresponding to the rearranged sample dialogue text, and the random hidden variable refers to a first hidden variable corresponding to the sample dialogue text segment; and determine the second loss according to the first hidden variable, the perturbed hidden variable, and the random hidden variable.
[0254] In an example embodiment, the third obtaining unit 1063 is configured to perform verb prediction on each sample sentence based on the second hidden variable of the sample sentence to obtain a verb prediction result corresponding to each sample sentence; and determine the third loss according to the verb prediction result corresponding to each sample sentence.
[0255] In an example embodiment, the fourth obtaining unit 1064 is configured to determine an information entropy of the first hidden variable according to a predicted probability distribution of the first hidden variable; determine an information entropy of the second hidden variable according to a predicted probability distribution of the second hidden variable of each sample sentence; determine a joint entropy of the first hidden variable and the second hidden variable according to the predicted probability distribution of the first hidden variable and the predicted probability distribution of the second hidden variable of each sample sentence; and determine the fourth loss based on the information entropy of the first hidden variable, the information entropy of the second hidden variable, and the joint entropy.
[0256] To sum up, in the technical scheme provided by the embodiments of the present application, the reply text generation model can determine the reply text based on the historical dialogue text, and provides an automatic reply manner. The first hidden variable is used to indicate the text personality information of the historical dialogue text and the object personality information of the participating object of the historical dialogue text, and the second hidden variable is used to indicate the predicted sentence personality information for the reply text. In the model training process, the personalization information of the overall dialogue, the personalization information of the participating object, and the personalization information of the individual sentence are considered, so as to improve the accuracy of the reply text generation model. Moreover, the state information of each sample sentence is used in the training process. The state information of each sentence is associated with each other and can reflect the state transition information of the overall dialogue, so as to improve the accuracy of the reply text generation model.
[0257] It should be noted that the device provided in the above embodiments is only used as an example to illustrate the division of the above functional modules in realizing its functions. In actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the above described functions. In addition, the device and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process is detailed in the method embodiments, which will not be described here.
[0258] Please refer to Figure 12 which shows the structure block diagram of the computer device provided in an embodiment of the present application. The computer device can be used to realize the functions of the above reply text generation method or the training method of the reply text generation model. Specifically:
[0259] The computer device 1200 includes a central processing unit (CPU) 1201, a system memory 1204 including a random access memory (RAM) 1202 and a read-only memory (ROM) 1203, and a system bus 1205 connecting the system memory 1204 and the central processing unit 1201. The computer device 1200 also includes a basic input / output system (Input / Output, I / O system) 1206 to help transfer information between various devices in the computer, and a mass storage device 1207 for storing an operating system 1213, application programs 1214 and other program modules 1215.
[0260] The basic input / output system 1206 includes the various components needed to display information and input information from a user, such as a display 1208 and input devices 1209, such as a mouse, keyboard, or electronic stylus. Both the display 1208 and the input devices 1209 are connected to the central processing unit 1201 through an input / output controller 1210 that is connected to the system bus 1205. The basic input / output system 1206 can also include the input / output controller 1210 for receiving and processing input from a number of other devices, including a keyboard, mouse, or electronic stylus. Similarly, the input / output controller 1210 provides output to a display screen, a printer, or other type of output device.
[0261] The mass storage device 1207 is connected to the central processing unit 1201 through a mass storage controller (not shown), which is connected to the system bus 1205. The mass storage device 1207 and its associated computer-readable media provide non-volatile storage for the computer device 1200. That is, the mass storage device 1207 can include a computer- readable medium (not shown) such as a hard disk or a CD-ROM (Compact Disc Read-Only Memory) drive.
[0262] Without loss of generality, computer-readable media can include computer storage media and communication media. Computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Computer storage media includes RAM, ROM, EPROM (Erasable Programmable Read Only Memory), EEPROM (Electrically Erasable Programmable Read Only Memory), flash memory or other solid state memory devices, CD-ROM, DVD (Digital Video Disc), or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices. Computer storage media would not, however, include communication media including wired or wireless signaling media that communicate program code in a modulated data signal. The system memory 1204 and mass storage device 1207 described above can be embodied as a memory.
[0263] According to various embodiments of the present application, the computer device 1200 can also operate in a networked environment using a network connection to one or more remote computers. The computer device 1200 can connect to the network 1212 through a network interface unit 1211 connected to the system bus 1205, or can connect to another type of network or remote computer system (not shown) using the network interface unit 1211.
[0264] The memory further includes a computer program stored in the memory and configured to be executed by one or more processors to implement the method for generating a reply text or the method for training a reply text generation model.
[0265] In an example embodiment, a computer-readable storage medium is also provided, and the storage medium stores at least one instruction, at least one program, a code set or an instruction set, which, when executed by a processor, implements the method for generating a reply text or the method for training a reply text generation model.
[0266] Optionally, the computer-readable storage medium can include a ROM (Read Only Memory), a RAM (Random Access Memory), a SSD (Solid State Drives), an optical disc or the like. The random access memory can include a ReRAM (Resistance Random Access Memory) and a DRAM (Dynamic Random Access Memory).
[0267] In an example embodiment, a computer program product or a computer program is also provided, and the computer program product or the computer program includes computer instructions stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions to make the computer device execute the method for generating a reply text or the method for training a reply text generation model.
[0268] It should be understood that "multiple" mentioned herein refers to two or more than two. The "and / or" describes the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B can represent the three cases of A existing alone, A and B existing together, and B existing alone. The character " / " generally represents that the associated objects before and after it are in an "or" relationship. In addition, the step numbers described herein only exemplarily show a possible execution order between steps, and in some other embodiments, the above steps can also be executed in a non-numbered order, such as two different numbered steps being executed simultaneously, or two different numbered steps being executed in an order opposite to the illustration, which is not limited in the embodiments of the present application.
[0269] The above only describes exemplary embodiments of the present application and is not intended to limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method for generating a reply text, characterized by, The method comprises: acquiring historical dialogue text, the historical dialogue text comprising at least one sentence; determining a first hidden variable and a state structure of the historical dialogue text based on the sentences contained in the historical dialogue text; wherein the first hidden variable is used to indicate text personality information of the historical dialogue text and object personality information of a participant object of the historical dialogue text; the state structure comprises state information of each of the sentences, the state information being used to indicate a dialogue intent of the sentence; determining predicted state information of a reply text corresponding to the historical dialogue text according to the state structure; determining a second hidden variable based on the predicted state information, the second hidden variable being used to indicate predicted sentence personality information of the reply text; generating the reply text based on the first hidden variable and the second hidden variable.
2. The method of claim 1, wherein, The method comprises: encoding each of the sentences in the historical dialogue text in two encoding modes to obtain a first encoding representation and a second encoding representation of each of the sentences; determining the first hidden variable based on the first encoding representation of each of the sentences; determining the state information of each of the sentences based on the second encoding representation of each of the sentences; generating the state structure of the historical dialogue text according to the state information of each of the sentences.
3. The method of claim 2, wherein, The method comprises: for each of the sentences, encoding the sentence by using a K-layer encoding network to obtain a first encoding representation of the sentence; encoding the sentence by using an L-layer encoding network to obtain a second encoding representation of the sentence; wherein K is less than L, and K and L are both positive integers.
4. The method of claim 3, wherein, The method comprises: for a target word in a target sentence of the historical dialogue text, acquiring a preceding word corresponding to the target word from the target sentence, the preceding word being a word located before the target word in the target sentence; encoding the target word and the preceding word by using the K-layer encoding network to obtain a first encoding representation corresponding to the target word; splicing the first encoding representation corresponding to each of the words in the target sentence to obtain a first encoding representation of the target sentence.
5. The method of claim 2, wherein, The method comprises: determining a sampling range of the first hidden variable based on the first encoding representation of each of the sentences; sampling from the sampling range to determine the first hidden variable.
6. The method of claim 1, wherein, The method comprises: acquiring a first encoding representation of a last sentence in the historical dialogue text; determine a target latent variable of the reply text based on the predicted state information and the first encoded representation of the last sentence; wherein the target latent variable of the reply text refers to a second latent variable preliminarily predicted for the reply text; determine a target latent variable of each of the sentences in the historical dialogue text based on the state information and the first encoded representation of each of the sentences; wherein the target latent variable of the sentence is used to indicate sentence personality information of the sentence; determine the second latent variable according to the target latent variable of the reply text and the target latent variables of the sentences in the historical dialogue text.
7. The method of claim 1, wherein, The generating the reply text based on the first latent variable and the second latent variable comprises: determine a first logical vector based on the second encoded representation of the last word in the historical dialogue text; project the first latent variable to a space where the second encoded representation of the last word is located to determine a second logical vector; project the second latent variable to the space where the second encoded representation of the last word is located to determine a third logical vector; generate the reply text according to the first logical vector, the second logical vector and the third logical vector.
8. The method of claim 7, wherein, The generating the reply text according to the first logical vector, the second logical vector and the third logical vector comprises: determine an athword in the reply text according to the first logical vector, the second logical vector and the third logical vector; wherein a is a positive integer; in a case where the athword is a terminal word, generate the reply text based on the first athword; in a case where the athword is not a terminal word, concatenate the athword to the last sentence in the historical dialogue text as the last word in the historical dialogue text to generate a concatenated historical dialogue text; and perform the steps of determining the first latent variable and the state structure of the historical dialogue text based on the sentences included in the concatenated historical dialogue text as a new historical dialogue text, to obtain an ath+1word in the reply text until the terminal word is obtained.
9. The method according to any one of claims 1 to 8, characterized in that, The reply text is generated by a reply text generation model, and the reply text generation model comprises an encoding network, a feature extraction network and a generator; wherein the encoding network is configured to encode each of the sentences in the historical dialogue text to obtain a first encoded representation and a second encoded representation of each of the sentences; the feature extraction network is configured to determine predicted state information of the reply text, the first latent variable and the second latent variable based on the first encoded representation and the second encoded representation of each of the sentences; the generator is configured to generate the reply text based on the first latent variable and the second latent variable. 10.A method for training a reply text generation model, the method comprising: The method comprises: obtaining a sample dialogue text, the sample dialogue text comprising at least one sample sentence; encoding each of the sample sentences to obtain a first encoded representation and a second encoded representation of each of the sample sentences; determine a first latent variable based on the first encoded representation of each of the sample sentences, the first latent variable being used to indicate text personality information of the sample dialogue text and object personality information of a participant of the sample dialogue text; determine state information of each of the sample sentences based on a second encoded representation of each of the sample sentences, the state information being used to indicate a dialogue intention of the sample sentence; determine a second latent variable of each of the sample sentences based on the first encoded representation of each of the sample sentences and the state information of each of the sample sentences, the second latent variable being used to indicate sentence feature information of the sample sentence; train the reply text generation model according to the first latent variable, the state information of each of the sample sentences, and the second latent variable of each of the sample sentences.
11. The method of claim 10, wherein, The training of the reply text generation model according to the first latent variable, the state information of each of the sample sentences, and the second latent variable of each of the sample sentences includes: determining a first loss of the reply text generation model according to the first latent variable, the state information of each of the sample sentences, and the second latent variable of each of the sample sentences, the first loss being used to measure accuracy of the reply text generation model in outputting a reply text; determining a second loss of the reply text generation model according to the first latent variable, the second loss being used to measure consistency of the first latent variable obtained based on different manners; determining a third loss of the reply text generation model according to the second latent variable of each of the sample sentences, the third loss being used to measure accuracy of the second latent variable; determining a fourth loss of the reply text generation model according to the first latent variable and the second latent variable of each of the sample sentences, the fourth loss being used to measure decoupling of the first latent variable and the second latent variable; performing parameter adjustment on the reply text generation model according to the first loss, the second loss, the third loss, and the fourth loss.
12. The method of claim 11, wherein, The determination of the first loss of the reply text generation model according to the first latent variable, the state information of each of the sample sentences, and the second latent variable of each of the sample sentences includes: determining a first sub-loss according to a joint probability distribution of the first latent variable and the second latent variable, and a target probability distribution of the first latent variable and a target probability distribution of the second latent variable; determining a second sub-loss according to a predicted probability distribution of the state information of each of the sample sentences, and a target probability distribution of the state information of each of the sample sentences; determining a third sub-loss according to a predicted probability distribution of the first latent variable, and a target probability distribution of the first latent variable; determining a fourth sub-loss according to a predicted probability distribution of the second latent variable of each of the sample sentences, and a target probability distribution of the second latent variable of each of the sample sentences; determining the first loss of the reply text generation model according to the first sub-loss, the second sub-loss, the third sub-loss, and the fourth sub-loss.
13. The method of claim 11, wherein, The determining the second loss of the reply text generation model according to the first latent variable comprises: rearranging the sentence order in the sample dialogue text to obtain a rearranged sample dialogue text; extracting a dialogue segment from the sample dialogue text to obtain a sample dialogue text segment; obtaining a perturbation latent variable and a random latent variable based on the rearranged sample dialogue text and the sample dialogue text segment; wherein the perturbation latent variable refers to a first latent variable corresponding to the rearranged sample dialogue text, and the random latent variable refers to a first latent variable corresponding to the sample dialogue text segment; determining the second loss according to the first latent variable, the perturbation latent variable and the random latent variable.
14. The method of claim 11, wherein, The determining the third loss of the reply text generation model according to the second latent variable of each sample sentence comprises: performing verb prediction on each sample sentence based on the second latent variable of each sample sentence to obtain a verb prediction result corresponding to each sample sentence respectively; determining the third loss according to the verb prediction result corresponding to each sample sentence respectively.
15. The method of claim 11, wherein, The determining the fourth loss of the reply text generation model according to the first latent variable and the second latent variable of each sample sentence comprises: determining the information entropy of the first latent variable according to the prediction probability distribution of the first latent variable; determining the information entropy of the second latent variable according to the prediction probability distribution of the second latent variable of each sample sentence; determining the joint entropy of the first latent variable and the second latent variable according to the prediction probability distribution of the first latent variable and the prediction probability distribution of the second latent variable of each sample sentence; determining the fourth loss based on the information entropy of the first latent variable, the information entropy of the second latent variable and the joint entropy.
16. A reply text generation apparatus characterized by comprising: The device comprises: a text acquisition module configured to acquire historical dialogue text, the historical dialogue text comprising at least one sentence; a structure determination module configured to determine a first latent variable and a state structure of the historical dialogue text based on the sentence included in the historical dialogue text; wherein the first latent variable is used to indicate text personality information of the historical dialogue text and object personality information of a participant object of the historical dialogue text; the state structure comprises state information of each sentence, and the state information is used to indicate a dialogue intent of the sentence; a state prediction module configured to determine predicted state information of a reply text corresponding to the historical dialogue text according to the state structure; a variable determination module configured to determine a second latent variable according to the predicted state information, the second latent variable being used to indicate predicted sentence personality information for the reply text; a reply generation module configured to generate the reply text based on the first latent variable and the second latent variable. 17.A device for training a reply text generation model, comprising: The device comprises: a sample acquisition module configured to acquire sample dialogue text, the sample dialogue text comprising at least one sample sentence; a sample encoding module configured to encode each sample sentence respectively to obtain a first encoded representation and a second encoded representation of each sample sentence; The first determining module is configured to determine a first latent variable based on the first encoded representation of each of the sample sentences, the first latent variable being used to indicate text personality information of the sample dialogue text and object personality information of a participant of the sample dialogue text. The information determining module is configured to determine state information of each of the sample sentences based on the second encoded representation of each of the sample sentences, the state information being used to indicate a dialogue intention of the sample sentence. The second determining module is configured to determine a second latent variable of each of the sample sentences based on the first encoded representation of each of the sample sentences and the state information of each of the sample sentences, the second latent variable being used to indicate sentence feature information of the sample sentence. The model training module is configured to train the reply text generation model according to the first latent variable, the state information of each of the sample sentences, and the second latent variable of each of the sample sentences.
18. A computer device, comprising: The computer device includes a processor and a memory, and the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set are loaded and executed by the processor to implement the reply text generation method according to any one of claims 1 to 9, or implement the training method of the reply text generation model according to any one of claims 10 to 15.
19. A computer-readable storage medium, characterized in that, The storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set are loaded and executed by the processor to implement the reply text generation method according to any one of claims 1 to 9, or implement the training method of the reply text generation model according to any one of claims 10 to 15.
20. A computer program product, characterised in that, The computer program product includes computer instructions stored in a computer readable storage medium, and the processor reads and executes the computer instructions from the computer readable storage medium to implement the reply text generation method according to any one of claims 1 to 9, or implement the training method of the reply text generation model according to any one of claims 10 to 15.
Citation Information
Patent Citations
Dialogue generation method and device
CN110309275A
Dialogue prediction method and device
CN112214591A