A language processing method and system based on reply perception feedback mechanism
By introducing a reply perceptual feedback mechanism in a multi-round dialogue system, and adjusting background knowledge in real time, the problem of meaningless and incoherent responses in traditional systems is solved, and more accurate and relevant dialogue replies are achieved.
Patent Information
- Application Number
- CN202210049818.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-17
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2042-01-17
AI Technical Summary
The traditional multi-round dialogue system cannot effectively link the content of each round of dialogue, resulting in meaningless or incoherent responses, and the knowledge pre-selecting model cannot adjust the background knowledge during the reply generation process, which may refer to inappropriate knowledge, resulting in a reply error.
A response-aware feedback mechanism is introduced, and the correlation between the generated replies and selected background knowledge is dynamically adjusted to generate more accurate replies. After each reply word is generated, the mechanism uses perceptual feedback to correct the background knowledge to ensure that the reply is highly relevant to the conversation content.
Improve the accuracy and relevance of the responses, reduce the possibility of reply errors caused by errors in background knowledge selection, and make the responses generated by the dialogue system more meaningful and coherent.
Smart Images

Figure CN114548120B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing and dialogue systems, and in particular to a language processing method and system based on a reply perception feedback mechanism. Background Art
[0002] With the development of machine learning and artificial intelligence, dialogue systems have attracted a lot of attention from academia and industry in recent years. The dialogue system responds to questions raised by users in real time based on pre-learned response data. However, traditional multi-turn dialogue systems often generate meaningless and incoherent responses (such as "I don't know", "OK", etc.) because they cannot connect the content between each round of dialogue.
[0003] In order to improve the defects of traditional multi-round dialogue, background knowledge-based dialogue helps the system generate more appropriate responses by selecting corresponding background knowledge, so that the responses carry meaningful information. Zhang et al. proposed a knowledge pre-selection model at the 2019 International Joint Conference on Artificial Intelligence that uses historical dialogue context to predict the current background knowledge selection. The knowledge pre-selection model provides a "background-context" bidirectional attention mechanism to select the closest content and output a response based on this content.
[0004] In the above-mentioned multi-round dialogue model, the steps for generating dialogue responses in each round are as follows: based on background knowledge and dialogue context, background knowledge representation, dialogue context representation and context-aware background knowledge representation are obtained, wherein the background knowledge usually comes from an open source text library or from a search engine; based on the context-aware background knowledge representation, a background knowledge segment is selected; based on the selected background knowledge segment, response words are generated one by one until the content of this round of dialogue is generated.
[0005] However, although the above-mentioned knowledge pre-selection model enhances the knowledge selection ability, it cannot change the selected background knowledge during the response process, resulting in a high probability of referring to inappropriate background knowledge during the response generation process, thereby generating inappropriate responses. Summary of the invention
[0006] Based on this, the purpose of the present invention is to provide a language processing method and system based on a reply perception feedback mechanism, which has the advantage of dynamically adjusting the selected background knowledge during the reply generation process, thereby more accurately calculating the appropriate reply.
[0007] A language processing method based on a reply perception feedback mechanism comprises the following steps:
[0008] S10: Obtain background knowledge representation H based on background knowledge K and dialogue context X K , dialogue context representation HX and context-aware background knowledge representation W X→K ;
[0009] S20: Representing W based on context-aware background knowledge X→K , select a background knowledge segment h X→K ;
[0010] S30: Based on the background knowledge segment h X→K , generate reply words one by one, and after generating each reply word, use the perception feedback mechanism to X→K Make corrections to generate the next response word.
[0011] In the process of generating reply words, by introducing a reply-aware feedback mechanism, the relevance between the generated reply and the selected background knowledge is calculated in real time, and the selected background knowledge is corrected in real time to reduce the possibility of incorrect replies due to incorrect background knowledge selection, thereby providing more accurate responses.
[0012] Furthermore, the step S30 includes the following steps:
[0013] S31: Generate the first response word;
[0014] S32: Check whether the reply content of this round of dialogue has been generated; if the reply content of this round of dialogue has been generated, output the reply content of this round of dialogue, otherwise, execute step S33;
[0015] S33: Calculate the relevance between the generated response words and the background knowledge segment to obtain a perception result;
[0016] S34: Based on the perception result obtained in step S33, the background knowledge segment h X→K make corrections;
[0017] S35: Based on the background knowledge segment h corrected in step S34 X→K Generate the next reply word, and then return to step S32.
[0018] Furthermore, the calculation method of step S33 and step S34 is as follows:
[0019] In step S33, firstly, a set of t-1 (t≥2) generated reply words F={r1,…,r t-1}, the characterization sequence is calculated by the following formula
[0020]
[0021]
[0022] Among them, W f and b are trainable functions, e(r t-1 ) is r t-1 The word vector of
[0023] Next, according to the characterization sequence H F The last element of A feedback feature matrix G is calculated using the following formula:
[0024]
[0025] Among them, W X→K T is the context-aware background knowledge representation W X→K The transpose of .
[0026] Next, according to the feedback feature matrix G, a reply perception feedback weight vector Z is calculated by the following formula:
[0027] A=SelfAttn(W x→K )=softmax(W X→K T W X→K );
[0028] Z=(G⊙A)W X→K T ;
[0029] Next, in step S34, based on the response perception feedback weight vector Z, the background knowledge correction segment is obtained by the following formula:
[0030]
[0031] Among them, W g1 , W g2 and b are both trainable parameters; W g1 and W g2 are the response perception weight vector Z and the background knowledge segment h respectively. X→K Soft switch;
[0032] Next, the background knowledge correction segment As the background knowledge segment at this stage X→K , to correct the current background knowledge h X→K :
[0033]
[0034] The above reply feedback mechanism dynamically responds to the background knowledge segment h according to the generated reply words. X→KMake real-time modifications to ensure that the reply words are highly relevant to the current multi-round conversation.
[0035] Furthermore, in step S31, the first decoding state is calculated by the following formula:
[0036]
[0037]
[0038] in, is the initial decoding state; W s and b are trainable parameters; Represent the conversation context H X The last element of the reply; the initial end r0 of the reply is [BOS], indicating the beginning of reply generation, and e(r0) is the word vector of r0;
[0039] Next, according to the first decoding state Train the first decoding guide vector by the following formula
[0040]
[0041] Next, according to the first decoded steering vector The background knowledge attention is calculated by the following formula Thus, we can obtain the background knowledge representation that guides perception.
[0042]
[0043]
[0044] in, Belongs to the background knowledge representation H K ,
[0045] Next, according to the first decoded steering vector The conversation context attention is calculated using the following formula: So as to obtain the contextual representation of the guided perception dialogue
[0046]
[0047]
[0048] in, Belongs to the dialogue context representation H X ,
[0049] Next, based on the background knowledge representation that guides perception and guiding the perception of dialogue context The feature vector of the original vocabulary is obtained through the following formula
[0050]
[0051] Next, based on the original vocabulary feature vector The probability P of the first reply word r1 being generated from the original vocabulary is calculated by the following formula: V (r1):
[0052]
[0053] Among them, W vocab It represents the original vocabulary;
[0054] Next, according to the first decoded steering vector The probability P of the first reply word r1 being selected from the background knowledge K is calculated by the following formula: K (r1):
[0055]
[0056] Next, the probability P generated from the original vocabulary based on the first reply word r1 V (r1) and the probability P of selecting from the background knowledge K K (r1), the final word list probability distribution P(r1) is obtained through the following formula:
[0057] P(1)=p gen P V (r1)+(1-p gen ) K (r1),
[0058]
[0059] Among them, W gen and b are both trainable parameters, σ is the Softmax activation function; p gen is between P V (r1) and P K Trainable gating between (r1);
[0060] According to the calculated final word list probability distribution P(1), a word is selected to generate the first reply word r1.
[0061] Furthermore, in step S35, the tth reply word r is generated. tThe process is as follows: According to the previous reply word r t-1 , the tth decoding state is obtained by the following formula
[0062]
[0063] Among them, e(r t-1 ) is r t-1 The word vector representation of is the t-1th decoding state;
[0064] Next, according to the tth decoding state The tth decoding guide vector is trained by the following formula:
[0065]
[0066] Next, according to the t-th decoding guidance vector A background knowledge representation guiding perception is calculated by the following formula:
[0067]
[0068]
[0069] in, Belongs to the background knowledge representation H K ,
[0070] Next, according to the t-th decoding guidance vector A guided-aware dialogue context representation is calculated using the following formula
[0071]
[0072]
[0073] in, Belongs to the dialogue context representation H X ,
[0074] Next, based on the background knowledge representation that guides perception and guidance-aware dialogue context representation The original vocabulary feature vector is calculated by the following formula
[0075]
[0076] Next, according to the original vocabulary feature vector The response vocabulary r is calculated by the following formula t The probability P generated from the original vocabulary V (r t ):
[0077]
[0078] Next, according to the t-th decoding guidance vector Calculate the response vocabulary r t The probability P of selecting from the background knowledge K K (r t ):
[0079]
[0080] Next, according to the response word r t The probability P generated from the original vocabulary V (r t ) and the probability P of selecting from the background knowledge K K (r t ), the final word list probability distribution P(r t ):
[0081] P(r t )=p gen P V (r t )+(1-p gen ) K (r t ),
[0082]
[0083] According to the final word list probability distribution P(r t ), select a word to generate the reply word r t .
[0084] Furthermore, the step S10 includes the following steps:
[0085] S11: Use the BIGRU neural network model to represent and encode each element of the background knowledge K to obtain the background knowledge representation H K , and encode each element of the dialogue context X to obtain the dialogue context representation H X ;
[0086] S12: Representing the background knowledge H K Perform aggregation calculation to obtain the aggregated background knowledge representation H K , and the conversation context representation H XPerform aggregation calculation, and the aggregated conversation context representation H X ; Represent H based on the aggregated background knowledge K and the aggregated conversation context representation H X , calculate the matching matrix M, and then perform maximum pooling calculation on the matching matrix M to obtain the context-aware background knowledge representation W X→K .
[0087] The present invention also provides a language processing system based on a reply perception feedback mechanism, which is characterized by comprising a background knowledge and dialogue context perception module, a background knowledge segment selection module and a reply generation module, as well as a dialogue record library and a background knowledge segment library; the background knowledge and dialogue context perception module calls background knowledge K from the background text library and obtains background knowledge representation H K , and call the conversation context X from the conversation record library and obtain the conversation context representation H X , and obtain the context-aware background knowledge representation W X→K ; The background knowledge segment selection module represents the context-aware background knowledge W X→K , select a background knowledge segment h X→K , stored in the background knowledge segment library; the reply generation module is based on the background knowledge segment h stored in the background knowledge segment library X→K , generate reply words one by one, and after generating each reply word, use the perception feedback mechanism to X→K Make corrections to generate the next response word.
[0088] Furthermore, the reply generation module includes a first reply word generation submodule, a dialogue reply checking submodule, a reply word relevance calculation submodule, a background knowledge segment correction submodule, a next reply word generation submodule, and a current round of dialogue reply storage;
[0089] The first reply word generation submodule calls the background knowledge segment h of the background knowledge segment library X→K , calculate and obtain the first reply word, and store the first reply word in the reply storage of this round of dialogue; each time a reply word is added to the reply storage of this round of dialogue, the dialogue reply checking submodule calls all the reply words in the reply storage of this round of dialogue to check whether the reply content of this round of dialogue has been generated. If the reply content of this round of dialogue has been generated, output the reply dialogue, otherwise, transmit the generated reply word to the reply word relevance calculation submodule; the reply word relevance calculation submodule receives the generated reply word and calculates its relevance to the background knowledge segment h X→K The background knowledge segment correction submodule receives the perception result and corrects the background knowledge segment h X→KThe next reply word generation submodule calls the background knowledge segment h in the updated background knowledge segment library. X→K , generate a reply word, and store the newly generated reply word in the reply storage of this round of dialogue.
[0090] Furthermore, the reply word relevance calculation submodule and the background knowledge segment correction submodule perform the following calculations:
[0091] The reply word relevance calculation submodule calls the generated set of t-1 (t≥2) reply words F={r1,…,r t-1}, the characterization sequence is calculated by the following formula
[0092]
[0093]
[0094] Among them, W f and b are trainable functions, e(r t-1 ) is r t-1 The word vector of
[0095] Next, according to the characterization sequence H F The last element of A feedback feature matrix G is calculated using the following formula:
[0096]
[0097] Among them, W X→K T is the context-aware background knowledge representation W X→K The transpose of .
[0098] Next, according to the feedback feature matrix G, a reply perception feedback weight vector Z is calculated by the following formula:
[0099] A=SelfAttn(W X→K )=softmax(W X→K T W X→K );
[0100] Z=(G⊙A)W X→K T ;
[0101] The background knowledge segment correction submodule receives the response perception feedback weight vector Z and obtains the background knowledge correction segment by the following formula:
[0102]
[0103] Among them, W g1 , W g2 and b are both trainable parameters; W g1 and W g2 are the response perception weight vector Z and the background knowledge segment h respectively. X→K Soft switch;
[0104] Next, use background knowledge to correct the segment The content of the background knowledge segment library is replaced by the content of the background knowledge segment library as the current background knowledge segment h X→K , to correct the current background knowledge h X→K :
[0105]
[0106] Furthermore, the first reply word generation submodule performs the following calculation: First, the first decoding state is calculated according to the following formula:
[0107]
[0108]
[0109] in, is the initial decoding state; W s and b are trainable parameters; Represent the conversation context H X The last element of the reply; the initial end r0 of the reply is [BOS], indicating the beginning of reply generation, and e(r0) is the word vector of r0;
[0110] Next, according to the first decoding state Train the first decoding guide vector by the following formula
[0111]
[0112] Next, according to the first decoded steering vector The background knowledge attention is calculated by the following formula Thus, we can obtain the background knowledge representation that guides perception.
[0113]
[0114]
[0115] in, Belongs to the background knowledge representation HK ,
[0116] Next, according to the first decoded steering vector The conversation context attention is calculated using the following formula: So as to obtain the contextual representation of the guided perception dialogue
[0117]
[0118]
[0119] in, Belongs to the dialogue context representation H X ,
[0120] Next, based on the background knowledge representation that guides perception and guiding the perception of dialogue context The feature vector of the original vocabulary is obtained through the following formula
[0121]
[0122] Next, based on the original vocabulary feature vector The probability P of the first reply word r1 being generated from the original vocabulary is calculated by the following formula: V (r1):
[0123]
[0124] Among them, W vocab It represents the original vocabulary;
[0125] Next, according to the first decoded steering vector The probability P of the response word r1 being selected from the background knowledge K is calculated by the following formula: K (r1):
[0126]
[0127] Next, the probability P generated from the original vocabulary based on the first reply word r1 V (r1) and the probability P of selecting from the background knowledge K K (r1), the final word list probability distribution P(r1) is obtained through the following formula:
[0128] P(r1)=p gen P V (r1)+(1-p gen ) K(r1),
[0129]
[0130] Among them, W gen and b are both trainable parameters, σ is the Softmax activation function; p gen is between P V (r1) and P K Trainable gating between (r1);
[0131] According to the calculated final word list probability distribution P(r1), a word is selected to generate the first reply word r1, and the first reply word r1 is stored in the current round dialogue reply storage.
[0132] For better understanding and implementation, the present invention is described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0133] Figure 1 It is a flow chart of the language processing method based on the reply perception feedback mechanism of the present invention;
[0134] Figure 2 It is a structural diagram of the language processing system based on the reply perception feedback mechanism of the present invention. DETAILED DESCRIPTION
[0135] The language processing method based on the reply perception feedback mechanism of the present invention selects a background knowledge segment through context-aware background knowledge representation, generates reply words one by one according to the background knowledge segment, and after generating each reply word, uses the perception feedback mechanism to modify the background knowledge segment to generate the next reply word.
[0136] See also Figure 1 , which is a flow chart of the language processing method based on the reply perception feedback mechanism of the present invention. The language processing method based on the reply perception feedback mechanism is specifically as follows:
[0137] S10: Obtain background knowledge representation H based on background knowledge K and dialogue context X K , dialogue context representation H X and context-aware background knowledge representation W X→K ; The step S10 comprises the following steps:
[0138] S11: Use the BIGRU neural network model to represent and encode each element of the background knowledge K to obtain the background knowledge representation H K , and encode each element of the dialogue context X to obtain the dialogue context representation H X ;
[0139] Specifically, in step S11, background knowledge text K is obtained from the text library, where K = {k1, ..., k t ,…,k |K|}, |K| is the number of words in the background knowledge text; the current dialogue context is X, which represents the content of the current multi-round dialogue, X={x1,…,x t ,…,x |x|}, |X| is the number of words in the conversation context. The background knowledge text K and the conversation context X are encoded by a bidirectional GRU (Gated Recurrent Unit Network) respectively, and the corresponding background knowledge representation is obtained by the following formula: and dialogue context representation
[0140]
[0141]
[0142] in, is the encoded background knowledge text word k t , is the encoded conversation context word x t . e(k t ) and e(x t ) are the background knowledge text words k t The word embedding and the conversation context word x t Word embedding. Word embedding gives each word a high-dimensional feature value, making the natural language processing algorithm more efficient.
[0143] S12: Representing the background knowledge H K Perform aggregation calculation to obtain the aggregated background knowledge representation H K , and the conversation context representation H X Perform aggregation calculation, and the aggregated conversation context representation H X ; Represent H based on the aggregated background knowledge K and the aggregated conversation context representation H X , calculate the matching matrix M, and then perform maximum pooling calculation on the matching matrix M to obtain the context-aware background knowledge representation W X→K .
[0144] In step S12, the background knowledge representation H K Perform the following aggregation operations:
[0145]
[0146]
[0147] Among them, W l , W nl , W g and b are both trainable parameters, and σ is the Softmax (normalized exponential) function. K Each element in is related to the last element of the conversation context representation, i.e. Perform aggregation operations.
[0148] The conversation context is represented by the following formula: X To aggregate:
[0149]
[0150]
[0151] Next, we use the aggregated background knowledge to represent H K and the aggregated conversation context representation H X , a matching matrix M is calculated, and the calculation method of each element in the matching matrix M is as follows:
[0152]
[0153] in, W M1 and W M2 These are all trainable parameters.
[0154] The matching matrix M is used to measure the similarity between the background knowledge and the conversation context, calculate word weights using a word-level similarity matrix, and lay the foundation for obtaining the following context-aware background knowledge representation.
[0155] Context-aware background knowledge representation W X→K , is obtained by performing a maximum pooling operation on the matching matrix M along the X-axis direction, that is:
[0156]
[0157] The context-aware background knowledge representation W X→K , represents the attention weight of each word of the background knowledge based on the perception of the dialogue context X, so as to realize the feature capture corresponding to the background knowledge K and the dialogue context X.
[0158] Through the above steps S11 and S12, the context-aware background knowledge representation W is calculated. X→KAfter that, although the features corresponding to the background knowledge K and the dialogue context have been captured, there is still a lack of knowledge weight selection from a global perspective. To solve this problem, step S20 is then performed to select a piece of background knowledge with the highest relevance to the dialogue context from a global perspective by using a global knowledge selection mechanism.
[0159] S20: Representing W based on context-aware background knowledge X→K , select a background knowledge segment h X→K .
[0160] Specifically, in step S20, the context-aware background knowledge representation W is firstly X→K The sliding adjacent weights of are summed through a window of size n, and a context-aware background knowledge semantic unit weight vector is obtained through the following formula: and
[0161]
[0162] Next, the background knowledge representation H K and the last element of the conversation context representation Perform "n-size unfold and attention" operation to obtain semantic unit representation
[0163]
[0164]
[0165]
[0166] Among them, a i is between and The attention weight distribution between It also represents the corresponding background knowledge segment K T:T+n The semantic unit representation of .
[0167] At the end of step S20, according to and Using the Softmax function and dot product operation, a most relevant text is selected from the background knowledge, and the representation vector of the selected background segment is h X→K :
[0168]
[0169]
[0170] The above step S20 will use the attention mechanism to select the background knowledge segment h that is most relevant to the dialogue context from a global perspective. X→K , i.e. the background knowledge segment with the most attention. In step S30, the background knowledge segment h X→K As the background knowledge basis for generating reply words, after each reply word is generated, the generated reply words are relevance calculated, and the background knowledge segment h is calculated according to the calculation result. X→K Make corrections.
[0171] Although after global perception, a background knowledge segment h is selected X→K However, it is still impossible to guarantee that the background knowledge segment h X→K It is highly relevant to the question raised by the user. Therefore, a response perception feedback mechanism is needed to judge the background knowledge segment h according to the generated response. X→K Check whether it is appropriate and make timely modifications if it is inappropriate.
[0172] Step S30: Based on the background knowledge segment h X→K , generate reply words one by one, and after generating each reply word, use the perception feedback mechanism to X→K Make corrections to generate the next response word.
[0173] The step S30 specifically includes the following steps:
[0174] S31: Based on background knowledge segment h X→K , generate the first reply word;
[0175] In order to generate the first reply word, the decoding state is initialized as follows:
[0176]
[0177]
[0178] The reply initial end r0 is set to [BOS], indicating the start of reply generation. The above formula uses a linear layer to represent the last element of the context representation. and the selected background knowledge segment h X→K , calculate the initial decoding state W s and b are trainable parameters.
[0179] Next, based on the selected background knowledge segment h X→K and the initialization decoding state Train a decoding guidance vector
[0180]
[0181] Among them, e(r0) is the word vector of r0.
[0182] On this basis, the background knowledge attention is calculated by the following formula Obtaining background knowledge representation to guide perception
[0183]
[0184]
[0185] The context representation of the guided perception dialogue is calculated by an algorithm similar to the above formula
[0186]
[0187]
[0188] Obtaining background knowledge representation to guide perception And the dialogue of said guide perception is expressed in the following Then, a readout feature layer is deployed through the following formula to obtain the feature vector generated by the original vocabulary
[0189]
[0190] Next, based on the above feature vector The Softmax function is used to calculate the probability P of the reply word r1 being generated from the original word. V (r1):
[0191]
[0192] Among them, W vocab Represents the original vocabulary.
[0193] In addition, by constructing a background attention mechanism as follows, the probability P of the response word r1 being selected from the background knowledge K is calculated K (r1):
[0194]
[0195] Finally, combined with P V (r1) and P K (r1), the final word list probability distribution P(r1) is obtained through the following formula:
[0196] P(r1)=pgen P V (r1)+(1-p gen ) K (r1),
[0197]
[0198] Among them, W gen and b are trainable parameters, σ is the Softmax activation function; in particular, p gen In addition to indicating the probability of the response word being generated from the original vocabulary, it also serves as the v (r1) and P k Trainable gate between (r1).
[0199] According to the calculated final word list probability distribution P(1), a word is selected to generate the response word r1, and the step S31 is terminated.
[0200] S32: Check whether the response to this round of dialogue has been generated; if the response to this round of dialogue has been generated, output the dialogue, otherwise, execute step S33;
[0201] S33: Calculate the relevance between the generated response words and the background knowledge segment to obtain a perception result;
[0202] Specifically, in step S33, the generated t-1 (t≥2) reply words are obtained, that is, the set F = {r1, ..., r t-1}, calculate the semantic representation of the generated reply word set F, and calculate the semantic representation of the generated reply word set F and the background knowledge segment h X→K 's relevance.
[0203] First, a GRU network is used to calculate the representation sequence
[0204]
[0205] Among them, e(r t ) is r t The word vector representation of . Since the above GRU network requires an initialization unit The initialization unit is obtained by constructing the following linear layer
[0206]
[0207] Among them, W f and b are trainable parameters; H F The last element of As the semantic representation of F.
[0208] Calculate the semantic representation of F Then, a feedback feature matrix G is calculated to evaluate the relevance between the background knowledge K and the generated reply words F:
[0209]
[0210] Wherein, each element in the feedback feature matrix G represents the weight of the “background knowledge-generated reply” relationship corresponding to the element; W X→K T is the context-aware background knowledge representation W X→K The transposition of
[0211] Next, we represent the background knowledge W perceived in the conversation context X→K Build a self-attention layer to calculate the background knowledge representation W of the dialogue context awareness X→K The self-attention weight A is:
[0212] A=SelfAttn(W X→K )=softmax(W X→K T W X→K ).
[0213] Next, a reply perception feedback weight vector Z is calculated by matrix dot multiplication:
[0214] Z=(G⊙A)W X→K T .
[0215] It should be pointed out that when training the model of the above-mentioned reply-aware feedback mechanism, the real reply is used to calculate the reply-aware weight vector Z; during actual prediction, the reply words generated in the previous time step are used to calculate the reply-aware weight vector Z.
[0216] S34: Based on the perception result of S33, the background knowledge segment h X→K Make corrections to obtain background knowledge correction segments;
[0217]
[0218] Among them, W g1 , W g2 W and b are both trainable parameters. g1 and W g2 are the response perception weight vector Z and the selected background knowledge segment h respectively. X→K Soft switch.
[0219]
[0220] Correct the segment with the corrected background knowledge As the background knowledge segment at this stage X→K , to modify the current background knowledge segment h X→K .
[0221] S35: Generate the next reply word, and then return to step S32.
[0222] After the background knowledge segment is corrected in step S34, step S35 is executed.
[0223] In step S35, the decoding state is first updated by the following formula:
[0224]
[0225] The above formula is obtained by using the GRU network and the decoding state of the previous time step Get the updated decoding status
[0226] After the decoding state is updated, the decoding state after the update is and the revised background knowledge segment Generate the probability distribution of the tth reply word, that is, reply word r t The final word list probability distribution P( t ).
[0227] Since the final word list probability generation step for each reply word is similar to the word list probability distribution P(1) generation step for the first reply word, the following is the reply word r t Taking the generation process of as an example, the reply word generation step formula and algorithm are provided, and the principles and trainable parameters that have been described are no longer repeated.
[0228] The decoding guidance vector is calculated by the following formula
[0229]
[0230] A background knowledge representation guiding perception is calculated by the following formula:
[0231]
[0232]
[0233] A guided-aware dialogue context representation is calculated using the following formula
[0234]
[0235]
[0236] Deploy a readout feature layer to calculate the feature vector generated by the original vocabulary
[0237]
[0238] Calculate the response vocabulary r through the Softmax function t The probability p of generating from the original vocabulary V (r t ):
[0239]
[0240] Construct a background attention mechanism as follows to calculate the probability P of the response word r1 being selected from the background knowledge K K (r t ):
[0241]
[0242] Combined with P V (r t ) and P K (r t ), and the final word list probability distribution P( t ):
[0243] P(r t )=p gen P V (r t )+(1-p gen ) K (r t ),
[0244]
[0245] According to the calculated final word list probability distribution P(r t ), select a word to generate the reply word r t .
[0246] Get reply word r t Then, return to step S32 and execute the content of step S32.
[0247] Based on the "encoder-decoder" natural language processing structure, the present invention introduces a reply-aware feedback mechanism to flexibly modify the selected background knowledge segment in the decoding stage, thereby achieving further precision and diversification of the multi-round dialogue system. The reply-aware feedback mechanism of the present invention achieves better knowledge selection accuracy while minimizing the increase in the number of parameters.
[0248] Based on the above method, the present invention also provides a language processing system based on a reply perception feedback mechanism, such as Figure 2 As shown, it includes a background knowledge and dialogue context perception module, a background knowledge segment selection module and a response generation module, as well as a dialogue record library and a background knowledge segment library; the background knowledge and dialogue context perception module calls background knowledge K from the background text library and obtains background knowledge representation H K , and call the conversation context X from the conversation record library and obtain the conversation context representation H X , and obtain the context-aware background knowledge representation W X→K The background knowledge segment selection module executes the step S20, based on the context-aware background knowledge representation W X→K , select a background knowledge segment h X→K , stored in the background knowledge segment library; the reply generation module is based on the background knowledge segment h stored in the background knowledge segment library X→K , generate reply words one by one, and after generating each reply word, use the perception feedback mechanism to X→K Make corrections to generate the next response word. Corrected background knowledge segment Based on the revised background knowledge segment Continue to generate the next response word.
[0249] Furthermore, the encoding aggregation module includes a background knowledge representation encoding submodule, a dialog context representation encoding submodule, a background knowledge representation aggregation submodule, a dialog context representation aggregation submodule and a context-aware background knowledge representation acquisition submodule. The background knowledge representation encoding submodule acquires background knowledge K from a background text library, which may be an existing open source text library, a text collection from a search engine, or a locally created text library, etc. The background knowledge representation encoding operation in step S11 is performed according to the background knowledge K, and the background knowledge representation H is calculated by BIGRU. K The dialogue context representation encoding submodule retrieves the dialogue context X from the dialogue record, and calculates the dialogue context representation H by executing the dialogue context representation encoding formula in step S1. X ; The dialogue background knowledge representation aggregation submodule, based on the background knowledge representation H KExecute the background knowledge representation aggregation formula in step S12 to obtain the aggregated background knowledge representation H K The conversation context representation aggregation submodule executes the conversation context representation aggregation formula in step S12 to obtain the aggregated conversation context representation H X The context-aware background knowledge representation acquisition submodule executes the matching matrix formula and the maximum pooling formula in step S12 to obtain the context-aware background knowledge representation W X→K
[0250] The reply decoding module and the reply generation module include a first reply word generation submodule, a dialogue reply checking submodule, a reply word relevance calculation submodule, a background knowledge segment correction submodule, a next reply word generation submodule, and a current round of dialogue reply storage;
[0251] The first reply word generation submodule calls the background knowledge segment h of the background knowledge segment library X→K , execute the step S31, obtain the first reply word, and store the first reply word in the reply storage of this round of dialogue; each time a reply word is added to the reply storage of this round of dialogue, the dialogue reply checking submodule calls all the reply words in the reply storage of this round of dialogue, executes the step 32, checks whether the reply content of this round of dialogue is generated, if the reply content of this round of dialogue is generated, outputs the reply dialogue, otherwise, transmits the generated reply word to the reply word relevance calculation submodule; the reply word relevance calculation submodule receives the generated reply word, and executes the step S33 to calculate its relevance to the background knowledge segment h X→K The background knowledge segment correction submodule receives the perception result and executes the step S34 to correct the background knowledge segment h. X→K The next reply word generation submodule calls the background knowledge segment h in the updated background knowledge segment library. X→K , execute step 35, generate a reply word, and store the newly generated reply word in the reply storage of this round of dialogue.
[0252] The present invention introduces a reply perception mechanism to perform real-time calculations on the generated replies during the process of generating replies, thereby correcting the background knowledge segment. When the semantics of the current round of replies differs greatly from the semantics of the conversation context, the reply perception mechanism of the present invention can make timely modifications by correcting the background knowledge segment, thereby reducing the possibility of generating replies that are irrelevant to the conversation context, thereby providing more accurate replies. Compared to the prior art, the above-mentioned reply perception mechanism provides a more flexible language processing method and system, making the dialogue system closer to real-person replies, thereby providing users with an interactive experience that is closer to real life when used in intelligent dialogue systems such as customer service systems.
[0253] The above-mentioned embodiments only express several implementation methods of the present invention, and the description is relatively specific and detailed, but it cannot be understood as limiting the scope of the invention patent. It should be pointed out that for ordinary technicians in this field, several modifications and improvements can be made without departing from the concept of the present invention, and the present invention is also intended to include these modifications and modifications.
Claims
1. A language processing method based on reply perception feedback mechanism, It is characterized in that The steps include: S10: Obtain background knowledge representation H based on background knowledge K and dialogue context X K , dialogue context representation H X and context-aware background knowledge representation W X→K ; S20: Representing W based on context-aware background knowledge X→K , select a background knowledge segment h X→K ; S30: Based on the background knowledge segment h X→K , generate reply words one by one, and after generating each reply word, use the perception feedback mechanism to X→K Make corrections to generate the next response word; The step S30 comprises the following steps: S31: Generate the first response word; In step S31, the first decoding state is calculated by the following formula: in, is the initial decoding state; W s and b are trainable parameters; Represent the conversation context H X The last element of the initial terminal r 0 [BOS], indicating the start of reply generation, e(r 0 ) is r 0 The word vector of Next, according to the first decoding state Train the first decoding guide vector by the following formula Next, according to the first decoded steering vector The background knowledge attention is calculated by the following formula Thus, we can obtain the background knowledge representation that guides perception. in, Belongs to the background knowledge representation H K , Next, according to the first decoded steering vector The conversation context attention is calculated using the following formula: So as to obtain the contextual representation of the guided perception dialogue in, Belongs to the dialogue context representation H X , Next, based on the background knowledge representation that guides perception and guiding the perception of dialogue context The feature vector of the original vocabulary is obtained through the following formula Next, based on the original vocabulary feature vector Calculate the first reply word r by the following formula 1 The probability P generated from the original vocabulary V (r 1 ): Among them, W vocab It represents the original vocabulary; Next, according to the first decoded steering vector The first reply word r is calculated by the following formula: 1 The probability P of selecting from the background knowledge K K (r 1 ): Next, according to the first reply word r 1 The probability P generated from the original vocabulary V (r 1 ) and the probability P of selecting from the background knowledge K K (r 1 ), the final word list probability distribution P(r 1 ): P(r 1 )=p gen P V (r 1 )+(1-p gen )P K (r 1 ), Among them, W gen and n are both trainable parameters, σ is the Softmax activation function; p gen is between P V (r 1 ) and P K (r 1 ) between trainable gates; According to the calculated final word list probability distribution P(r 1 ), select a word to generate the first reply word r 1 ; S32: Check whether the reply content of this round of dialogue has been generated; if the reply content of this round of dialogue has been generated, output the reply content of this round of dialogue, otherwise, execute step S33; S33: Calculate the relevance between the generated response words and the background knowledge segment to obtain a perception result; S34: Based on the perception result obtained in step S33, the background knowledge segment h X→K make corrections; S35: Based on the background knowledge segment h corrected in step S34 X→K Generate the next reply word, and then return to step S32; The calculation method of step S33 and step S34 is as follows: In step S33, firstly, a set of t-1 (t≥2) generated reply words F={r 1 ,…,r t-1 }, the characterization sequence is calculated by the following formula Among them, W f and b are trainable functions, e(r t-1 ) is r t-1 The word vector of To characterize the sequence H F The initial element of Next, according to the characterization sequence H F The last element of A feedback feature matrix G is calculated using the following formula: Among them, W X→K T is the context-aware background knowledge representation W X→K The transpose of Next, according to the feedback feature matrix G, a reply perception feedback weight vector Z is calculated by the following formula: A=SelfAttn(W X→K )=softmax(W X→K T W X→K ); W=(G⊙A)W X→K T ; Next, in step S34, based on the response perception feedback weight vector Z, the background knowledge correction segment is obtained by the following formula: Among them, W g1 , W g2 and b are both trainable parameters; W g1 and W g2 are the response perception feedback weight vector Z and the background knowledge segment h respectively. X→K Soft switch; Next, the background knowledge correction segment As the background knowledge segment at this stage X→K , to modify the current background knowledge segment h X→K : In step S35, the tth reply word r is generated. t The process is as follows: According to the previous reply word r t-1 , the tth decoding state is obtained by the following formula Among them, e(r t-1 ) is r t-1 The word vector representation of is the t-1th decoding state; Next, according to the tth decoding state The tth decoding guide vector is trained by the following formula: Next, according to the t-th decoding guidance vector A background knowledge representation guiding perception is calculated by the following formula: in, Belongs to the background knowledge representation H K , Next, according to the t-th decoding guidance vector A guided-aware dialogue context representation is calculated using the following formula in, Belongs to the dialogue context representation H X , Next, based on the background knowledge representation that guides perception and guidance-aware dialogue context representation The original vocabulary feature vector is calculated by the following formula Next, according to the original vocabulary feature vector The response vocabulary r is calculated by the following formula t The probability P generated from the original vocabulary V (r t ): Next, according to the t-th decoding guidance vector Calculate the response vocabulary r t The probability P of selecting from the background knowledge K K (r t ): Next, according to the response word r t The probability P generated from the original vocabulary V (r t ) and the probability P of selecting from the background knowledge K K (r t ), the final word list probability distribution P(r t ): P(r t )=p gen P V (r t )+(1-p gen )P K (r t ), According to the final word list probability distribution P(r t ), select a word to generate the reply word r t .
2. The language processing method based on the reply perception feedback mechanism according to claim 1, Features: The step S10 includes the following steps: S11: Use the BIGRU neural network model to represent and encode each element of the background knowledge K to obtain the background knowledge representation H K , and encode each element of the dialogue context X to obtain the dialogue context representation H X ; S12: Representing the background knowledge H K Perform aggregation calculation to obtain the aggregated background knowledge representation H K , and the conversation context representation H X Perform aggregation calculation, and the aggregated conversation context representation H X ; Represent H based on the aggregated background knowledge K and the aggregated conversation context representation H X , calculate the matching matrix M, and then perform maximum pooling calculation on the matching matrix M to obtain the context-aware background knowledge representation W X→K .
3. A language processing system based on reply perception feedback mechanism, Features: The system comprises a background knowledge and dialogue context perception module, a background knowledge segment selection module and a response generation module, as well as a dialogue record library and a background knowledge segment library; the background knowledge and dialogue context perception module calls background knowledge K from the background text library and obtains background knowledge representation H K , and call the conversation context X from the conversation record library and obtain the conversation context representation H X , and obtain the context-aware background knowledge representation W X→K ; The background knowledge segment selection module represents the context-aware background knowledge W X→K , select a background knowledge segment h X→K , stored in the background knowledge segment library; the reply generation module is based on the background knowledge segment h stored in the background knowledge segment library X→K , generate reply words one by one, and after generating each reply word, use the perception feedback mechanism to X→K Make corrections to generate the next response word; The reply generation module includes a first reply word generation submodule, a dialogue reply checking submodule, a reply word relevance calculation submodule, a background knowledge segment correction submodule, a next reply word generation submodule, and a current round of dialogue reply storage; The first reply word generation submodule calls the background knowledge segment h of the background knowledge segment library X→K , calculate and obtain the first reply word, and store the first reply word in the reply storage for this round of dialogue; each time a reply word is added to the reply storage for this round of dialogue, the dialogue reply checking submodule calls all the reply words in the reply storage for this round of dialogue to check whether the reply content for this round of dialogue has been generated. If the reply content for this round of dialogue has been generated, output the reply dialogue, otherwise, transmit the generated reply word to the reply word relevance calculation submodule; the reply word relevance calculation submodule receives the generated reply word, and calculates its relevance to the background knowledge segment h. X→K The background knowledge segment correction submodule receives the perception result and corrects the background knowledge segment h X→K The next reply word generation submodule calls the background knowledge segment h in the updated background knowledge segment library. X→K , generate a reply word, and store the newly generated reply word in the reply storage of this round of dialogue; The reply word relevance calculation submodule and the background knowledge segment correction submodule perform the following calculations: The reply word relevance calculation submodule calls the generated set of t-1 (t≥2) reply words F={r 1 ,…,r t-1 }, the characterization sequence is calculated by the following formula Among them, W f and b are trainable functions, e(r t-1 ) is r t-1 The word vector of To characterize the sequence H F The initial element of Next, according to the characterization sequence H F The last element of A feedback feature matrix G is calculated using the following formula: Among them, W X→K T is the context-aware background knowledge representation W X→K The transpose of Next, according to the feedback feature matrix G, a reply perception feedback weight vector Z is calculated by the following formula: A=SelfAttn(W X→K )=softmax(W X→K T W X→K ); W=(G⊙A)W X→K T ; The background knowledge segment correction submodule receives the response perception feedback weight vector Z and obtains the background knowledge correction segment by the following formula: Among them, W g1 , W g2 and b are both trainable parameters; W g1 and W g2 are the response perception feedback weight vector Z and the background knowledge segment h respectively. X→K Soft switch; Next, use background knowledge to correct the segment The content of the background knowledge segment library is replaced by the content of the background knowledge segment library as the current background knowledge segment h K→K , to correct the current background knowledge h X→K : The first reply word generation submodule performs the following calculations: First, the first decoding state is calculated according to the following formula: in, is the initial decoding state; W s and b are trainable parameters; Represent the conversation context H X The last element of the initial terminal r 0 [BOS], indicating the start of reply generation, e(r 0 ) is r 0 The word vector of Next, according to the first decoding state Train the first decoding guide vector by the following formula Next, according to the first decoded steering vector The background knowledge attention is calculated by the following formula Thus, we can obtain the background knowledge representation that guides perception. in, Belongs to the background knowledge representation H K , Next, according to the first decoded steering vector The conversation context attention is calculated using the following formula: So as to obtain the contextual representation of the guided perception dialogue in, Belongs to the dialogue context representation H X , Next, based on the background knowledge representation that guides perception and guiding the perception of dialogue context The feature vector of the original vocabulary is obtained through the following formula Next, based on the original vocabulary feature vector Calculate the first reply word r by the following formula 1 The probability P generated from the original vocabulary V (r 1 ): Among them, W vocab It represents the original vocabulary; Next, according to the first decoded steering vector The reply word r is calculated by the following formula: 1 The probability P of selecting from the background knowledge K K (r 1 ): Next, according to the first reply word r 1 The probability P generated from the original vocabulary V (r 1 ) and the probability P of selecting from the background knowledge K K (r 1 ), the final word list probability distribution P(r 1 ): P(r 1 )=p gen P V (r 1 )+(1-p gen )P K (r 1 ), Among them, W gen and b are both trainable parameters, σ is the Softmax activation function; p gen is between P V (r 1 ) and P K (r 1 ) between trainable gates; According to the calculated final word list probability distribution P(r 1 ), select a word to generate the first reply word r 1 , and the first reply word r 1 Stored in the current round of dialogue reply storage.
