Conversational methods and systems
By combining deep learning models to calculate the semantic similarity and matching degree between the dialogue context and candidate dialogues, the problem of inaccurate responses caused by ignoring contextual information in existing technologies is solved, and more accurate response selection is achieved.
Patent Information
- Application Number
- CN202010707211.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-21
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2040-07-21
AI Technical Summary
Existing retrieval-based dialogue systems ignore contextual information in candidate responses when calculating their matching accuracy, resulting in inaccurate responses.
By combining deep learning models, the semantic similarity and matching degree between the dialogue context and multiple candidate dialogues are calculated, and the most matching candidate dialogue is selected as the response dialogue. This includes using Transformer networks, cross-attention operations, self-attention operations, graph attention networks, and multilayer perceptrons to calculate semantic similarity and matching degree.
This improves the accuracy of responses, ensuring that the responses better match the user's query intent.
Smart Images

Figure CN114036267B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the field of natural language processing, and in particular, to a dialogue method and system. BACKGROUND
[0002] In recent years, with the increasing maturity of deep learning models in natural language processing, deep learning models have been widely applied to dialogue systems. Dialogue systems can be divided into generative dialogue systems and retrieval dialogue systems according to the implementation. The generative dialogue system constructs a response sentence according to the user input sentence. The retrieval dialogue system retrieves the past dialogue dataset according to the user input sentence and selects the most matching response sentence. At present, the retrieval dialogue system is widely applied in practice, such as online customer service system.
[0003] Figure 1 is a schematic diagram of a prior art retrieval dialogue system. The dialogue system includes a coarse-grained screening step S10 and a fine-grained screening step S20. Specifically, step S10 screens the entire dialogue dataset using dialogue context to select multiple candidate responses. The screening is mainly based on conventional methods such as TF-IDF (term frequency-inverted document frequency), which is efficient but has relatively low accuracy. Step S20 uses a CRM (context-to-response matching) model to select the final response from the multiple candidate responses. The CRM model calculates the matching degree between the dialogue context and the multiple candidate responses respectively, and determines the final response based on the matching degree. However, the CRM model ignores the previous information of the candidate response in the calculation process, and these information is usually very useful. Ignoring the previous information of the candidate response by CRM may lead to inaccurate calculation results, and further lead to the inability to output the most matching response. SUMMARY
[0004] Therefore, the purpose of the present disclosure is to provide a dialogue method and system to solve the above problems existing in the retrieval dialogue system.
[0005] In a first aspect, the embodiments of the present disclosure provide a dialogue method, comprising:
[0006] obtaining a dialogue context of a user query;
[0007] obtaining multiple candidate dialogues according to the dialogue context;
[0008] selecting a candidate dialogue that is most matched with the dialogue context from the multiple candidate dialogues as a reply dialogue;
[0009] determine a reply to the user query according to the reply dialogue.
[0010] Optionally, the selecting, from the plurality of candidate dialogues, a candidate dialogue that is most matched with the dialogue context as the reply dialogue comprises:
[0011] calculating semantic similarity between the dialogue context and the plurality of candidate dialogues;
[0012] calculating a matching degree between the dialogue context and replies of the plurality of candidate dialogues;
[0013] selecting, according to the semantic similarity and the matching degree, a candidate dialogue that is most matched as the reply dialogue.
[0014] Optionally, the calculating semantic similarity between the dialogue context and the plurality of candidate dialogues comprises:
[0015] inputting the dialogue context and the plurality of candidate dialogues into a trained first model, and calculating, by the first model, semantic similarity between the dialogue context and the plurality of candidate dialogues;
[0016] wherein the first model performs the following operations:
[0017] representing words in a constituent sentence in the dialogue context as a plurality of first word vectors;
[0018] representing words in a constituent sentence in the candidate dialogue as a plurality of second word vectors;
[0019] calculating the semantic similarity according to the plurality of first word vectors and the plurality of second word vectors.
[0020] Optionally, the calculating the semantic similarity according to the plurality of first word vectors and the plurality of second word vectors comprises:
[0021] performing cross-attention operations on the plurality of first word vectors and the plurality of second word vectors to obtain a first matrix;
[0022] performing self-attention operations and then cross-attention operations on the plurality of first word vectors and the plurality of second word vectors to obtain a second matrix;
[0023] inputting a matrix obtained by stacking the first matrix and the second matrix into a preset model, extracting matching features by the preset model, and unfolding the extracted features into a plurality of one-dimensional vectors; and
[0024] calculating, based on the plurality of one-dimensional vectors, a first vector representing semantic similarity using a graph attention network and an attention mechanism with role information.
[0025] Optionally, the selecting the most matched candidate dialogue as the reply dialogue according to the semantic similarity and the matching degree comprises:
[0026] calculating scores of the plurality of candidate dialogues according to the semantic similarity and the matching degree;
[0027] selecting the candidate dialogue with the highest score as the reply dialogue.
[0028] Optionally, the calculating scores of the plurality of candidate dialogues according to the semantic similarity and the matching degree comprises:
[0029] modeling the first vector representing the semantic similarity and the second vector representing the matching degree through a first multi-layer perceptron, and calculating the scores by using a second multi-layer perceptron.
[0030] Optionally, the obtaining the plurality of candidate dialogues according to the dialogue context comprises:
[0031] filtering the plurality of candidate dialogues from a historical dialogue dataset according to the dialogue context, each piece of data in the historical dialogue dataset comprising at least one round of dialogue.
[0032] Optionally, the filtering the plurality of candidate dialogues from the historical dialogue dataset by using the TF-IDF algorithm.
[0033] In a second aspect, the embodiments of the present disclosure provide a dialogue system, comprising:
[0034] a dialogue collection module, configured to obtain a dialogue context of a user query;
[0035] a first filtering module, configured to obtain a plurality of candidate dialogues according to the dialogue context;
[0036] a second filtering module, configured to select, from the plurality of candidate dialogues, a candidate dialogue that is most matched with the dialogue context as a reply dialogue;
[0037] a response determination module, configured to determine a response to the user query according to the reply dialogue.
[0038] Optionally, the second filtering module comprises:
[0039] a semantic similarity calculation unit, configured to calculate a semantic similarity between the dialogue context and the plurality of candidate dialogues;
[0040] a matching degree calculation unit, configured to calculate a matching degree between the dialogue context and responses of the plurality of candidate dialogues;
[0041] The reply dialogue determination unit is configured to select a most matched candidate dialogue as a reply dialogue according to the semantic similarity and the matching degree.
[0042] Optionally, the semantic similarity calculation unit comprises:
[0043] The dialogue context and the plurality of candidate dialogues are input into a trained first model, and the semantic similarity between the dialogue context and the plurality of candidate dialogues is calculated by the first model.
[0044] The first model performs the following operations:
[0045] The words in the constituent sentences in the dialogue context are represented as a plurality of first word vectors.
[0046] The words in the constituent sentences in the candidate dialogues are represented as a plurality of second word vectors.
[0047] The semantic similarity is calculated according to the plurality of first word vectors and the plurality of second word vectors.
[0048] Optionally, the calculation of the semantic similarity according to the plurality of first word vectors and the plurality of second word vectors comprises:
[0049] A cross-attention operation is performed on the plurality of first word vectors and the plurality of second word vectors to obtain a first matrix.
[0050] For the plurality of first word vectors and the plurality of second word vectors, a self-attention operation is performed first and then a cross-attention operation is performed to obtain a second matrix.
[0051] The first matrix and the second matrix are stacked to obtain a matrix which is input into a preset model, and matching features are extracted by the preset model and the extracted features are unfolded into a plurality of one-dimensional vectors.
[0052] A first vector representing the semantic similarity is calculated based on the plurality of one-dimensional vectors using a graph attention network and an attention mechanism with role information.
[0053] Optionally, the selection of the most matched candidate dialogue as the reply dialogue according to the semantic similarity and the matching degree comprises:
[0054] The scores of the plurality of candidate dialogues are calculated according to the semantic similarity and the matching degree.
[0055] The candidate dialogue with the highest score is selected as the reply dialogue.
[0056] Optionally, the calculation of the scores of the plurality of candidate dialogues according to the semantic similarity and the matching degree comprises:
[0057] After the first vector representing the semantic similarity and the second vector representing the matching degree are modeled by a first multi-layer perceptron, a score is calculated by a second multi-layer perceptron.
[0058] Optionally, the obtaining the plurality of candidate dialogues according to the dialogue context comprises:
[0059] The plurality of candidate dialogues are filtered from a historical dialogue dataset, each piece of data in the historical dialogue dataset comprising at least one round of dialogue.
[0060] In a third aspect, an electronic device is provided, comprising a memory and a processor, the memory further storing computer instructions executable by the processor, the computer instructions being executed to implement the dialogue method of any of the preceding aspects.
[0061] In a fourth aspect, a computer readable medium is provided, the computer readable medium storing computer instructions executable by an electronic device, the computer instructions being executed to implement the dialogue method of any of the preceding aspects.
[0062] The embodiments of the present disclosure select the candidate dialogue that is most matched to the dialogue context from the plurality of candidate dialogues as the reply dialogue, so that the reply obtained is more accurate. Further, the embodiments of the present disclosure combine the semantic similarity between the dialogue context and the plurality of candidate dialogues and the matching degree between the dialogue context and each reply of the plurality of candidate dialogues to determine the reply, rather than relying only on the matching degree between the dialogue context and each reply of the plurality of candidate dialogues, so that the final reply obtained is more accurate. BRIEF DESCRIPTION OF DRAWINGS
[0063] The above and other objects, features and advantages of the present disclosure will become more apparent from the following description when taken in conjunction with the accompanying drawings, in which:
[0064] Figure 1 is a schematic diagram of a prior art retrieval-based dialogue system;
[0065] Figure 2 is a schematic diagram of application deployment of a dialogue system;
[0066] Figure 3 is an example diagram of an online customer service;
[0067] Figure 4 is a schematic diagram of a dialogue system provided by the embodiments of the present disclosure;
[0068] Figure 5 is an architecture diagram of a deep learning model used by the embodiments of the present disclosure;
[0069] Figure 6 isFigure 5 Detailed schematic diagram of the representation layer and interaction layer in the diagram;
[0070] Figure 7 This is a flowchart of the dialogue method provided in the embodiments of this disclosure;
[0071] Figure 8 yes Figure 7 A more detailed flowchart of step S703 is shown below;
[0072] Figure 9 This is a structural diagram of an electronic device used in embodiments of this disclosure. Detailed Implementation
[0073] The present disclosure is described below based on embodiments, but it is not limited to these embodiments. In the detailed description of the present disclosure below, certain specific details are described in detail. Those skilled in the art will fully understand the present disclosure even without these details. To avoid obscuring the substance of the present disclosure, well-known methods, processes, and procedures are not described in detail. Furthermore, the accompanying drawings are not necessarily drawn to scale.
[0074] Figure 2 This is a deployment diagram of the dialogue system. For example... Figure 2 As shown, various terminals 201 establish communication with server 202 through network 203. Terminal 201 is various electronic devices employing computer systems, such as personal computers, mobile phones, laptops, tablets, etc. Network 203 can be based on one or a combination of various communication technologies implemented through signal exchange, including but not limited to wired technology using electrical and / or optical transmission cables, and wireless technology using infrared, radio frequency, and / or other forms. In different application scenarios, network 203 can be the Internet, a wide area network (WAN), or a local area network (LAN), such as a company's private network. Network 203 can also be a wired network or a wireless network. Server 202 can be a physical server or a cloud server. A cloud server utilizes virtualization technology to integrate the hardware and software resources of a physical server, thereby providing computing power, storage capacity, or various application services based on user needs. Specifically, in this disclosure, server 202 deploys and runs a dialog system that responds to user queries from various terminals.
[0075] Combination Figure 3The illustrated example of online customer service continues to illustrate the retrieval dialogue system. As shown in the figure, the display screen of terminal 201 displays a chat window 21. In chat window 21, when a sentence input by a user is received, one or more rounds of dialogue between the user and the customer service have already existed before the sentence. In the figure, the sentence and the round of dialogue before the sentence are represented by a QC, which is an example of the dialogue context of the user query referred to herein. Server 202 stores a historical dialogue dataset. Historical dialogue dataset 22 is a dataset sorted out based on original dialogue records. In actual operation, a batch of original dialogue records can be collected first, each of which records a complete process of dialogue between the customer service and the customer, usually including multiple rounds of dialogue, and then the original dialogue records are filtered to remove miscellaneous information, and then are cut and composed into a piece of data of the historical dialogue dataset. Optionally, each piece of data of the historical dialogue dataset includes a question sentence initiated by the customer and at least one round of dialogue before the question sentence.
[0076] Referring to the figure, the dialogue system of server 202 receives the dialogue context, finds multiple matched candidate dialogues DS1 to DSn from historical dialogue dataset 22, and then determines a final response according to responses CR1 to CRn. The final response is provided to terminal 201. If the customer service system is an intelligent customer service (without manual customer service), the final response will be directly displayed in chat window 21, and if the customer service is manual customer service, the final response can be provided as a recommended response to the manual customer service, which can modify and process the recommended response and push it to chat window 21.
[0077] In combination Figure 1 As shown, the input of the CRM model is the dialogue context QC and the responses CR1 to CRn (obtained by the coarse-grained screening step of S10), and then the CRM model determines the final response based on the matching degree of the dialogue context QC and the responses CR1 to CRn, and finally obtains the response CR1. However, in the process of calculating the matching degree, the CRM model does not consider the candidate dialogues DS1 to DSn corresponding to the responses CR1 to CRn, so the response CR1 obtained in this way is not accurate enough. As can be seen from the figure, the customer asks about the delivery time of EMS express, and CR1 is not for the delivery time of EMS express.
[0078] Figure 4 is a schematic diagram of a dialogue system provided by an embodiment of the disclosure. As shown in the figure, the dialogue system includes a dialogue collection module 401, a first screening module 402, a second screening module 403, and a response determination module 404.
[0079] The dialogue acquisition module 401 is used to obtain the dialogue context of the user query. This dialogue context includes the current user-input query (typically a question) and at least one round of dialogue preceding this query. The dialogue acquisition module 401 outputs the obtained dialogue context to the first filtering module 402.
[0080] The first filtering module 402 performs coarse-grained filtering. Specifically, it filters the entire historical dialogue dataset using the dialogue context, selecting multiple candidate dialogues 1-n. This operation can be implemented using conventional methods such as TF-IDF (term frequency–inverse document frequency). This operation is efficient and fast, but its accuracy is relatively low. The first filtering module 402 outputs the multiple candidate dialogues 1-n to the second filtering module 403.
[0081] The second filtering module 403 is used to select the candidate dialogue that best matches the dialogue context from multiple candidate dialogues as the response dialogue.
[0082] The response determination module 404 determines the response to the user's query based on the reply dialogue. If it is an intelligent customer service, the response to the reply dialogue can be directly output as the response to the current user's query on the display screen. If it is a human customer service, the human customer service will modify the response before outputting it.
[0083] In some embodiments, the second filtering module 403 includes a semantic similarity calculation unit, a matching degree calculation unit, and a response dialogue determination unit. The semantic similarity calculation unit calculates the semantic similarity between the dialogue context and multiple candidate dialogues, the matching degree calculation unit calculates the matching degree between the dialogue context and each response of the multiple candidate dialogues, and the response dialogue determination unit combines the two to determine the response dialogue.
[0084] Compared with existing technologies, this embodiment not only calculates the semantic similarity between the dialogue context and multiple candidate dialogues, but also calculates the matching degree between the dialogue context and each response of the multiple candidate dialogues. Based on both, the final response is determined, thus this embodiment can obtain a more accurate final response.
[0085] Furthermore, such as Figure 5 As shown, the second screening module 403 uses a trained deep learning model 500 to calculate the semantic similarity between the dialogue context and multiple candidate dialogues, and simultaneously calculates the matching degree between the dialogue context and the responses of multiple candidate dialogues. Based on the semantic similarity and matching degree, the most matching candidate dialogue is selected as the response dialogue.
[0086] Figure 5 This is an architecture diagram of a deep learning model used in an embodiment of this disclosure. Figure 6yes Figure 5 Detailed schematic diagram of the representation layer and interaction layer in the model.
[0087] For ease of explanation, we will consider this deep learning model 500 as a combination of the CCM model, the CRM model, and the ensemble model.
[0088] The CCM Model 501 takes a dialogue context and multiple candidate dialogues as input. It calculates the semantic similarity between the dialogue context and each candidate dialogue. In simpler terms, it determines how similar the content described by the dialogue context and the candidate dialogues is. If the dialogue context has a high semantic similarity to a candidate dialogue, the probability that the response of that candidate dialogue will become the response of the dialogue context is relatively high.
[0089] CRM Model 502 assesses the degree of matching between the dialogue context and the various responses in a candidate dialogue; in simpler terms, it determines whether each response in a candidate dialogue adequately addresses the dialogue context. CRM Model 502 and... Figure 1 The CRM model is similar to that in [the context of the text].
[0090] The integrated model 503 determines the most matching candidate dialogue as the response dialogue based on the outputs of the CCM model 501 and the CRM model 502.
[0091] As shown in the figure, the CCM model 501 includes a representation layer 5011, an interaction layer 5012, and an aggregation layer 5013.
[0092] Representation layer 5011 represents sentences as word vectors containing sentence information, using a Transformer network:
[0093]
[0094]
[0095] and Each represents the dialogue context u q The i-th statement and candidate dialogue u r The j-th utterance, where q indicates that the corresponding part belongs to the dialogue context, and r indicates that the corresponding part belongs to the candidate dialogue. represent Vector representation, represent The vector representation of the word vector, where R represents the real number space, t is the number of words in the sentence, and d is the dimension of the word vector.
[0096] refer to Figure 6 As shown, first according to and The input of the Transformer network is Q, K and V, representing the sequence of query vectors, the sequence of key vectors and the sequence of value vectors, respectively. They are first passed through an attention layer (Attention), then through an addition and normalization operation (ADD&Norm) to obtain a new representation, and then through a feedforward neural network (FeedForward) and an addition and normalization operation (ADD&Norm) to obtain the corresponding vector expression.
[0097] Reference Figure 5 As shown, the representation layer 5011 outputs the vector expression to the interaction layer 5012. After obtaining the vector expression, the interaction layer 5012 performs the following steps.
[0098] Step S1 is used to perform cross attention operation according to the vector expression of the dialogue context and the vector expression of the candidate dialogue, and obtain a result matrix M. Specifically, directly according to the output of the representation layer The cross attention operation is performed to obtain a matrix M i,j ∈R t*t , wherein M i,j The element in the a-th row and the b-th column of M
[0099]
[0100] wherein, represents the a-th row element of , and the superscript T represents the transpose operation
[0101] Step S2 is used to perform self-attention operation and then cross attention operation according to the vector expression of the dialogue context and the vector expression of the candidate dialogue, and obtain a result structure M'. That is, first perform self-attention operation on , and specifically use a self-attention function f att to perform the following calculation to obtain and
[0102]
[0103]
[0104] Then, based on and perform cross attention operation, and a new matrix M' is obtained i,j ∈R t*t , wherein M' i,j The element in the a-th row and the b-th column of M'is calculated as follows:
[0105]
[0106] After obtaining M, M' in step S3, the corresponding elements are stacked:
[0107] F i,j = f stack (M i,j , M' i,j ), where F i,j ∈ R 2*t*t (7)
[0108] Step S4 is to use a 2D CNN model to extract matching features, and to expand the extracted features to multiple one-dimensional vectors:
[0109] S i,j = f flatten (f CNN (F i,j )) (8)
[0110] where f CNN is the function expression corresponding to the 2D CNN model. f flatten represents the flattening operation, which flattens the output of f CNN into a one-dimensional vector.
[0111] The above steps can refer to Figure 5 On the diagram, the interaction layer 5012 obtains and according to the above steps, and then obtains M i,j and M' i,j , and then inputs M i,j and M' i,j to a CNN model to obtain S i,j .
[0112] The aggregation layer 5013 receives the one-dimensional vector S i,j from the interaction layer 5012. Where i represents the i-th sentence of the dialogue context, and j represents the j-th sentence (utterance) of the candidate dialogue, so S i,j represents the matching relationship vector of the i-th sentence of the dialogue context and the j-th sentence of the candidate dialogue. At this time, since is a matrix with vector elements, traditional methods cannot well encode this form of tensor. Here we use a graph network to handle this problem. We consider S to be an undirected graph, and each element of S corresponds to a node of the undirected graph. We directly use a graph attention network (Graph Attention Network) to process, which can be represented as:
[0113] A = f gat (S) (9)
[0114] where f gat (S) is a function of graph attention network representation.
[0115] A is then integrated by a role-aware attention mechanism. It is denoted as
[0116]
[0117] where E is a role information matrix, E i ,E j ,E a ,E b denote the i,j,a,b-th row of the role information matrix E respectively. A i,j is the element of the i-th row and j-th column of the output A of the graph attention network mentioned above. A a,b is the element of the a-th row and b-th column of the output A of the graph attention network mentioned above. MLP denotes a multi-layer perceptron, and exp denotes an exponential function.
[0118] The semantic similarity between the dialogue context and the multiple candidate dialogues is finally obtained, i.e., as shown in the following formula.
[0119] R cc = f cc (query's context, candicate's session) = A r (11)
[0120] where query's context denotes the dialogue context, and candicate's session denotes a candidate dialogue.
[0121] The deep interaction layer is used in the CRM model 402. The deep interaction layer utilizes deep-level interaction and can fully capture the semantic relationship between the dialogue context and the candidate response. The deep interaction layer is proposed and described in detail in the paper One Time of Interaction May Not Be Enough: Go Deep with an Interaction-over-Interaction Network for Response Selection in Dialogues, which will not be described here. The final CRM model 402 can be represented as:
[0122] R cr = fcr (query's context, response) (12)
[0123] wherein query's context represents the dialogue context and response represents the response.
[0124] The integrated model 503 obtains the vector representation R of the CCM model 501 and the CRM model 502 cc cr Then, as shown in the figure, a multilayer perceptron is used to model the relationship between the two, that is, as follows:
[0125] γ = sigmoid(MLP g (R cc , R cr )) (12)
[0126] wherein the multilayer perceptron (MLP) is a feedforward artificial neural network model that maps multiple input data sets to a single output data set, and the sigmoid function is an activation function in the model that maps variables to a set interval, for example, to the interval [0, 1].
[0127] In addition, the following formula is obtained:
[0128] R cs = γR cc + (1-γ)R cr (13)
[0129] R cs is obtained, and then another multilayer perceptron (MLP) is passed to obtain the final score, which represents the score.
[0130] score = MLP2(R cs ) (14)
[0131] Corresponding to the above embodiment, as shown in the figure, the present disclosure provides a dialogue method, comprising the following steps. Figure 7
[0132] In step S701, the dialogue context of the user query is obtained.
[0133] Step S701 is to take the query statement input by the current user and at least one round of dialogue before the statement as the dialogue context. Optionally, all dialogues before the query statement can be placed in the dialogue context.
[0134] In step S702, a plurality of candidate dialogues are obtained according to the dialogue context.
[0135] Step S702 is the coarse screening step. It compares the dialogue context with multiple existing candidate dialogues in the dataset to filter out multiple candidate dialogues from the historical dialogue dataset.
[0136] A historical dialogue dataset is a collection of dialogue sessions. Each dialogue session includes at least a user-input query and one or more previous rounds of dialogue. The user-input query typically contains a question. To obtain a historical dialogue dataset, multiple historical dialogue records need to be collected, each representing a complete communication record. Then, each historical dialogue record is segmented into dialogues.
[0137] Candidate dialogues are those that are related to the dialogue context; for example, both the candidate dialogue and the dialogue context may mention a product brand. To avoid the coarse screening process from filtering out multiple segments that are not semantically related to the dialogue context, most candidate dialogues can be filtered out using keywords.
[0138] In step S703, the candidate dialogue that best matches the dialogue context is selected from multiple candidate dialogues as the response dialogue.
[0139] In some embodiments, such as Figure 8 As shown, this step includes steps S7031-S7033. Step S7031 calculates the semantic similarity between the dialogue context and multiple candidate dialogues. Step S7032 calculates the matching degree between the dialogue context and the responses of multiple candidate dialogues. S7033 selects the most matching candidate dialogue as the response dialogue based on semantic similarity and matching degree.
[0140] Further, step S7033 includes: calculating the scores of multiple candidate dialogues based on semantic similarity and matching degree; and selecting the candidate dialogue with the highest score as the response dialogue.
[0141] Furthermore, such as Figure 8 The steps shown are all performed using a deep learning model. Regarding deep learning models, the above text, combined with... Figures 5-6 As already described in detail, it will not be repeated here.
[0142] In step S704, the response to the user's query is determined based on the response dialogue. Specifically, the response to the response dialogue can be directly used as the response to the user's query, or the response to the response dialogue can be modified and used as the response to the user's query.
[0143] In summary, compared with the prior art, the embodiments of this disclosure take into account both the semantic similarity between the dialogue context and multiple candidate dialogues and the matching degree between the dialogue context and each response of the multiple candidate dialogues to determine the final response, thereby improving the accuracy of the response.
[0144] The electronic device 90 according to the embodiments of the present disclosure can include a processor 901, a memory 902, an input / output device 903, and other hardware 904. The memory 902 can include a volatile memory (e.g., a random access memory (RAM)) and / or a non-volatile memory (e.g., a read-only memory (ROM)). The input / output device 903 can include a display, a keyboard, a mouse, a network interface, and / or other input / output devices. The processor 901 can include one or more processors (e.g., a central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a graphics processing unit (GPU), etc.). The processor 901 can be configured to execute instructions stored in the memory 902. The other hardware 904 can include a storage device (e.g., a hard disk drive, a solid state drive, etc.), a communication device (e.g., a network interface card, etc.), and / or other hardware. Figure 7 The bus 905 can include an address bus, a data bus, and / or a control bus in compliance with a bus standard, such as an Industry Standard Architecture (ISA) bus, Peripheral Component Interconnect (PCI) bus, Extended Industry Standard Architecture (EISA) bus, etc. The bus 905 can be implemented as a single bus or a combination of buses, and can be implemented as a single bus or a combination of buses.
[0145] The memory 902 can store instructions and / or data. The processor 901 can read the instructions and / or data from the memory 902 and execute the instructions. The instructions can include instructions for obtaining a dialog context of a user query, obtaining a plurality of candidate dialogs according to the dialog context, selecting a candidate dialog that is most matched with the dialog context from the plurality of candidate dialogs as a reply dialog, and determining a response to the user query according to the reply dialog.
[0146] Those skilled in the art can understand that the present disclosure can be implemented as a system, a method, and a computer program product. Therefore, the present disclosure can be embodied in a form of a complete hardware, a complete software (including firmware, resident software, microcode), and a combination of software and hardware. In addition, in some embodiments, the present disclosure can also be embodied in a form of a computer program product in one or more computer readable media including computer readable program codes.
[0147] Any combination of one or more computer readable medium can be utilized. The computer readable medium can be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a computer readable storage medium can include, but are not limited to, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In this context, a computer readable storage medium can be any tangible medium that can contain or store a program for use by or in connection with a processing system, apparatus, or device.
[0148] A computer readable signal medium can include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated signal can take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium can be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
[0149] Program code embodied on a computer readable medium can be transmitted using any appropriate medium, including but not limited to wireless, wire line, optical fiber cable, RF, etc., and any suitable combination of the foregoing.
[0150] Computer program code for carrying out embodiments of the present disclosure can be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C++, and conventional procedural programming languages, such as the C programming language. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer, or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider). In an embodiment, multiple computing devices can be used, for example, client and server. Data can be stored on or transmitted across some or all of the aforementioned computer readable medium and computer readable storage media and can include any suitable data in one example, the database can include cookies and associated contextual data. In another example, the database can include cookies and associated contextual data.
[0151] The above merely provides preferred embodiments of the present disclosure, and is not used to limit the present disclosure. For those skilled in the art, the present disclosure can have various modifications and changes. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present disclosure shall fall into the protective scope of the present disclosure.
Claims
1. A dialogue method, comprising: obtaining a dialogue context of a user query; obtaining a plurality of candidate dialogues according to the dialogue context; selecting a candidate dialogue that is most matched with the dialogue context as a reply dialogue from the plurality of candidate dialogues; determining a response to the user query according to the reply dialogue; wherein the selecting a candidate dialogue that is most matched with the dialogue context as a reply dialogue from the plurality of candidate dialogues comprises: calculating semantic similarity based on the dialogue context and the candidate dialogue using a graph attention network and an attention mechanism with role information, wherein the attention mechanism with role information is used to calculate semantic similarity based on a role information matrix and an output matrix of the graph attention network to obtain the semantic similarity, the role information matrix is used to represent role information corresponding to constituent sentences in the dialogue context and role information corresponding to constituent sentences in the candidate dialogue, and the output matrix of the graph attention network is obtained by inputting the dialogue context and the candidate dialogue into the graph attention network; calculating a matching degree between the dialogue context and responses of the plurality of candidate dialogues; selecting a candidate dialogue that is most matched with the dialogue context as a reply dialogue according to the semantic similarity and the matching degree.
2. The dialog method according to claim 1, wherein, The calculating semantic similarity based on the dialogue context and the candidate dialogue using a graph attention network and an attention mechanism with role information comprises: inputting the dialogue context and the plurality of candidate dialogues into a trained first model to calculate semantic similarity between the dialogue context and the plurality of candidate dialogues by the first model; wherein the first model performs the following operations: representing words in constituent sentences in the dialogue context as a plurality of first word vectors; representing words in constituent sentences in the candidate dialogue as a plurality of second word vectors; obtaining a plurality of one-dimensional vectors according to the plurality of first word vectors and the plurality of second word vectors; calculating a first vector representing the semantic similarity based on the plurality of one-dimensional vectors using the graph attention network and the attention mechanism with role information.
3. The dialog method according to claim 2, wherein, The obtaining a plurality of one-dimensional vectors according to the plurality of first word vectors and the plurality of second word vectors comprises: performing cross-attention operations on the plurality of first word vectors and the plurality of second word vectors to obtain a first matrix; performing self-attention operations and then cross-attention operations on the plurality of first word vectors and the plurality of second word vectors to obtain a second matrix; inputting a matrix obtained by stacking the first matrix and the second matrix into a preset model to extract matching features and expand the extracted features into the plurality of one-dimensional vectors by the preset model.
4. The dialog method according to any one of claims 1-3, wherein, The selecting a candidate dialogue that is most matched with the dialogue context as a reply dialogue according to the semantic similarity and the matching degree comprises: calculating scores of the plurality of candidate dialogues according to the semantic similarity and the matching degree; selecting a candidate dialogue with the highest score as a reply dialogue.
5. The dialog method according to claim 4, wherein, The calculating scores of the plurality of candidate dialogues according to the semantic similarity and the matching degree comprises: After modeling the first vector representing the semantic similarity and the second vector representing the matching degree through a first multi-layer perceptron, a score is calculated using a second multi-layer perceptron.
6. The dialogue method according to claim 1, wherein, The obtaining of the plurality of candidate dialogues according to the dialogue context comprises: The plurality of candidate dialogues are filtered from a historical dialogue dataset according to the dialogue context.
7. The dialog method according to claim 6, wherein, The plurality of candidate dialogues are filtered from the historical dialogue dataset using a TF-IDF algorithm.
8. A dialogue system, comprising: a dialogue collection module configured to obtain a dialogue context of a user query; a first filtering module configured to obtain a plurality of candidate dialogues according to the dialogue context; a second filtering module configured to select, from the plurality of candidate dialogues, a candidate dialogue that is most matched to the dialogue context as a reply dialogue; a response determination module configured to determine a response to the user query according to the reply dialogue; The second filtering module comprises: a semantic similarity calculation unit configured to calculate a semantic similarity based on the dialogue context and the candidate dialogue using a graph attention network and an attention mechanism with role information, wherein the attention mechanism with role information is configured to calculate the semantic similarity based on a role information matrix and an output matrix of the graph attention network to obtain the semantic similarity, the role information matrix is configured to represent role information corresponding to constituent sentences in the dialogue context and role information corresponding to constituent sentences in the candidate dialogue, and the output matrix of the graph attention network is obtained by inputting the dialogue context and the candidate dialogue into the graph attention network; a matching degree calculation unit configured to calculate a matching degree between the dialogue context and responses of the plurality of candidate dialogues; a reply dialogue determination unit configured to select, as the reply dialogue, a candidate dialogue that is most matched according to the semantic similarity and the matching degree.
9. The dialog system of claim 8, wherein, The semantic similarity calculation unit comprises: inputting the dialogue context and the plurality of candidate dialogues into a trained first model to calculate a semantic similarity between the dialogue context and the plurality of candidate dialogues by the first model; The first model performs the following operations: representing words in constituent sentences in the dialogue context as a plurality of first word vectors; representing words in constituent sentences in the candidate dialogue as a plurality of second word vectors; obtaining a plurality of one-dimensional vectors according to the plurality of first word vectors and the plurality of second word vectors; calculating a first vector representing the semantic similarity based on the plurality of one-dimensional vectors using the graph attention network and the attention mechanism with role information.
10. The dialog system of claim 9, wherein, The obtaining of the plurality of one-dimensional vectors according to the plurality of first word vectors and the plurality of second word vectors comprises: performing a cross-attention operation on the plurality of first word vectors and the plurality of second word vectors to obtain a first matrix; performing a self-attention operation and then a cross-attention operation on the plurality of first word vectors and the plurality of second word vectors to obtain a second matrix; The first matrix and the second matrix are stacked to obtain a matrix, and the matrix is input into a preset model to extract matching features and expand the extracted features into the plurality of one-dimensional vectors.
11. The dialog system according to any one of claims 8-10, wherein, The selecting the most matching candidate dialogue as the reply dialogue according to the semantic similarity and the matching degree comprises: calculating scores of the plurality of candidate dialogues according to the semantic similarity and the matching degree; selecting the candidate dialogue with the highest score as the reply dialogue.
12. The dialog system of claim 11, wherein, The calculating scores of the plurality of candidate dialogues according to the semantic similarity and the matching degree comprises: after modeling the first vector representing the semantic similarity and the second vector representing the matching degree by a first multi-layer perceptron, calculating the scores by a second multi-layer perceptron.
13. The dialog system of claim 8, wherein, The obtaining the plurality of candidate dialogues according to the dialogue context comprises: filtering the plurality of candidate dialogues from a historical dialogue dataset according to the dialogue context. 14.An electronic device comprising a memory and a processor, wherein the memory further stores computer instructions executable by the processor, and the computer instructions, when executed, implement the dialogue method according to any one of claims 1 to 7. 15.A computer readable medium storing computer instructions executable by an electronic device, and the computer instructions, when executed, implement the dialogue method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Multi-round dialogue reply selection method and system based on QA knowledge base reasoning
CN110096567A