Method, apparatus, device, medium and program product for generating dialogue sentences
The method enhances dialogue quality in intelligent conversation systems by determining word importance weights and constructing a corpus recall pool to select contextually relevant replies, addressing the issue of content inconsistency in multi-turn dialogues.
Patent Information
- Application Number
- CN202111405739.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-24
- Publication Date
- 2024-12-31
- Estimated Expiration
- 2041-11-24
AI Technical Summary
Intelligent conversation systems often fail to maintain content consistency in multi-turn dialogues due to the lack of contextual information utilization, leading to poor quality in generated replies.
A method that generates dialogue sentences by determining word importance weights based on self-characteristics and semantic relationships, constructing a corpus recall pool using multiple index libraries, and selecting the candidate reply sentence with the highest match, leveraging pre-trained models to enhance context awareness.
Improves dialogue quality by ensuring content consistency between generated replies and user statements through full utilization of contextual information.
Smart Images

Figure CN114118100B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to a method, an apparatus, an electronic device, a storage medium and a computer program for generating a dialogue sentence. Background Art
[0002] At present, intelligent conversation systems (such as robot customer service, chatbots, etc.) are increasingly used in daily life. For example, they can be used to meet the needs of family care, medical care, education, government agencies, banks, tourism and other industry scenarios. Usually, after receiving the statements sent by the user, the intelligent conversation system can automatically generate corresponding replies to achieve dialogue between people and machines. In this process, the degree of match between the replies generated by the intelligent conversation system and the statements sent by the user is directly related to the quality of the dialogue between people and machines.
[0003] In the related art, the intelligent conversation system usually retrieves the corresponding reply sentences from a pre-built corpus for the sentences sent by the user in a single round of conversation, so as to realize intelligent conversation. Summary of the invention
[0004] The embodiments of the present disclosure provide a method, an apparatus, an electronic device, a storage medium, and a computer program for generating a dialogue sentence, so as to improve the pertinence of the dialogue sentence in an intelligent dialogue system.
[0005] One aspect of an embodiment of the present disclosure provides a method for generating a dialogue sentence, comprising: in response to a current sentence sent by a user, generating a word set of the current sentence, the word elements in the word set including words obtained by word segmentation of the current sentence and phrases constructed based on the words; determining a first importance weight of the word element; based on the semantic relationship of historical dialogue sentences in the current dialogue scene, determining a second importance weight of the word element; based on the first importance weight and the second importance weight, determining an importance parameter of the word element; determining a corpus recall pool of the current sentence, the candidate reply corpus in the corpus recall pool including a first corpus retrieved from a first index library based on the importance parameter and a second corpus retrieved from a second index library based on the similarity between the historical dialogue sentences and a preset corpus; and determining the candidate reply sentence in the corpus recall pool that has the highest degree of match with the current sentence as the target reply sentence.
[0006] In some embodiments, the candidate reply sentence with the highest degree of match with the current sentence in the corpus recall pool is determined as the target reply sentence, including: inputting the candidate reply corpus, the current sentence and the historical conversation sentence into at least one pre-trained corpus determination model, determining a first feature vector and a second feature vector and a third feature vector corresponding to the candidate reply corpus, wherein the first feature vector represents the sentence vector of the sentence obtained by concatenating the current sentence with the historical conversation sentence, the second feature vector represents the sentence vector of the sentence obtained by concatenating the candidate reply corpus with the historical conversation sentence, and the third feature vector represents the sentence vector of the candidate reply corpus; concatenating the first feature vector and the second feature vector and the third feature vector corresponding to the candidate reply corpus to obtain the target feature vector of the candidate reply corpus; inputting the target feature vector into a fully connected layer to estimate the confidence of the candidate reply corpus corresponding to each preset priority label, the priority label representing the degree of match between the candidate reply corpus and the current sentence; inputting each confidence into a pre-built classifier to determine the priority label of the candidate reply corpus; and determining the target reply sentence from the corpus recall pool based on the priority label.
[0007] In some embodiments, at least one corpus determination model is trained via the following steps: extracting sample sentences from a sample conversation log; determining, based on the conversation order, a first preset number of reply sentences and a second preset number of sample historical conversation sentences corresponding to each sample sentence from the sample conversation log, wherein the first preset number of reply sentences occur after the sample sentence and are adjacent to the conversation order of the sample sentence, and the second preset number of sample historical conversation sentences occur before the sample sentence; marking sample labels for the first preset number of reply sentences based on preset priority labels to obtain a first preset number of sample reply sentences; constructing a sample corpus based on the sample sentences, the first preset number of sample reply sentences, and the second preset number of sample historical conversation sentences to obtain a sample set; inputting the sample corpus in the sample set into at least one pre-constructed initial corpus determination model, taking the sample labels of the sample reply sentences as the expected output, training the initial corpus determination model to obtain at least one corpus determination model.
[0008] In some embodiments, a sample corpus in a sample set is input into at least one pre-built initial corpus determination model, and a sample label of a sample reply sentence is used as an expected output to train the initial corpus determination model to obtain at least one corpus determination model, including: determining the semantic type of the sample sentence; based on the semantic type of the sample sentence, determining multiple sample subsets from the sample set, each sample subset including only sample corpora consisting of sample sentences of one semantic type; training a pre-built initial corpus determination model based on each sample subset to obtain multiple corpus determination models corresponding one-to-one to the multiple sample subsets, each corpus determination model corresponding to one semantic type.
[0009] In some embodiments, the candidate response corpus, the current sentence, and the historical conversation sentences are input into at least one pre-built corpus determination model, including: determining the semantic type of the candidate response corpus; using the corpus determination model in at least one corpus determination model that corresponds to the semantic model of the candidate response corpus as the target corpus determination model; and inputting the candidate response corpus, the current sentence, and the historical conversation sentences into the target corpus determination model.
[0010] In some embodiments, word elements also include synonyms of terms.
[0011] In some embodiments, generating a word set for a current sentence includes: detecting information pointing words from the current sentence; determining historical information pointed to by the information pointing words from historical dialogue sentences; replacing the information pointing words in the current sentence with the historical information to obtain an updated current sentence; segmenting the updated current sentence to obtain a word set corresponding to the updated current sentence; combining the words in the word set into phrases based on semantic relationships to obtain a phrase set corresponding to the updated current sentence; and merging the word set and the phrase set to obtain a word set for the current sentence.
[0012] In some embodiments, the method further includes: deleting word elements in the word set that meet preset conditions, the preset conditions being: the number of occurrences is greater than a first preset threshold or less than a second preset threshold, and the second preset threshold is less than the first preset threshold.
[0013] According to another aspect of the embodiments of the present disclosure, an electronic device is provided, comprising: a memory for storing a computer program; and a processor for executing the computer program stored in the memory, wherein when the computer program is executed, the method for generating a dialogue sentence in any of the above embodiments is implemented.
[0014] Another aspect of the embodiments of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method for generating a dialogue sentence in any of the above embodiments.
[0015] Another aspect of the embodiments of the present disclosure provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the method for generating a dialogue statement in any of the above embodiments.
[0016] The method for generating a dialogue sentence provided by the embodiment of the present disclosure generates a word set of the current sentence in response to the current sentence sent by the user; then, the first importance weight of the word element in the word set is determined, and the second importance weight of the word element is determined according to the semantic relationship of the historical dialogue sentence; then, the importance parameter of the word element is determined based on the first importance weight and the second importance weight; then, the first corpus and the second corpus are determined from the first index library and the second index library respectively based on the importance parameter and the similarity between the historical dialogue sentence and the preset corpus, and a corpus recall pool is constructed based on this; finally, the target reply sentence with the highest matching degree with the current sentence is determined from the corpus recall pool. The second importance weight of the word element is determined by the semantic relationship of the historical dialogue sentence, and the second corpus is retrieved based on the similarity between the historical dialogue sentence and the preset corpus, so that the context information is fully utilized, and the consistency of the content between the target reply sentence and the current sentence can be improved, thereby improving the dialogue quality.
[0017] The technical solution of the present disclosure is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The accompanying drawings, which constitute a part of the specification, illustrate embodiments of the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0019] The present disclosure may be more clearly understood from the following detailed description with reference to the accompanying drawings, in which:
[0020] Figure 1 A schematic diagram of an application scenario of the method for generating dialogue sentences disclosed in the present invention;
[0021] Figure 2 A flowchart of an embodiment of a method for generating a dialogue sentence disclosed in the present invention;
[0022] Figure 3 A schematic diagram of a flow chart of determining a target reply sentence in one embodiment of the method for generating a dialogue sentence disclosed in the present invention;
[0023] Figure 4 A schematic diagram of a flow chart of training corpus to determine a model in one embodiment of the method for generating dialogue sentences disclosed herein;
[0024] Figure 5 A schematic diagram of a flow chart of training corpus to determine a model in yet another embodiment of the method for generating dialogue sentences disclosed herein;
[0025] Figure 6 A schematic diagram of a flow chart of generating a word set in one embodiment of the method for generating a dialogue sentence disclosed in the present invention;
[0026] Figure 7 A schematic diagram of the structure of an embodiment of the device for generating dialogue sentences disclosed in the present invention;
[0027] Figure 8 The figure is a schematic diagram of the structure of an application embodiment of the electronic device disclosed in the present invention. DETAILED DESCRIPTION
[0028] Various exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that the relative arrangement of components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present disclosure unless otherwise specifically stated.
[0029] Those skilled in the art can understand that the terms "first" and "second" in the embodiments of the present disclosure are only used to distinguish different steps, devices or modules, etc., and neither represent any specific technical meaning nor indicate the necessary logical order between them.
[0030] It should also be understood that in the embodiments of the present disclosure, “plurality” may refer to two or more than two, and “at least one” may refer to one, two, or more than two.
[0031] It should also be understood that any component, data or structure mentioned in the embodiments of the present disclosure can generally be understood as one or more, unless explicitly limited or otherwise indicated in the context.
[0032] In addition, the term "and / or" in the present disclosure is only a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in the present disclosure generally indicates that the associated objects before and after are in an "or" relationship.
[0033] It should also be understood that the description of the various embodiments in the present disclosure focuses on the differences between the various embodiments, and the same or similar aspects thereof can be referenced to each other, and for the sake of brevity, they will not be described one by one.
[0034] At the same time, it should be understood that for the convenience of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.
[0035] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present disclosure, its application, or uses.
[0036] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered as part of the specification.
[0037] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0038] The embodiments of the present disclosure can be applied to electronic devices such as terminal devices, computer systems, servers, etc., which can operate with many other general or special computing system environments or configurations. Examples of well-known terminal devices, computing systems, environments and / or configurations suitable for use with electronic devices such as terminal devices, computer systems, servers, etc. include, but are not limited to: personal computer systems, server computer systems, thin clients, thick clients, handheld or laptop devices, microprocessor-based systems, set-top boxes, programmable consumer electronics, network personal computers, small computer systems, large computer systems, and distributed cloud computing technology environments including any of the above systems, etc.
[0039] Electronic devices such as terminal devices, computer systems, servers, etc. can be described in the general context of computer system executable instructions (such as program modules) executed by computer systems. Generally, program modules can include routines, programs, object programs, components, logic, data structures, etc., which perform specific tasks or implement specific abstract data types. Computer systems / servers can be implemented in a distributed cloud computing environment, where tasks are performed by remote processing devices linked through a communication network. In a distributed cloud computing environment, program modules can be located on local or remote computing system storage media including storage devices.
[0040] In the process of implementing the present disclosure, the inventors discovered that the intelligent dialogue system in the related art usually retrieves the corresponding reply sentences from a pre-built corpus for the sentences sent by the user in a single round of dialogue. This type of intelligent dialogue system can be applicable to simple question-and-answer dialogues.
[0041] However, in some dialogue scenarios with a large number of dialogue turns (such as instant messaging scenarios), the contextual information in the dialogue scenario is ignored, resulting in poor content consistency between the reply statements generated by the intelligent dialogue system and the statements sent by the user.
[0042] Combine the following Figure 1 The method for generating dialogue information disclosed in the present invention is exemplified. Figure 1In the scenario shown, the server 110 is the server of the intelligent dialogue system, the mobile terminal 120 may be pre-loaded with the client of the intelligent dialogue system, and the intelligent dialogue system may also be a module or unit embedded in the application, such as an automatic customer service module of a shopping application. The user may have a dialogue with the server 110 through the mobile terminal 120. After the user sends the current sentence 130 to the server in the intelligent dialogue system, the server 110 may generate a word set 140 corresponding to the current sentence 130, and determine the first importance weight 150 and the second importance weight 160 of each word element in the word set 140, wherein the second importance weight 160 is determined based on the semantic relationship of the historical dialogue sentences 170 in the current dialogue scenario. Afterwards, the importance parameter 180 of the word element may be determined based on the first importance weight 150 and the second importance weight 160. After that, the corpus recall pool 190 corresponding to the current sentence 130 is determined, and the candidate reply corpus in the corpus recall pool 190 includes a first corpus and a second corpus, wherein the first corpus is a corpus retrieved from a first index library (e.g., Elasticsearch) based on an importance parameter 180, and the second corpus is a corpus retrieved from a second index library (e.g., Faiss) based on the similarity between the historical reply sentence 170 and the preset corpus. Finally, the server 110 selects the target reply sentence 191 with the highest degree of match with the current sentence 130 from the corpus recall pool, and sends the target reply sentence 191 to the mobile terminal 120 to be presented to the user, thereby realizing the automatic generation of dialogue sentences.
[0043] In the process of generating the target reply sentence, the second importance weight of the word element is determined by the semantic relationship of the historical dialogue sentences, and the second corpus is retrieved based on the similarity between the historical dialogue sentences and the preset corpus, thereby making full use of the context information and improving the consistency of the content between the target reply sentence and the current sentence, thereby improving the quality of the dialogue.
[0044] Exemplary Methods
[0045] Next reference Figure 2 , Figure 2 FIG. 1 is a flow chart of an embodiment of a method for generating a dialogue sentence according to the present disclosure. Figure 2 As shown, the process includes the following steps.
[0046] Step 210: In response to the current sentence sent by the user, generate a word set of the current sentence.
[0047] The word elements in the word set include words obtained by segmenting the current sentence and phrases constructed based on the words.
[0048] In a specific example, the execution entity can tokenize the current statement through a tokenization tool to obtain multiple words, and then delete the stop words among them, such as conjunctions and pronouns that do not have practical meanings, specifically such as "de" (of), "le" (particle indicating completion), etc. After that, according to the semantic relationship, the words can be combined to obtain multiple phrases. The multiple words and multiple phrases thus obtained constitute the word set of the current statement.
[0049] Step 220: Determine the first importance weight of the word element.
[0050] In this embodiment, the first importance weight can characterize the importance degree of the word element from the self-characteristics of the word (such as part of speech).
[0051] As an example, the execution entity can first obtain the conversation record in the current conversation scenario, and then based on the conversation record, use a preset TF-IDF (term frequency–inverse document frequency) algorithm or BM25 algorithm to determine the first importance weight of each word element.
[0052] Step 230: Based on the semantic relationship of the historical conversation statements in the current conversation scenario, determine the second importance weight of the word element.
[0053] In practice, the importance degree of the words in the conversation scenario will change dynamically as the conversation continues. In this embodiment, the second importance weight can characterize the importance degree of the word element in the context. For example, the earlier the word element appears in the conversation, the lower its importance and the smaller its corresponding second importance weight; for another example, the more times the word element appears in the conversation, the higher its importance and the larger its corresponding second importance weight.
[0054] As an example, the execution entity can parse the historical conversation statements in the current conversation scenario based on the semantic relationship, determine the target historical conversation statements related to the word element from them, and then according to the time decay mechanism, assign different weights to each target historical conversation statement, and this weight is the second importance weight of the word element.
[0055] For another example, the execution entity can determine the second importance weight of the word element through a neural network model based on the attention mechanism, such as an LSTM (Long Short-Term Memory) neural network.
[0056] Step 240: Based on the first importance weight and the second importance weight, determine the importance parameter of the word element.
[0057] In this embodiment, the importance parameter can characterize the importance degree of the word in both the dimensions of self-characteristics and context.
[0058] As an example, the first importance weight and the second importance weight of a word may be weighted and determined as the importance parameter of the word.
[0059] Step 250: Determine the corpus recall pool of the current sentence.
[0060] The candidate reply corpora in the corpus recall pool include first corpora retrieved from the first index library based on importance parameters and second corpora retrieved from the second index library based on similarity between historical dialogue sentences and preset corpora.
[0061] In a specific example, the first index library can be a corpus built based on ES (Elasticsearch). The execution subject can first convert the importance parameter of the word element into the index value of the word element in ES based on a preset mapping relationship, and then search ES based on the index value to obtain the first corpus corresponding to the word element.
[0062] In some optional implementations of this embodiment, the word elements in step 210 also include synonyms of the words, and the first corpus also includes corpus retrieved based on the synonyms of the words.
[0063] In this implementation, the execution subject may add synonyms of words obtained after word segmentation to the word set, which may increase the quantity of the first corpus retrieved from the first index library.
[0064] In another specific example, the second index library may be a corpus built based on Faiss, in which preset corpus is pre-stored in the form of vectors. The execution subject may first convert the historical dialogue sentences into vector representations, and then search Faiss based on the vectors of the historical dialogue sentences to obtain the second corpus corresponding to the historical dialogue sentences.
[0065] Step 260: Determine the candidate reply corpus in the corpus recall pool that has the highest matching degree with the current sentence as the target reply sentence.
[0066] In this embodiment, the execution subject can determine the candidate reply corpus with the highest matching degree with the current sentence from the corpus recall pool based on a preset screening strategy as the target reply sentence.
[0067] For example, the execution subject can estimate the degree of match between the candidate response corpus and the current sentence based on the number of times the candidate response corpus appears in the corpus recall pool. The more times it appears, the higher the degree of match. The execution subject can determine the candidate response corpus with the most appearances as the target response sentence.
[0068] For another example, the degree of match between the candidate response corpus and the current sentence can be represented by the sum of the importance parameters of each word element contained in the candidate response corpus. The more word elements contained in the candidate response corpus and the larger the sum of the importance parameters, the higher the degree of match. In this way, the execution subject can select the candidate response corpus with the highest degree of match as the target response sentence.
[0069] The method for generating a dialogue sentence provided in this embodiment generates a word set of the current sentence in response to the current sentence sent by the user; then, determines the first importance weight of the word element in the word set, and determines the second importance weight of the word element according to the semantic relationship of the historical dialogue sentence; then, determines the importance parameter of the word element based on the first importance weight and the second importance weight; then, determines the first corpus and the second corpus from the first index library and the second index library respectively based on the importance parameter and the similarity between the historical dialogue sentence and the preset corpus, and constructs a corpus recall pool based on this; finally, determines the target reply sentence with the highest matching degree with the current sentence from the corpus recall pool. The context information in the historical dialogue record can be fully utilized to improve the consistency of the content between the target reply sentence and the current sentence, thereby improving the dialogue quality.
[0070] Next reference Figure 3 , Figure 3 FIG. 2 is a flow chart of determining a target reply sentence in one embodiment of the method for generating a dialogue sentence of the present disclosure. In some optional implementations of the present embodiment, the above step 260 may be implemented as follows: Figure 3 The process shown includes the following steps.
[0071] Step 310: Input the candidate reply corpus, the current sentence, and the historical dialogue sentences into at least one pre-trained corpus determination model to determine a first feature vector and a second feature vector and a third feature vector corresponding to the candidate reply corpus.
[0072] Among them, the first feature vector represents the sentence vector of the sentence obtained by concatenating the current sentence with the historical dialogue sentence, the second feature vector represents the sentence vector of the sentence obtained by concatenating the candidate reply corpus with the historical dialogue sentence, and the third feature vector represents the sentence vector of the candidate reply corpus.
[0073] Step 320: Concatenate the first feature vector and the second feature vector and the third feature vector corresponding to the candidate reply corpus to obtain a target feature vector of the candidate reply corpus.
[0074] In this implementation, the first feature vector can represent the association characteristics between the current sentence and the context in the current dialogue scene, the second feature vector can represent the association characteristics between the candidate reply corpus and the context in the current dialogue scene, and the third feature vector can represent the characteristics of the candidate reply corpus itself.
[0075] In a specific example, the execution subject can determine the first feature vector and the second feature vector and the third feature vector corresponding to the candidate response corpus through the pre-trained Bert (Bidirectional Encoder Representation from Transformers) or GRU (Gated Recurrent Unit). Take Bert as an example for illustrative explanation: the execution subject can first input the current sentence and the historical dialogue sentence into the Bert model, and the Bert model transfers the features in the historical dialogue sentence to the features of the current sentence to obtain the first feature vector; then, the execution subject can input the candidate response corpus and the historical dialogue sentence into the Bert model to obtain the second feature vector; finally, the execution subject can input the candidate response corpus into the Bert model to obtain the third feature vector.
[0076] Step 330: Input the target feature vector into the fully connected layer to estimate the confidence of the candidate response corpus corresponding to each preset priority label.
[0077] In this implementation, the priority label represents the degree of match between the candidate reply corpus and the current sentence, and the higher the degree of match, the higher the priority. In a specific example, the priority labels may include, from high to low: high-quality reply, general reply, poor reply, non-reply in the same conversation, and non-reply in different conversations. Among them, "non-reply in the same conversation" means that the candidate reply corpus belongs to the same conversation scene as the current sentence, but the candidate reply corpus is not a reply sentence of the current sentence. "Non-reply in different conversations" means that the candidate reply belongs to a different conversation scene than the current sentence, and is not a reply sentence of the current sentence.
[0078] The execution subject may input the target feature vectors of each candidate reply corpus into the fully connected layer in sequence, and determine the confidence of each target feature vector corresponding to each priority label in sequence.
[0079] Step 340: Input each confidence level into a pre-built classifier to determine the priority label of the candidate reply corpus.
[0080] As an example, softmax can be used as a classifier, and the execution entity can input the confidence of the target feature vector obtained in step 330 into the classifier, and the classifier determines the priority label of the target feature vector, which is the priority label of the candidate reply corpus.
[0081] Step 350: Determine a target response sentence from the corpus recall pool based on the priority tag.
[0082] As an example, the execution subject may sort the candidate response corpora according to the priority labels, and then select the target response sentence from the candidate response corpora with the highest priority.
[0083] In this implementation, three feature vectors are used to characterize the characteristics of the candidate reply corpus from three dimensions respectively, and the priority label is used to characterize the degree of match between the candidate reply corpus and the current sentence, and the target reply sentence is determined based on this. The contextual information in the dialogue scene can be coupled to the screening process of the reply corpus, thereby improving the match between the target reply sentence and the current sentence.
[0084] Next reference Figure 4 , Figure 4 FIG. 1 is a flow chart of a training corpus determination model in one embodiment of the method for generating dialogue sentences disclosed in the present invention. Figure 4 As shown, the process includes the following steps.
[0085] Step 410: extract sample sentences from the sample conversation log.
[0086] As an example, the execution subject may extract historical dialogue logs from the intelligent dialogue system, and then extract user dialogue records therefrom as sample sentences.
[0087] Step 420: Based on the conversation order, determine from the sample conversation log a first preset number of reply sentences and a second preset number of sample historical conversation sentences corresponding to each sample sentence.
[0088] Among them, a preset number of reply statements occur after the sample statement and are adjacent to the conversation order of the sample statement, and a second preset number of sample historical conversation statements occur before the sample statement.
[0089] In practice, intelligent dialogue systems may have a phenomenon of misaligned dialogue sentences, that is, the current reply sentence does not correspond to the current user sentence, but is a reply generated for the user sentence before the current user sentence.
[0090] In order to avoid the adverse effect of the misaligned dialogue sentences on the dialogue quality of the intelligent dialogue system, this embodiment can simultaneously obtain multiple reply sentences after the sample sentence to ensure that the reply sentence includes a reply corresponding to the sample sentence.
[0091] The execution entity can first determine the position of the sample statement in the sample conversation log, and then use the three replies after the sample statement and closest to the sample statement as reply statements to the sample statement. At the same time, a second preset number of conversation statements before the position can also be extracted from the sample log as sample historical conversation statements.
[0092] Step 430: Based on the preset priority labels, mark sample labels for the first preset number of reply statements respectively to obtain a preset number of sample reply statements.
[0093] Step 440: construct a sample corpus based on the sample sentences, a first preset number of sample reply sentences, and a second preset number of sample historical conversation sentences to obtain a sample set.
[0094] Step 450: Input the sample corpus in the sample set into at least one pre-built initial corpus determination model, take the sample label of the sample reply sentence as the expected output, train the initial corpus determination model, and obtain at least one corpus determination model.
[0095] In this embodiment, multiple replies after the sample sentence can be determined as reply sentences corresponding to the sample sentence, and priority tags are respectively marked on each reply sentence to construct a sample corpus. Then, an initial corpus determination model is trained based on the sample corpus to obtain a trained corpus determination model, which can avoid the adverse effects of misaligned dialogue sentences on the accuracy of the corpus determination model, thereby improving the accuracy of the corpus determination model.
[0096] Next reference Figure 5 , Figure 5 FIG. 1 is a flow chart of training corpus to determine a model in another embodiment of the method for generating dialogue sentences disclosed in the present invention. Figure 4 In some optional implementations of the illustrated embodiment, the above step 450 may include the following steps.
[0097] Step 510: Determine the semantic type of the sample sentence.
[0098] In this implementation, the semantic type may represent the semantic features of the sample sentence, and may include, for example, statement, inquiry, answer, and the like.
[0099] The execution subject can determine the semantic type of the sample statement based on its content.
[0100] Step 520: Determine multiple sample subsets from the sample set based on the semantic type of the sample sentence.
[0101] Each sample subset includes sample corpus consisting of sample sentences of only one semantic type.
[0102] As an example, the execution subject can extract sample corpus whose sample sentences are of the "statement" type from the sample set to construct the first sample subset; extract sample corpus whose sample sentences are of the "question" type from the sample set to construct the second sample subset. Similarly, a sample subset can be constructed for each semantic type.
[0103] Step 530: train a pre-built initial corpus determination model based on each sample subset to obtain multiple corpus determination models corresponding to the multiple sample subsets.
[0104] In this implementation, each corpus determination model corresponds to a semantic type.
[0105] Continuing with the example in step 520, the execution entity can simultaneously construct two initial corpus determination models. Based on the first sample subset, the first initial corpus determination model is trained to obtain a first corpus determination model corresponding to the "statement" type; based on the second sample subset, the second initial corpus determination model is trained to obtain a second corpus determination model corresponding to the "inquiry" type.
[0106] In this implementation, a corresponding sample subset can be constructed according to the semantic type of the sample sentence, and the corresponding corpus determination model can be trained based on it, which can improve the recognition accuracy of the corpus determination model for the corpus of this semantic type, thereby improving the accuracy of determining the priority of the candidate reply corpus.
[0107] In an optional example of the present implementation, inputting the candidate reply corpus, the current sentence, and the historical conversation sentences into at least one pre-built corpus determination model may also include: determining the semantic type of the candidate reply corpus; using the corpus determination model in at least one corpus determination model that corresponds to the semantic model of the candidate reply corpus as the target corpus determination model; and inputting the candidate reply corpus, the current sentence, and the historical conversation sentences into the target corpus determination model.
[0108] In this example, a corpus determination model corresponding to the semantic type of the candidate reply corpus can be used to identify the candidate reply corpus to determine the priority of the candidate reply corpus, and the degree of match between the candidate reply corpus and the current sentence can be determined more accurately.
[0109] Next reference Figure 6 ,exist Figure 2 In some optional implementations of the embodiment shown, step 210 may also be implemented by Figure 6 The process shown also includes the following steps.
[0110] Step 610: Detect information pointing words from the current sentence.
[0111] Step 620: Determine the historical information pointed to by the information pointing word from the historical dialogue sentences.
[0112] In a multi-round dialogue scenario, the subsequent dialogue usually uses information-pointing words to represent specific information in the previous dialogue.
[0113] In this implementation, the information pointing words are used to refer to the historical information involved in the historical dialogue sentences, for example, they can be phrases used to represent the order, or they can be phrases used to represent the characteristics of the object.
[0114] As an example, if a dialogue scene involves multiple objects, the specific object can be referred to by the sequence number of the object's appearance, such as "the number".
[0115] For another example, if a dialogue scene involves multiple objects of different colors, color adjectives and pronouns can be used to form information pointing words, such as "the yellow one."
[0116] Step 630: Replace the information pointing word in the current sentence with the historical information to obtain an updated current sentence.
[0117] For example, the current sentence is "I want to buy a second house", and the historical information pointed to by "second house" is "three bedrooms and one living room". Then the updated current sentence is "I want to buy that three-bedroom, one-living room house".
[0118] Step 640: Segment the updated current sentence to obtain a word set corresponding to the updated current sentence.
[0119] Step 650: Based on the semantic relationship, combine the words in the word set into phrases to obtain an updated phrase set corresponding to the current sentence.
[0120] Step 660: Merge the word set and the phrase set to obtain the word set of the current sentence.
[0121] In this implementation, the historical information in the above text can be substituted into the current sentence, and then the corresponding word set can be constructed based on the updated current sentence, which can improve the coupling degree between the context information and the generation process of the target reply sentence, and can further improve the matching degree between the target reply sentence and the current dialogue.
[0122] Furthermore, the method also includes: deleting word elements in the word set that meet preset conditions, the preset conditions being: the number of occurrences is greater than a first preset threshold or less than a second preset threshold, and the second preset threshold is less than the first preset threshold.
[0123] In this implementation, the word elements that meet the preset conditions represent word elements with low importance and low impact on the target reply sentence. Deleting the word elements with low importance can reduce the redundant data in the word set and improve the operation efficiency while ensuring the quality of the dialogue.
[0124] Exemplary Devices
[0125] Next reference Figure 7 , Figure 7FIG. 1 is a schematic diagram of a structure of an embodiment of a device for generating a dialogue sentence according to the present disclosure, as shown in FIG. Figure 7 As shown, the device includes: a set generation unit 710, configured to generate a word set of the current sentence in response to the current sentence sent by the user, the word elements in the word set include words obtained by word segmentation of the current sentence and phrases constructed based on the words; a first weight unit 720, configured to determine a first importance weight of the word element; a second weight unit 730, configured to determine a second importance weight of the word element based on the semantic relationship of the historical dialogue sentences in the current dialogue scene; a parameter determination unit 740, configured to determine the importance parameter of the word element based on the first importance weight and the second importance weight; a corpus recall unit 750, configured to determine a corpus recall pool of the current sentence, the candidate reply corpus in the corpus recall pool includes a first corpus retrieved from the first index library based on the importance parameter and a second corpus retrieved from the second index library based on the similarity between the historical dialogue sentences and the preset corpus; a sentence determination unit 760, configured to determine the candidate reply corpus with the highest matching degree of the current sentence in the corpus recall pool as the target reply sentence.
[0126] In this embodiment, the sentence determination unit 760 further includes: a feature extraction module, configured to input the candidate reply corpus and the historical dialogue sentence into at least one pre-trained corpus determination model, determine a first feature vector and a second feature vector and a third feature vector corresponding to the candidate reply corpus, wherein the first feature vector represents the sentence vector of the sentence obtained by concatenating the current sentence with the historical dialogue sentence, the second feature vector represents the sentence vector of the sentence obtained by concatenating the candidate reply corpus with the historical dialogue sentence, and the third feature vector represents the sentence vector of the candidate reply corpus; a vector concatenation module, configured to input the first feature vector and the second feature vector and the third feature vector corresponding to the candidate reply corpus; The target feature vector of the candidate reply corpus is concatenated with the second feature vector and the third feature vector corresponding to the candidate reply corpus to obtain the target feature vector of the candidate reply corpus; the confidence determination module is configured to input the target feature vector into the fully connected layer to estimate the confidences of the candidate reply corpus corresponding to each preset priority label, and the priority label represents the degree of match between the candidate reply corpus and the current sentence; the priority determination module is configured to input each confidence into a pre-built classifier to determine the priority label of the candidate reply corpus; the corpus determination module is configured to determine the target reply sentence from the corpus recall pool based on the priority label.
[0127] In this embodiment, the device also includes a model training unit, which includes: a sample sentence extraction module, configured to extract sample sentences from a sample conversation log; a reply sentence extraction module, configured to determine, based on the conversation order, a first preset number of reply sentences and a second preset number of sample historical conversation sentences corresponding to each sample sentence from the sample conversation log, wherein the preset number of reply sentences occur after the sample sentence and are adjacent to the conversation order of the sample sentence, and the second preset number of sample historical conversation sentences occur before the sample sentence; a marking module, configured to mark sample labels for the first preset number of reply sentences based on a preset priority label, respectively, to obtain a first preset number of sample reply sentences; a sample construction module, configured to construct a sample corpus based on the sample sentence and the preset number of sample reply sentences, to obtain a sample set; a training module, configured to input the sample corpus in the sample set into at least one pre-constructed initial corpus determination model, take the sample label of the sample reply sentence as the expected output, train the initial corpus determination model, and obtain at least one corpus determination model.
[0128] In this embodiment, the training module is further configured to: determine the semantic type of the sample sentence; based on the semantic type of the sample sentence, determine multiple sample subsets from the sample set, each sample subset only includes a sample corpus consisting of sample sentences of one semantic type; based on each sample subset, train a pre-constructed initial corpus determination model to obtain multiple corpus determination models corresponding one-to-one to the multiple sample subsets, each corpus determination model corresponds to one semantic type.
[0129] In this embodiment, the feature extraction module further includes: a type determination submodule, configured to determine the semantic type of the candidate reply corpus; a model determination submodule, configured to use the corpus determination model corresponding to the semantic model of the candidate reply corpus in at least one corpus determination model as the target corpus determination model; and an input submodule, configured to input the candidate reply corpus, the current sentence and the historical dialogue sentence into the target corpus determination model.
[0130] In this embodiment, word elements also include synonyms of words.
[0131] In this embodiment, the collection birth unit further includes: an information detection module, which is configured to detect information pointing words from the current sentence; an information determination module, which is configured to determine the historical information pointed to by the information pointing words from the historical dialogue sentences; an information substitution module, which is configured to replace the information pointing words in the current sentence with the historical information to obtain an updated current sentence; a word segmentation module, which is configured to segment the updated current sentence to obtain a word set corresponding to the updated current sentence; a phrase construction module, which is configured to combine the words in the word set into phrases based on semantic relationships to obtain a phrase set corresponding to the updated current sentence; and a merging module, which is configured to merge the word set and the phrase set to obtain the word set of the current sentence.
[0132] In this embodiment, the device also includes a filtering unit configured to delete word elements in the word set that meet preset conditions, wherein the preset conditions are: the number of occurrences is greater than a first preset threshold or less than a second preset threshold, and the second preset threshold is less than the first preset threshold.
[0133] In addition, an embodiment of the present disclosure further provides an electronic device, including:
[0134] Memory for storing computer programs;
[0135] The processor is used to execute the computer program stored in the memory, and when the computer program is executed, the method for generating a dialogue sentence described in any of the above embodiments of the present disclosure is implemented.
[0136] Figure 8 This is a schematic diagram of the structure of an application embodiment of the electronic device disclosed in the present invention. Figure 8 The electronic device according to the embodiment of the present disclosure is described. The electronic device may be any one or both of the first device and the second device, or a stand-alone device independent of them, and the stand-alone device may communicate with the first device and the second device to receive the collected input signals from them.
[0137] like Figure 8 As shown, the electronic device includes one or more processors and memory.
[0138] The processor may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device to perform desired functions.
[0139] The memory may include one or more computer program products, and the computer program product may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, a random access memory (RAM) and / or a cache memory (cache), etc. The non-volatile memory may include, for example, a read-only memory (ROM), a hard disk, a flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor may execute the program instructions to implement the method for generating a dialogue statement and / or other desired functions of the various embodiments of the present disclosure described above.
[0140] In one example, the electronic device may further include: an input device and an output device, and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).
[0141] In addition, the input device may also include, for example, a keyboard, a mouse, and the like.
[0142] The output device can output various information to the outside, including determined distance information, direction information, etc. The output device can include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto, and the like.
[0143] Of course, to simplify, Figure 8 Only some of the components related to the present disclosure in the electronic device are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application situations, the electronic device may further include any other appropriate components.
[0144] In addition to the above-mentioned methods and devices, an embodiment of the present disclosure may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps in the method for generating dialogue sentences according to various embodiments of the present disclosure described in the above part of this specification.
[0145] The computer program product may be written in any combination of one or more programming languages to write program code for performing the operations of the disclosed embodiments, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0146] In addition, an embodiment of the present disclosure may also be a computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, causes the processor to execute the steps of the method for generating dialogue sentences according to various embodiments of the present disclosure described in the above part of this specification.
[0147] The computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0148] A person of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk, etc., various media that can store program codes.
[0149] The basic principles of the present disclosure are described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, effects, etc. mentioned in the present disclosure are only examples and not limitations, and it cannot be considered that these advantages, strengths, effects, etc. are required by each embodiment of the present disclosure. In addition, the specific details disclosed above are only for the purpose of illustration and ease of understanding, and are not limitations. The above details do not limit the present disclosure to the necessity of adopting the above specific details to be implemented.
[0150] Each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system embodiment, since it basically corresponds to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0151] The block diagrams of the devices, apparatuses, equipment, and systems involved in this disclosure are only illustrative examples and are not intended to require or imply that they must be connected, arranged, and configured in the manner shown in the block diagrams. As will be appreciated by those skilled in the art, these devices, apparatuses, equipment, and systems can be connected, arranged, and configured in any manner. Words such as "including," "comprising," "having," and the like are open words, referring to "including but not limited to," and can be used interchangeably therewith. The words "or" and "and" used herein refer to the words "and / or," and can be used interchangeably therewith, unless the context clearly indicates otherwise. The word "such as" used herein refers to the phrase "such as but not limited to," and can be used interchangeably therewith.
[0152] The method and apparatus of the present disclosure may be implemented in many ways. For example, the method and apparatus of the present disclosure may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above order of steps for the method is for illustration only, and the steps of the method of the present disclosure are not limited to the order specifically described above, unless otherwise specifically stated. In addition, in some embodiments, the present disclosure may also be implemented as a program recorded in a recording medium, which includes machine-readable instructions for implementing the method according to the present disclosure. Therefore, the present disclosure also covers a recording medium storing a program for executing the method according to the present disclosure.
[0153] It should also be noted that in the apparatus, device and method of the present disclosure, each component or each step can be decomposed and / or recombined. Such decomposition and / or recombination should be regarded as equivalent solutions of the present disclosure.
[0154] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the aspects shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
[0155] The above description has been given for the purpose of illustration and description. In addition, this description is not intended to limit the embodiments of the present disclosure to the forms disclosed herein. Although multiple example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, changes, additions and sub-combinations thereof.
Claims
1. A method for generating a dialogue sentence, characterized in that: include: In response to a current sentence sent by a user, a word set of the current sentence is generated, wherein the word elements in the word set include words obtained by word segmentation of the current sentence and phrases constructed based on the words; Determine a first importance weight of the word element, where the first importance weight is used to characterize the importance of the word element based on its own characteristics, where the own characteristics include part of speech; Determining a second importance weight of the word element based on a semantic relationship of historical dialogue sentences in a current dialogue scene, wherein the second importance weight is used to represent the importance of the word element in a context; Based on the first importance weight and the second importance weight, determining an importance parameter of the word element, wherein the importance parameter is used to simultaneously characterize the importance of the word element in two dimensions: the word element's own characteristics and the context; Determine a corpus recall pool for the current sentence, wherein the candidate reply corpus in the corpus recall pool includes a first corpus retrieved from a first index library based on the importance parameter and a second corpus retrieved from a second index library based on a similarity between the historical dialogue sentence and a preset corpus; The candidate reply corpus in the corpus recall pool that has the highest matching degree with the current sentence is determined as the target reply sentence.
2. The method according to claim 1, characterized in that Determining the candidate reply corpus with the highest matching degree with the current sentence in the corpus recall pool as the target reply sentence includes: Input the candidate reply corpus, the current sentence, and the historical dialogue sentence into at least one pre-trained corpus determination model to determine a first feature vector and a second feature vector and a third feature vector corresponding to the candidate reply corpus, wherein the first feature vector represents a sentence vector of a sentence obtained by concatenating the current sentence with the historical dialogue sentence, the second feature vector represents a sentence vector of a sentence obtained by concatenating the candidate reply corpus with the historical dialogue sentence, and the third feature vector represents a sentence vector of the candidate reply corpus; concatenating the first feature vector, the second feature vector, and the third feature vector to obtain a target feature vector of the candidate response corpus; Input the target feature vector into a fully connected layer to estimate the confidence of the candidate reply corpus corresponding to each preset priority label, wherein the priority label represents the matching degree between the candidate reply corpus and the current sentence; Inputting each of the confidences into a pre-built classifier to determine a priority label for the candidate response corpus; Based on the priority tag, the target response sentence is determined from the corpus recall pool.
3. The method according to claim 2, characterized in that The at least one corpus determination model is trained via the following steps: Extract sample sentences from the sample conversation log; Based on the conversation order, determining a first preset number of reply statements and a second preset number of sample history conversation statements corresponding to each of the sample statements from the sample conversation log, wherein the first preset number of reply statements occur after the sample statement and are adjacent to the conversation order of the sample statement, and the second preset number of sample history conversation statements occur before the sample statement; Based on the preset priority labels, respectively label the first preset number of reply statements with sample labels to obtain the first preset number of sample reply statements; Based on the sample sentences, the first preset number of sample reply sentences, and the second preset number of sample historical conversation sentences, construct a sample corpus to obtain a sample set; The sample corpus in the sample set is input into at least one pre-built initial corpus determination model, the sample label of the sample reply sentence is used as the expected output, the initial corpus determination model is trained, and the at least one corpus determination model is obtained.
4. The method according to claim 3, characterized in that Inputting the sample corpus in the sample set into at least one pre-built initial corpus determination model, taking the sample label of the sample reply sentence as the expected output, training the initial corpus determination model, and obtaining the at least one corpus determination model, including: Determining the semantic type of the sample sentence; Based on the semantic type of the sample sentences, determining a plurality of sample subsets from the sample set, each of the sample subsets only including sample corpora consisting of sample sentences of one semantic type; A pre-built initial corpus determination model is trained based on each of the sample subsets to obtain a plurality of corpus determination models corresponding one-to-one to the plurality of sample subsets, each of the corpus determination models corresponding to a semantic type.
5. The method according to claim 4, characterized in that Inputting the candidate reply corpus, the current sentence, and the historical dialogue sentence into at least one pre-built corpus determination model comprises: Determining the semantic type of the candidate response corpus; Using a corpus determination model corresponding to the semantic model of the candidate reply corpus in the at least one corpus determination model as a target corpus determination model; The candidate reply corpus, the current sentence and the historical dialogue sentence are input into the target corpus determination model.
6. The method according to any one of claims 1 to 5, characterized in that The word elements also include: synonyms of the words.
7. The method according to any one of claims 1 to 5, characterized in that Generate a word set for the current sentence, including: Detecting information pointing words from the current sentence; Determining the historical information pointed to by the information pointing word from the historical dialogue sentences; Replacing the information pointing word in the current sentence with the historical information to obtain an updated current sentence; Segmenting the updated current sentence to obtain a word set corresponding to the updated current sentence; Based on the semantic relationship, the words in the word set are combined into phrases to obtain a phrase set corresponding to the updated current sentence; The word set and the phrase set are combined to obtain the word set of the current sentence.
8. The method according to claim 7, characterized in that The method further comprises: Delete word elements in the word set that meet a preset condition, wherein the preset condition is: the number of occurrences is greater than a first preset threshold or less than a second preset threshold, and the second preset threshold is less than the first preset threshold.
9. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to execute a computer program stored in the memory, and when the computer program is executed, implement the method described in any one of claims 1 to 8.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method described in any one of claims 1 to 8 is implemented.
11. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the method described in any one of claims 1 to 8 is implemented.
