Training method of multi-turn dialogue model, multi-turn dialogue prediction method and device
By introducing weight augmentation and loss function optimization in the training of multi-turn dialogue models, and combining forward and backward training, the problem of low prediction accuracy of multi-turn dialogue models is solved, and the model's understanding and prediction ability of context is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- MASHANG CONSUMER FINANCE CO LTD
- Filing Date
- 2023-02-20
- Publication Date
- 2026-04-17
AI Technical Summary
In existing technologies, retrieval-based multi-turn dialogue models fail to effectively establish connections between multiple turns of the same dialogue during training, resulting in low prediction accuracy.
By introducing weighting techniques, the connection between the first training text and the first real result in the multi-turn dialogue model is strengthened. The model parameters are optimized through a loss function, and the model's ability to understand context is enhanced by combining forward and backward training methods.
It improves the accuracy of multi-turn dialogue models in prediction, realizes the connection between dialogue corpora in the same scenario, and enhances the model's ability to understand and reason about multi-turn dialogue texts.
Smart Images

Figure CN116127040B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of natural language processing, specifically relating to a training method for a multi-turn dialogue model, a multi-turn dialogue prediction method, and a device. Background Technology
[0002] With the development of technology, intelligent chatbots have begun to appear in various service venues, and multi-turn dialogue models have been widely used as a result.
[0003] Currently, related technologies often employ retrieval-based multi-turn dialogue models for dialogue prediction, enabling the selection of appropriate response statements from a database based on contextual information within multiple turns of the dialogue. However, these technologies often fail to establish connections between multiple turns of the same dialogue during training, resulting in low prediction accuracy for the trained multi-turn dialogue models. Summary of the Invention
[0004] This application provides a training method, a prediction method, and an apparatus for a multi-turn dialogue model, which improves the accuracy of the multi-turn dialogue model in prediction.
[0005] In a first aspect, embodiments of this application provide a method for training a multi-turn dialogue model, the method comprising:
[0006] A second training text is obtained from the training text containing multi-turn dialogues. The second training text includes a first training text and a first target text. The first training text and the second training text are both texts used to train the multi-turn dialogue model to be trained. The first target text is the first real result corresponding to the first training text, and the first target text is at least one text in the training text that is adjacent to the first training text.
[0007] The target vector corresponding to the second training text is determined, and the target vector is adjusted to a target update vector through weight increase processing. The weight increase processing is used to strengthen the connection between the first target text and the first training text.
[0008] Input the target update vector into the multi-turn dialogue model to be trained to obtain a second loss for the second training text;
[0009] Based on the second loss, the parameters of the multi-turn dialogue model to be trained are adjusted to obtain the trained multi-turn dialogue model.
[0010] Secondly, embodiments of this application provide a multi-turn dialogue prediction method, the method comprising:
[0011] Obtain the feature vector corresponding to the target text, where the target text is the text to be predicted in a multi-turn dialogue.
[0012] The feature vector corresponding to the target text is input into the trained multi-turn dialogue model, wherein the trained multi-turn dialogue model is a pre-trained multi-turn dialogue model.
[0013] The trained multi-turn dialogue model is used to perform dialogue prediction processing on the feature vectors and outputs a dialogue prediction result that matches the target text.
[0014] The trained multi-turn dialogue model is obtained using the training method described in the first aspect.
[0015] Thirdly, embodiments of this application provide a training apparatus for a multi-turn dialogue model, the apparatus comprising:
[0016] The acquisition module is used to acquire a second training text from training text containing multi-turn dialogues. The second training text includes a first training text and a first target text. The first training text and the second training text are both texts used to train the multi-turn dialogue model to be trained. The first target text is the first real result corresponding to the first training text, and the first target text is at least one text in the training text that is adjacent to the first training text.
[0017] A determination module is used to determine the target vector corresponding to the second training text, and adjust the target vector into a target update vector through weight increase processing, wherein the weight increase processing is used to strengthen the connection between the first target text and the first training text; the target update vector is input into the multi-turn dialogue model to be trained to obtain a second loss for the second training text;
[0018] An adjustment module is used to adjust the parameters of the multi-turn dialogue model to be trained based on the second loss, so as to obtain the trained multi-turn dialogue model.
[0019] Fourthly, embodiments of this application provide a multi-turn dialogue prediction device, the device comprising:
[0020] The acquisition module is used to acquire the feature vector corresponding to the target text, wherein the target text is the text to be predicted in a multi-turn dialogue.
[0021] The input module is used to input the feature vector corresponding to the target text into the trained multi-turn dialogue model, wherein the trained multi-turn dialogue model is a pre-trained multi-turn dialogue model.
[0022] The processing module is used to perform dialogue prediction processing on the feature vector through the trained multi-turn dialogue model, and output the dialogue prediction result that matches the target text.
[0023] The trained multi-turn dialogue model is obtained using the training method described in the first aspect.
[0024] Fifthly, embodiments of this application provide an electronic device including a processor and a memory, the memory storing programs or instructions that, when executed by the processor, implement the steps of the method described in the first or second aspect.
[0025] In a sixth aspect, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first or second aspect.
[0026] In a seventh aspect, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the methods described in the first or second aspect.
[0027] Eighthly, embodiments of this application provide a computer program product stored in a storage medium, which is executed by at least one processor to implement the method as described in the first or second aspect.
[0028] The multi-turn dialogue model training method provided in this application embodiment obtains a second training text from training text containing multi-turn dialogues. The second training text includes a first training text and a first target text. Both the first and second training texts are used to train the multi-turn dialogue model to be trained. The first target text is a first real result corresponding to the first training text, and the first target text is at least one text adjacent to the first training text in the training text. A target vector corresponding to the second training text is determined, and the target vector is adjusted to a target update vector through weighting processing. The weighting processing is used to strengthen the connection between the first target text and the first training text. The target update vector is input into the multi-turn dialogue model to be trained to obtain a second loss for the second training text. Based on the second loss, the parameters of the multi-turn dialogue model to be trained are adjusted to obtain the trained multi-turn dialogue model. Thus, by introducing weight augmentation during the training process of a multi-turn dialogue model, and strengthening the connection between the first training text and the corresponding first real result, a close connection can be achieved between the preceding and following dialogue texts in the same multi-turn dialogue scenario. This allows the multi-turn dialogue model to focus on the content in the first training text that is related to the first real result during training, and to re-understand the contextual information in the training text. This is beneficial for the multi-turn dialogue model to accurately predict subsequent sentences, and can, to some extent, solve the problem of low accuracy in prediction by multi-turn dialogue models in related technologies. Attached Figure Description
[0029] Figure 1 This is a schematic diagram of a training method for a multi-turn dialogue model provided in an embodiment of this application;
[0030] Figure 2 This is a schematic diagram of another training method for a multi-turn dialogue model provided in an embodiment of this application;
[0031] Figure 3 This is a flowchart illustrating a training method for a multi-turn dialogue model provided in an embodiment of this application;
[0032] Figure 4 This is a flowchart of another training method for a multi-turn dialogue model provided in an embodiment of this application;
[0033] Figure 5 This is a flowchart of another training method for a multi-turn dialogue model provided in an embodiment of this application;
[0034] Figure 6 This is a flowchart of another training method for a multi-turn dialogue model provided in an embodiment of this application;
[0035] Figure 7This is a flowchart of another training method for a multi-turn dialogue model provided in an embodiment of this application;
[0036] Figure 8 This is a flowchart of another training method for a multi-turn dialogue model provided in an embodiment of this application;
[0037] Figure 9 This is a flowchart of a multi-turn dialogue prediction method provided in an embodiment of this application;
[0038] Figure 10 This is a structural block diagram of a training device for a multi-turn dialogue model provided in an embodiment of this application;
[0039] Figure 11 This is a structural block diagram of a multi-turn dialogue prediction device provided in an embodiment of this application;
[0040] Figure 12 This is a structural block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0041] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0042] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0043] As described in the background section, related technologies often employ retrieval-based multi-turn dialogue models for dialogue prediction, selecting appropriate response statements from a database based on contextual information within the multi-turn dialogue. However, due to issues in training these retrieval-based multi-turn dialogue models, the prediction accuracy of the trained models is often low.
[0044] In view of this, this application creatively proposes a training method for a multi-turn dialogue model, which can improve the prediction accuracy of the multi-turn dialogue model to a certain extent.
[0045] Specifically, this application's embodiments introduce a weighting process. After obtaining the second training text, the weighting process can strengthen the connection between the first training text and the corresponding real result in the second training text. This closely links the preceding and following dialogue texts in the same multi-turn dialogue scenario, enabling the multi-turn dialogue model to focus on the content in the first training text that is related to the first real result during training. This allows the multi-turn dialogue model to review the preceding text in relation to the real result and re-understand the contextual information, which is beneficial for the model to accurately predict subsequent sentences. This can, to some extent, solve the problem of low accuracy in prediction by multi-turn dialogue models in related technologies.
[0046] Furthermore, this application embodiment proposes that the training text consists of a first part and a second part. The first training text includes all the content of the first part, and the second part includes n texts corresponding to n true results. It clarifies that the loss can be calculated once for each of the n texts to obtain n losses, and the parameters of the multi-turn dialogue model to be trained can be adjusted based on the average of the n losses. In this way, on the one hand, it is possible to optimize the parameters of the multi-turn dialogue model by comprehensively considering the full-text loss, overcoming the one-sidedness of updating model parameters based solely on a single prediction result in related technologies, making the updating of multi-turn dialogue model parameters more evidence-based. On the other hand, the prediction results of multiple sentences in the second part can be fed back to the multi-turn dialogue model through loss values, enabling the multi-turn dialogue model to have the ability of multi-sentence reasoning.
[0047] Furthermore, it should be noted that the improvements in this application's embodiments not only lie in the introduction of weight enhancement processing and loss comprehensive optimization, but also in the ability to select training text in different orders. Specifically, the training text can be divided into a first part and a second part in either a forward or backward order. During training, the text to be trained on the multi-turn dialogue model can be obtained from the training text based on this forward or backward order. In this way, the multi-turn dialogue model can be trained based on either the preceding or following information in the training text, achieving bidirectional training of the dialogue data. This allows the multi-turn dialogue model to infer the following text from the preceding text and vice versa, thereby enhancing the model's full-text understanding and reasoning capabilities regarding training texts containing multi-turn dialogues. In addition, based on obtaining the training text for the multi-turn dialogue model from the training text in a forward order, the text to be trained on the multi-turn dialogue model can also be obtained from the training text in a backward order. This combination of forward and backward training further improves the model's prediction accuracy. Similarly, based on obtaining the training text from the training text in reverse order to train the multi-turn dialogue model to be trained, the training text can be obtained from the training text in forward order. By combining backward training and forward training, the prediction accuracy of the model can be further improved.
[0048] Furthermore, it should be understood that the embodiments of this application not only propose weight increase processing but also clarify that weight increase processing can be performed based on the first loss corresponding to the first training text. It can be understood that the larger the first loss, the greater the difference between the predicted result output by the multi-turn dialogue model when predicting based on the first training text and the first target text (the true result corresponding to the first training text), meaning the model considers the first target text to be less related to the first training text. Thus, by using loss to increase weights and strengthen the connection between the first target text and the first training text, the prediction error of the multi-turn dialogue model can be compensated for, enabling the multi-turn dialogue model to pay more attention to important text in the first training text, thereby improving prediction accuracy.
[0049] The training method and prediction method of the multi-turn dialogue model provided in this application will be described in detail below with reference to the accompanying drawings, through specific embodiments and application scenarios.
[0050] Figure 1 This is a schematic diagram illustrating a training method for a multi-turn dialogue model provided in an embodiment of this application. For example... Figure 1As shown in the embodiments of this application, the training method for the multi-turn dialogue model may involve an embedding layer, an associated layer, and the multi-turn dialogue model to be trained. The embedding layer can output a target vector corresponding to the input training text. The associated layer can adjust the input target vector into a target update vector through weighting, strengthening the connection between the preceding information in the training text and the corresponding real results. The multi-turn dialogue model to be trained can predict the following sentence based on the text vector or target update vector corresponding to the input training text and output the prediction result. Furthermore, a loss calculation module can be set up in this embodiment. The loss calculation module can use a loss function to calculate the loss value based on the model prediction result and the corresponding real result. Since the training method for the multi-turn dialogue model provided in this embodiment is not limited to retrieval-based (selecting a suitable response statement from the database based on preceding information in a selection form) or generative (directly generating an answer based on the current question and historical information), the loss function can be selected according to the selected training method. For retrieval-based methods, cross-entropy loss function or others can be used; for generative methods, maximum likelihood function or others can be used.
[0051] It should be noted that, Figure 1 The training method of the multi-turn dialogue model shown corresponds to the forward training process, which is to obtain the training text from the training text containing multi-turn dialogues in a forward-to-back order and train the multi-turn dialogue model in sequence.
[0052] Reference Figure 1 Taking a training text containing nine texts (A, B, C, D, E, F, G, H, I) as an example, the specific process of forward training is as follows:
[0053] First, A, B, C, and D can be used as preceding information (first training text). The multi-turn dialogue model to be trained is then instructed to predict the following information E (first target text, the true result corresponding to text ABCD) based on the vectors corresponding to text ABCD, and output the prediction result e. The loss LE is calculated based on the prediction result e and the true result E.
[0054] Secondly, the LE results can be fed back to the text E, and the model parameters can be temporarily not updated based on the loss LE;
[0055] Secondly, A, B, C, D, and E can be used as preceding context information (the second training text), and F can be used as following context information (the true result corresponding to the second training text). Before inputting the preceding context information into the multi-turn dialogue model, the target vector corresponding to the preceding context information ABCDE can be input into the association layer. This allows the association layer to adjust the weights based on the loss LE from the previous step, optimizing the weights of the preceding context information A, B, C, D, and E, strengthening the connection between the first target text E and the first training text ABCD in the second training text, and outputting the adjusted target update vector to the multi-turn dialogue model to be trained. The multi-turn dialogue model outputs the prediction result f based on the target update vector corresponding to the input text ABCDE; the loss LF is calculated based on the prediction result f and the true result F.
[0056] Then, A, B, C, D, E, and F can be used as preceding information (the second training text), and G can be used as following information (the real result corresponding to the second training text). At this point, text ABCDE is the first training text, and text F is the first target text. Before inputting the preceding information into the multi-turn dialogue model, the target vector corresponding to the preceding information ABCDEF can be input into the association layer. This allows the association layer to adjust the weights based on the loss LF from the previous step, optimizing the weights of the preceding information A, B, C, D, E, and F, strengthening the connection between the first target text F and the first training text ABCDE in the second training text, and outputting the adjusted target update vector to the multi-turn dialogue model to be trained. The multi-turn dialogue model outputs the prediction result g based on the target update vector corresponding to the input text ABCDEF; and calculates the loss LG based on the prediction result g and the real result G.
[0057] This process is repeated until the final prediction step, yielding the loss LI. The model parameters are then updated based on the loss (LE+LF+LG+LH+LI) / 5.
[0058] Figure 2 This is a schematic diagram illustrating another training method for an argumentative dialogue model provided in an embodiment of this application. For example... Figure 2 As shown in the embodiments of this application, the training method for the multi-turn dialogue model may involve the use of an embedding layer, an associated layer, and the multi-turn dialogue model to be trained. Their respective functions can be referred to the description above.
[0059] It should be noted that, Figure 2 The training method of the multi-turn dialogue model shown corresponds to the backward training process, which is to obtain the training text from the training text containing multi-turn dialogues in reverse order and train the multi-turn dialogue model in sequence.
[0060] Reference Figure 2Taking a training text containing nine texts (A, B, C, D, E, F, G, H, I) as an example, the specific process of backward training is as follows:
[0061] First, F, G, H, and I can be used as preceding information (the first training text). The multi-turn dialogue model to be trained is then instructed to predict the following information E (the first target text, the true result corresponding to the text F, G, H, and I) based on the vector corresponding to the text F, G, H, and I, and output the prediction result e. The loss LE is calculated based on the prediction result e and the true result E.
[0062] Secondly, the LE results can be fed back to the text E, and the parameters of the model to be trained can be temporarily not updated based on the loss LE;
[0063] Secondly, E, F, G, H, and I can be used as preceding context information (the second training text), and D as following context information (the true result corresponding to the second training text). Before inputting the preceding context information into the multi-turn dialogue model, the target vector corresponding to the preceding context information EFGHI can be input into the association layer. This allows the association layer to adjust the weights based on the loss LE from the previous step, optimizing the weights of the preceding context information E, F, G, H, and I, strengthening the connection between the first target text E and the first training text FGHI in the second training text, and outputting the adjusted target update vector to the multi-turn dialogue model to be trained. The multi-turn dialogue model outputs the prediction result d based on the target update vector corresponding to the input text EFGHI; the loss LD is calculated based on the prediction result d and the true result D.
[0064] Then, D, E, F, G, H, and I can be used as preceding information (the second training text), and C can be used as following information (the real result corresponding to the second training text). At this point, text EFGHI is the first training text, and text D is the first target text. Before inputting the preceding information into the multi-turn dialogue model, the target vector corresponding to the preceding information DEFGHI can be input into the association layer. This allows the association layer to adjust the weights based on the loss LD from the previous step, optimizing the weights of the preceding information D, E, F, G, H, and I, strengthening the connection between the first target text D and the first training text EFGHI in the second training text, and outputting the adjusted target update vector to the multi-turn dialogue model to be trained. The multi-turn dialogue model outputs the prediction result c based on the target update vector corresponding to the input text DEFGHI; the loss LC is calculated based on the prediction result c and the real result C.
[0065] This process continues until the final prediction step, yielding the loss LA. The network parameters can then be updated based on the loss value (LA+LB+LC+LD+LE) / 5.
[0066] It should be noted that the training method for the multi-turn dialogue model provided in this application is applicable to training text in various multi-turn dialogue scenarios. Figure 1 and Figure 2 This is merely an example and should not be considered a limitation of this application. Moreover, it should be emphasized that the training method for the multi-turn dialogue model provided in the embodiments of this application can, in actual training, either perform forward training first and then backward training, or perform backward training first and then forward training.
[0067] Furthermore, it is understandable that the quality of a multi-turn dialogue model's prediction cannot be determined by a single answer, but rather by a combination of multiple outcomes from the multi-turn dialogue. The training method for the multi-turn dialogue model provided in this application proposes adjusting parameters based on the average of multiple losses, effectively avoiding the "single-turn" nature (optimizing model parameters only based on the loss from a single prediction within the same dialogue) when optimizing model parameters in multi-turn dialogues. Simultaneously, in related technologies, the multi-turn corpora within the same dialogue often lack connection during model training. However, the training method for the multi-turn dialogue model provided in this application can achieve predictive self-feedback through weighting, combining the prediction results of the same dialogue through an association layer, establishing connections between dialogue corpora in the same scene, which is beneficial for improving the prediction accuracy of the multi-turn dialogue model. In addition, related technologies, during model training, allow the model to predict subsequent corpora from preceding corpora, consistent with the reading comprehension process. However, predicting preceding text from following text better reflects human understanding and cognitive ability. The training method for the multi-turn dialogue model provided in this application improves the existing model cognitive training method by introducing a bidirectional training understanding approach, which is conducive to strengthening the model's understanding of text containing multi-turn dialogue and further improving prediction accuracy.
[0068] Figure 3 This application provides a training method for a multi-turn dialogue model. For example... Figure 3 As shown, the training method for the multi-turn dialogue model provided in this application embodiment may include the following steps:
[0069] Step 310: Obtain a second training text from the training text containing multi-turn dialogues. The second training text includes a first training text and a first target text. The first training text and the second training text are both texts used to train the multi-turn dialogue model to be trained. The first target text is the first real result corresponding to the first training text, and the first target text is at least one text in the training text that is adjacent to the first training text.
[0070] Multi-turn dialogue can be understood as a continuous dialogue based on context, aimed at solving a specific type of task. For example, the training text can include at least five texts. The first training text can include at least two consecutive texts from the training text. The first target text can be at least one text from the training text. A text can be understood as a sentence. If the first training text is used for multi-turn dialogue prediction, the first target text can be considered the true prediction result; that is, the first target text is the first true result corresponding to the first training text. At different training stages, different texts from the training text can be designated as second training texts for training the multi-turn dialogue model.
[0071] For example, if the training text includes nine texts (ABCDEFGHI), then four texts (ABCD) can be extracted from the training text and designated as the second training text. In this case, text ABC can be the first training text, and text D can be the first target text. Alternatively, five texts (ABCDE) can be extracted from the training text and designated as the second training text. In this case, text ABCD can be the first training text, and text E can be the first target text. Similarly, four texts (FGHI) can be extracted from the training text and designated as the second training text. In this case, text GHI can be the first training text, and text F can be the first target text. Of course, at least one of the following can be designated as the second training text: the first six, seven, or eight texts corresponding to the training text, or the last five, seven, or eight texts corresponding to the training text. These can be used to train the multi-turn dialogue model to be trained. It should be noted that the training text may include more or fewer texts than nine. The second training text obtained may be adjusted accordingly for different training texts. The above example is only for illustrative purposes and should not be regarded as a limitation of this application.
[0072] Step 320: Determine the target vector corresponding to the second training text, and adjust the target vector into a target update vector through weight increase processing. The weight increase processing is used to strengthen the connection between the first target text and the first training text.
[0073] Determining the target vector corresponding to the second training text can include: inputting the second training text into the embedding layer to obtain the target vector corresponding to the second training text, or using a matrix to transform the second training text into the corresponding target vector. The target vector can include sub-vectors corresponding to each text in the second training text, such as sub-vectors corresponding to each text in the first training text and sub-vectors corresponding to the first target text.
[0074] After determining the target vector, weights can be increased based on loss, enhancement formula, or custom enhancement methods to optimize the weights of each sub-vector in the target vector, adjust the target vector to the target update vector, and strengthen the connection between the first target text and the first training text.
[0075] Step 330: Input the target update vector into the multi-turn dialogue model to be trained to obtain the second loss for the second training text;
[0076] In this embodiment, the target update vector can be used as the input to the multi-turn dialogue model to be trained. Based on the prediction result output by the multi-turn dialogue model and the true result corresponding to the second training text, a second loss is determined for the second training text. The true result corresponding to the second training text can be at least one text in the training text. The cross-entropy loss function or the maximum likelihood function can be used to determine the second loss.
[0077] Step 340: Based on the second loss, adjust the parameters of the multi-turn dialogue model to be trained to obtain the trained multi-turn dialogue model.
[0078] As described above, multiple different second training texts can be determined for the same training text. And based on the different second training texts, multiple second losses can be determined.
[0079] Adjusting the parameters of the multi-turn dialogue model to be trained based on the second loss can include: adjusting the parameters of the multi-turn dialogue model to be trained based on each second loss obtained, or adjusting the parameters of the multi-turn dialogue model to be trained by combining multiple second losses for different second training texts. Specifically, the average value of multiple second losses can be determined, and the parameters of the multi-turn dialogue model to be trained can be adjusted based on the average value. Alternatively, the sum of the products of each second loss and its corresponding coefficient can be determined, and the parameters of the multi-turn dialogue model to be trained can be adjusted based on the sum.
[0080] The training method for a multi-turn dialogue model provided in this application introduces weighting processing during the training process. By strengthening the connection between the first training text and the corresponding first real result, the method can closely link the preceding and following dialogue texts in the same multi-turn dialogue scenario. This allows the multi-turn dialogue model to focus on the content in the first training text that is related to the first real result during training, and to re-understand the contextual information in the training text. This is beneficial for the multi-turn dialogue model to accurately predict subsequent sentences, and can thus solve the problem of low accuracy in prediction by multi-turn dialogue models in related technologies to a certain extent.
[0081] Since the loss corresponding to the first training text can reflect the prediction error of the multi-turn dialogue model and the degree of correlation between the first target text and the first training text as perceived by the multi-turn dialogue model, i.e., the greater the loss, the weaker the correlation between the first target text and the first training text as perceived by the multi-turn dialogue model. Therefore, weighting based on the loss corresponding to the first training text can compensate for some of the prediction loss, which is beneficial for the multi-turn dialogue model to achieve better training results. In one embodiment of this application, the training method of the multi-turn dialogue model may further include: obtaining a first prediction result corresponding to the first training text through the multi-turn dialogue model to be trained; obtaining a first loss for the first training text based on the first prediction result and the first target text; adjusting the target vector to a target update vector through weighting includes: adjusting the target vector to a target update vector through weighting based on the first loss. Thus, by using the first loss corresponding to the first training text for weighting, the connection between the first target text and the first training text is strengthened, and the prediction result of the current round can be fed back into the input data of the next round, compensating for the prediction error of the multi-turn dialogue model, and strengthening the multi-turn dialogue model's attention to important text in the first training text, which is beneficial for improving prediction accuracy.
[0082] The first training text can be at least two consecutive texts selected from the training text in either forward or backward order. For example, if the training text includes nine texts (ABCDEFGHI), then texts ABC can be selected as the first training text in forward order, and text D can be selected as the first target text. Alternatively, at least one of the first four, five, six, or seven texts corresponding to the training text can be selected as the first training text. Similarly, texts GHI can be selected as the first training text in backward order, and text F can be selected as the first target text. Alternatively, at least one of the last four, five, six, or seven texts corresponding to the training text can be selected as the first training text.
[0083] After obtaining the first training text, the first training text or the vector corresponding to the first training text can be input into the multi-turn dialogue model. Based on the output of the multi-turn dialogue model, the first prediction result corresponding to the first training text can be obtained.
[0084] After determining the first prediction result and the first target text, the first prediction result and the first target text can be substituted into the cross-entropy loss function or the maximum likelihood function to calculate the first loss for the first training text.
[0085] Based on the first loss, weighting can be performed to adjust the vector corresponding to the first training text in the target vector, amplify the similarity words between the first training text and the first target text, and adjust the target vector to the target update vector.
[0086] Optionally, in one embodiment of this application, the training text consists of a first part and a second part, wherein the first training text includes all the content of the first part; and the first target text is a text obtained from the second part of the training text in a forward-to-back order.
[0087] The first part can be located before or after the second part. The first part can include, for example, the first half, the first third, the last third, or the last half of the training text. The actual division of the first and second parts in the training text can be determined as needed.
[0088] Optionally, in one embodiment of this application, the training text consists of a first part and a second part, wherein the first training text includes all the content of the first part; and the first target text is a text obtained from the second part of the training text in reverse chronological order.
[0089] The first part can be located before or after the second part. The first part can include, for example, the first half, the first third, the last third, or the last half of the training text. The actual division of the first and second parts in the training text can be determined as needed.
[0090] When training a multi-turn dialogue model using training text, inputting information from the training text in different orders can endow the trained multi-turn dialogue model with different capabilities. In one embodiment of this application, the training text is divided into a first part and a second part in a forward-to-back order; the first part of the training text is denoted by F1; the second part includes n texts arranged in ascending order from front to back: P1...P n Where n≥2; the first training text includes F1, and the second training text is F1+X1, where X1 is P1 to P... i The first target text is P i Where 1≤i≤n-1. Thus, the first and second training texts can be obtained from the training text in a forward order, and the multi-turn dialogue model to be trained can be trained in a forward manner, so that the multi-turn dialogue model to be trained can acquire the ability to infer the following text based on the preceding text information through training.
[0091] In this embodiment of the application, the first training text can be F1+X1-Pi The first target text can be the last text in the second training text.
[0092] When the second training text is F1+P1, the first training text can be F1, and the first target text can be P1. When the second training text is F1+P1+P2, the first training text can be F1+P1, and the first target text can be P2. When the second training text is F1+P1+P2+P3, the first training text can be F1+P1+P2, and the first target text can be P3. Based on the pattern described above, when the second training text is F1+P1+…+P… n-1 At that time, the first training text can be F1+P1+…+P n-2 The first target text can be P n-1 .
[0093] In another embodiment of this application, the training text is divided into a first part and a second part in reverse order from back to front; the first part of the training text is denoted by F2; the second part includes n texts arranged in descending order from back to front: P n ...P1, where n≥2; the first training text includes F2, the second training text is F2+X2, X2 is Pn to Pi, and the first target text is Pi, where 2≤i≤n. Thus, the first and second training texts can be obtained from the training text in reverse order, and the multi-turn dialogue model to be trained can be backward trained. This allows the multi-turn dialogue model to acquire the ability to infer preceding information from subsequent information, which helps the multi-turn dialogue model strengthen its understanding of the entire training text, thereby further improving the model's prediction accuracy.
[0094] In this embodiment of the application, the first training text can be F2+X2-P. i The first target text can be the first text in the second training text.
[0095] When the second training text is F2+P n At that time, the first training text can be F2, and the first target text can be P. n When the second training text is F2+P n +P n-1 At that time, the first training text can be F2+P n The first target text can be P n-1 When the second training text is F2+P n +P n-1 +P n-2 At that time, the first training text can be F2+P n +P n-1 The first target text can be Pn-2 Based on the pattern described above, when the second training text is F2+P... n When +…+P2, the first training text can be F2+P. n +…+P3, the first target text can be P2.
[0096] Optionally, in one embodiment of this application, step 330, inputting the target update vector into the multi-turn dialogue model to be trained to obtain a second loss for the second training text, may include: inputting the target update vector into the multi-turn dialogue model to be trained to obtain a second prediction result corresponding to the second training text; and obtaining a second loss for the second training text based on the second prediction result and the second target text; wherein the second target text is the second true result corresponding to the second training text, and the second target text is adjacent to the first target text. Thus, the second loss for the second training text can be accurately determined using the second training text and the second target text.
[0097] If a second training text is used for multi-turn dialogue prediction, the second target text can be taken as the true prediction result; that is, the second target text is the second true result corresponding to the second training text. In different training phases, the second target text changes along with the second training text.
[0098] For example, if the training text includes nine texts (ABCDEFGHI), and the second training text is ABCDE, then text F, which is adjacent to the second training text, can be identified as the second target text. Similarly, if the second training text is EFGHI, then text D, which is adjacent to the second training text, can be identified as the second target text.
[0099] Figure 4 This is a flowchart illustrating another training method for a multi-turn dialogue model provided in an embodiment of this application. For example... Figure 4 As shown, the training method for the multi-turn dialogue model provided in this application embodiment may include the following steps:
[0100] Step 405: Obtain a first training text and a first target text from the training text; wherein, the first target text is at least one text in the training text that is adjacent to the first training text;
[0101] Step 410: Obtain the first prediction result corresponding to the first training text through a multi-turn dialogue model;
[0102] Step 415: Based on the first prediction result and the first target text, obtain the first loss for the first training text;
[0103] Step 420: Obtain a second training text from the training text containing multi-turn dialogues. The second training text includes a first training text and a first target text. The first training text and the second training text are both texts used to train the multi-turn dialogue model to be trained. The first target text is the first real result corresponding to the first training text.
[0104] Step 425: Determine the target vector corresponding to the second training text;
[0105] Step 430: Determine the similarity between the first target text and each sentence in the first training text to obtain S similarity weight sequences, wherein the first training text includes S texts and S is a positive integer;
[0106] The similarity between texts can be represented as the word similarity between two texts, which can be obtained by calculating the cosine similarity of the vectors corresponding to every two characters in the text. In this embodiment, for each text in the first training text, the vector corresponding to that text can be determined. Simultaneously, the vector corresponding to the first target text is determined. A similarity weight sequence is then calculated based on the vector corresponding to any text in the training text and the vector corresponding to the first target text. Of course, the vectors corresponding to each text in the first training text and the vector corresponding to the first target text can be directly obtained from the target vector.
[0107] For example, if the first training text includes four texts A, B, C, and D, and the first target text is E, then the similarity between text E and text A can be determined to obtain the first similarity weight sequence; the similarity between text E and text B can be determined to obtain the second similarity weight sequence; the similarity between text E and text C can be determined to obtain the third similarity weight sequence; and the similarity between text E and text D can be determined to obtain the fourth similarity weight sequence.
[0108] Step 435: Based on the first loss, perform weight increase processing on the S similarity weight sequences to obtain S target similarity weight sequences;
[0109] Each similarity weight sequence can include multiple weight values. After determining S similarity weight sequences, the increment of the weight value to be amplified can be determined based on the first loss. The weight value to be amplified can be a value in the similarity weight sequence that meets a preset condition. Specifically, the product of the first loss and the first coefficient can be used as the increment, and the weight value to be amplified in the similarity weight sequence can be updated to the sum of the original weight value and the increment, thus obtaining the target similarity weight sequence. The first coefficient can be any value greater than 0 and less than 1.
[0110] Step 440: Multiply the vector to be updated in the target vector by the respective target similarity weight sequences in the S target similarity weight sequences to obtain the target updated vector; wherein, the vector to be updated is all or part of the vectors in the target vector that satisfy the specified conditions;
[0111] As described above, if the first training text includes four texts A, B, C, and D, and the first target text is E, then the similarity between text E and text A can be determined, resulting in the first similarity weight sequence. After weighting the first similarity weight sequence to obtain the first target similarity weight sequence, the vector corresponding to text A in the target vector can be determined. This vector is then multiplied by the first target similarity weight sequence. Other similar steps are performed similarly. This yields the target update vector.
[0112] Step 445: Input the target update vector into the multi-turn dialogue model to be trained to obtain the second loss for the second training text;
[0113] Step 450: Based on the second loss, adjust the parameters of the multi-turn dialogue model to be trained to obtain the trained multi-turn dialogue model.
[0114] The training method for the multi-turn dialogue model provided in this application embodiment, based on the first loss, performs weight increase processing on the similarity weight sequence, which can realize prediction self-feedback. It combines the prediction results of the same dialogue with the text used for training through weight increase processing, so as to establish a connection between the dialogue corpora in the same scene, which is conducive to improving the prediction accuracy of the multi-turn dialogue model.
[0115] The training method for a multi-turn dialogue model provided in this application embodiment can amplify only the weight values that meet certain conditions within the S similarity weight sequences when performing weight amplification processing on the S similarity weight sequences. In one embodiment of this application, step 435, which involves performing weight amplification processing on the S similarity weight sequences based on the first loss to obtain S target similarity weight sequences, may include: for each of the S similarity weight sequences, performing weight amplification processing using the following formula: V2 = V1 + (1 - Nmax) * L1 to obtain S target similarity weight sequences; where V1 is a specified value in the similarity weight sequence, the specified value being a weight value greater than a threshold, V2 is the weight value obtained after weight amplification processing on V1, Nmax is the maximum weight value in the similarity weight sequence, and L1 is the first loss. In this way, it is possible to focus on amplifying similar word groups between texts (word groups with corresponding weight values greater than a threshold), enabling the multi-turn dialogue model to focus on text related to the correct answer (true result) during prediction, thereby improving the prediction accuracy of the trained multi-turn dialogue model.
[0116] V1 can be greater than or equal to 0.4 and less than or equal to 0.8. The formula shows that the larger the first loss, the greater the actual amplification effect. The smaller Nmax is while still above the threshold, the greater the actual amplification effect.
[0117] Taking one of the S similarity weight sequences as [0.1, 0.2, 0.3, 0.4, 0.5, 0.4, 0.5, 0.6] as an example, Nmax = 0.6, 1-Nmax = 0.4. If L1 = 0.6 and V1 ≥ 0.5, then after weighting, the target similarity weight sequence can be [0.1, 0.2, 0.3, 0.4, 0.74, 0.4, 0.74, 0.84].
[0118] Figure 5 This is a flowchart illustrating another training method for a multi-turn dialogue model provided in an embodiment of this application. For example... Figure 5 As shown, the training method for the multi-turn dialogue model provided in this application embodiment may include the following steps:
[0119] Step 510: Obtain a second training text from the training text containing multi-turn dialogues. The second training text includes a first training text and a first target text. The first training text and the second training text are both texts used to train the multi-turn dialogue model to be trained. The first target text is the first real result corresponding to the first training text.
[0120] The training text consists of a first part and a second part. The first training text includes all the content of the first part. The first target text is a text obtained from the second part of the training text in a forward-to-back order.
[0121] The training text is divided into a first part and a second part in chronological order. The first part of the training text is denoted by F1. The second part includes n texts arranged in ascending order from front to back: P1...P n Where n≥2; the first training text includes F1, the second training text is F1+X1, X1 is P1 to Pi, and the first target text is P. i , where 1≤i≤n-1. The first part may include the first half of the training text.
[0122] The n texts in the second part can correspond to n real results, where the first real result is one of the n real results. In the case where the first part includes the first half of the training text, n can be the number of rounds in the multi-turn dialogue.
[0123] In this embodiment, when the second training text is F1+P1, the first training text can be F1, the first target text can be P1, and P2 in the second part can be the true result corresponding to the second training text. When the second training text is F1+P1+P2, the first training text can be F1+P1, the first target text can be P2, and P3 in the second part can be the true result corresponding to the second training text. When the second training text is F1+P1+P2+P3, the first training text can be F1+P1+P2, the first target text can be P3, and P4 in the second part can be the true result corresponding to the second training text. According to the pattern described above, when the second training text is F1+P1+…+P… n-1 At that time, the first training text can be F1+P1+…+P n-2 The first target text can be P n-1 At this point, P in the second part n It can be the real result corresponding to the second training text.
[0124] Step 520: Determine the target vector corresponding to the second training text, and adjust the target vector into a target update vector through weight increase processing. The weight increase processing is used to strengthen the connection between the first target text and the first training text.
[0125] Once the target vector is determined, weighting can be performed based on loss, enhancement formula, or custom enhancement methods.
[0126] The weighting process can be implemented by the association layer; the specific weighting process can be found in [reference needed]. Figure 4 Partial description.
[0127] Step 530: Input the target update vector into the multi-turn dialogue model to be trained to obtain the second loss for the second training text;
[0128] Step 540: Calculate the loss once for each of the n texts to obtain n losses; wherein, the first loss and the second loss for the first training text are both among the n losses.
[0129] The n losses can be multiple losses obtained from the first training text and the second training text. Specifically, a first loss can be obtained based on the prediction result F1 and the true result P1 of the multi-turn dialogue model output for the first training text F1. A second loss can be obtained based on the prediction result F1+P1 and the true result P2 of the multi-turn dialogue model output for the second training text F1+P1+P2. A third loss can be obtained based on the prediction result F1+P1+…+Pn-1 and the true result P... n We can obtain a second loss. Thus, by training on a training text containing multi-turn dialogues, we can obtain n losses.
[0130] For ease of understanding, the following section uses loss-based weight enhancement through an association layer as an example to explain in detail the training method of the multi-turn dialogue model provided in this application.
[0131] First, the vector corresponding to the preceding information F1 (the first training text) can be input into the multi-turn dialogue model to be trained to obtain the prediction result. The loss L1 is calculated based on the prediction result and the actual result P1. At this time, the model parameters do not need to be updated.
[0132] Secondly, the preceding information can be updated to F1+P1 (the second training text), and the predicted true result can be updated to P2. After embedding the preceding information F1+P1 into characters (e.g., inputting it into the embedding layer to obtain the target vector corresponding to the preceding information F1+P1), it is input into the association layer. The association layer can perform weighting based on the loss value L1 to strengthen the connection between P1 (the first target text) and the preceding information F1 (the first training text), outputting the target update vector corresponding to the preceding information F1+P1 to the multi-turn dialogue model to be trained. The loss L2 is calculated based on the output of the multi-turn dialogue model and P2.
[0133] Next, the preceding information can be updated to F+P1+P2 (the second training text), and the predicted true result can be updated to P3. The preceding information F+P1+P2 is then embedded into characters and input into the association layer. The association layer can increase the weights based on the loss value L2 to strengthen the connection between P2 (the first target text) and the preceding information F1+P1 (the first training text), outputting the target update vector corresponding to the preceding information F+P1+P2 to the multi-turn dialogue model to be trained. The loss L3 is calculated based on the output of the multi-turn dialogue model and P3.
[0134] Then, according to the above pattern, this continues until the preceding information is updated to F+P1+…+P n-1 (Second training text), the predicted true result is updated to P. nThe preceding information is F+P1+…+P n-1 After character embedding, the input is fed into the association layer. The association layer can then be configured based on the loss value L. n-1 Perform weighting to strengthen P n-1 (First target text) and the preceding text F+P1+…+P n-2 The connection between the first training text and the preceding text is used to output the preceding text information F+P1+…+P to the multi-turn dialogue model to be trained. n-1 The corresponding target update vector. Based on the output of the multi-turn dialogue model and P n Calculate the loss L n .
[0135] Step 550: Determine the average value of the n losses, including the second loss;
[0136] Step 560: Adjust the parameters of the multi-turn dialogue model based on the average value.
[0137] In this embodiment, the n losses include a second loss. After determining the average value of the n losses, the average value can be directly used to adjust the parameters of the multi-turn dialogue model to be trained, or the average value can be used as the sum of the average value and a constant selected based on experience to adjust the parameters of the multi-turn dialogue model to be trained.
[0138] The training method for a multi-turn dialogue model provided in this application introduces weight augmentation during the training process. This weight augmentation strengthens the connection between the first training text and the corresponding first real result, enabling a close connection between the preceding and following dialogue texts within the same multi-turn dialogue scenario. This allows the multi-turn dialogue model to focus on content in the first training text that is related to the first real result during training, thus reinterpreting the contextual information in the training text. This is beneficial for the multi-turn dialogue model to accurately predict subsequent sentences, thereby improving the model's prediction accuracy to a certain extent. Furthermore, it proposes adjusting parameters based on the average of multiple losses. This effectively avoids the "single-turn" nature (optimizing model parameters only based on the loss from predicting a single result in the same dialogue) when optimizing model parameters in multi-turn dialogue.
[0139] Figure 6 This is a flowchart illustrating another training method for a multi-turn dialogue model provided in an embodiment of this application. For example... Figure 6 As shown, the training method for the multi-turn dialogue model provided in this application embodiment may include the following steps:
[0140] Step 610: Obtain a second training text from the training text containing multi-turn dialogues. The second training text includes a first training text and a first target text. The first training text and the second training text are both texts used to train the multi-turn dialogue model to be trained. The first target text is the first real result corresponding to the first training text.
[0141] The training text consists of a first part and a second part. The first training text includes all the content of the first part. The first target text is a text obtained from the second part of the training text in reverse chronological order.
[0142] The training text is divided into a first part and a second part in reverse order from back to front; the first part of the training text is denoted by F2; the second part includes n texts arranged in descending order from back to front: P n ...P1, where n≥2; the first training text includes F2, the second training text is F2+X2, and X2 is P... n To P i The first target text is P i , where 2≤i≤n. The first part may include the latter half of the training text.
[0143] The n texts in the second part can correspond to n real results, and the first real result is one of the n real results.
[0144] When the second training text is F2+P n At that time, the first training text can be F2, and the first target text can be P. n At this point, P in the second part n-1 This can be the true result corresponding to the second training text. When the second training text is F2+P n +P n-1 At that time, the first training text can be F2+P n The first target text can be P n-1 In this case, Pn-2 in the second part can be the true result corresponding to the second training text. When the second training text is F2+P n +P n-1 +P n-2 At that time, the first training text can be F2+P n +P n-1 The first target text can be P n-2 At this point, P in the second part n-3 This can be the true result corresponding to the second training text. Based on the pattern described above, when the second training text is F2+P... nWhen +…+P2, the first training text can be F2+P. n +…+P3, the first target text can be P2, and P1 in the second part can be the real result corresponding to the second training text.
[0145] Step 620: Determine the target vector corresponding to the second training text, and adjust the target vector into a target update vector through weight increase processing. The weight increase processing is used to strengthen the connection between the first target text and the first training text.
[0146] Once the target vector is determined, weighting can be performed based on loss, enhancement formula, or custom enhancement methods.
[0147] The weighting process can be implemented by the association layer; the specific weighting process can be found in [reference needed]. Figure 4 Partial description.
[0148] Step 630: Input the target update vector into the multi-turn dialogue model to be trained to obtain the second loss for the second training text;
[0149] Step 640: Calculate the loss once for each of the n texts to obtain n losses; wherein, the first loss and the second loss for the first training text are both among the n losses.
[0150] The n losses can be multiple losses obtained from the first and second training texts. Specifically, they are the prediction results F2 and the true results P output by the multi-turn dialogue model for the first training text. n We can obtain a first loss. Based on the F2+P output of the multi-turn dialogue model for the second training text... n The predicted results and the actual results P n-1 A second loss can be obtained. Based on the F2+P output of the multi-turn dialogue model for the second training text, a second loss can be obtained. n +P n-1 The predicted results and the actual results P n-2 A second loss can be obtained... based on the F2+P output of the multi-turn dialogue model for the second training text. n The predicted result of P2 and the actual result P1 are combined to obtain a second loss. Thus, by training on a training text containing multiple rounds of dialogue, n losses can be obtained.
[0151] For ease of understanding, the following section uses loss-based weight enhancement through an association layer as an example to explain in detail the training method of the multi-turn dialogue model provided in this application.
[0152] First, the vector corresponding to the preceding information F2 (the first training text) can be input into the multi-turn dialogue model to be trained to obtain the prediction result. Then, the prediction result is compared with the actual result P. n The loss L was calculated. n In this case, the model parameters do not need to be updated;
[0153] Secondly, the information above can be updated to F2+P. n (Second training text), the predicted true result is updated to P. n-1 F2+P (replace the preceding information) n After character embedding (e.g., input embedding layer, to obtain the preceding information F2+P) n The corresponding target vector is input into the association layer. The association layer can then adjust the loss value L. n Perform weighting to strengthen P n The connection between the first target text and the preceding text F2 (first training text) is used to output the target update vector corresponding to the preceding text information F2+Pn to the multi-turn dialogue model to be trained. Based on the output of the multi-turn dialogue model and P... n-1 Calculate the loss L n-1 ;
[0154] Again, the information above can be updated to F2+P. n +P n-1 (Second training text), the predicted true result is updated to Pn-2, and the previous information F2+P is added. n +P n-1 After character embedding, the input is fed into the association layer. The association layer can be weighted according to the loss value Ln-1 to strengthen P. n-1 (First target text) and the previous F2+P n The connection between the first training text and the preceding text is used to output the preceding text information F2+Pn+P to the multi-turn dialogue model to be trained. n-1 The corresponding target update vector. Based on the output of the multi-turn dialogue model and P n-2 Calculate the loss L n-2 ;
[0155] Then, based on the above pattern, until the preceding information is updated to F2+P. n +…+P2 (second training text), predict the true result and update it to P1. Add the preceding information F2+P n After character embedding using +…+P2, the text is input into the association layer. The association layer can apply weights based on the loss value L2 to strengthen the connection between P2 (the first target text) and the preceding text F2+P. n The connection between +…+P3 (the first training text) outputs the preceding context information F2+P to the multi-turn dialogue model to be trained. nThe target update vector corresponding to P2 is calculated based on the output of the multi-turn dialogue model and P1.
[0156] Step 650: Determine the average value of the n losses, including the second loss;
[0157] Step 660: Adjust the parameters of the multi-turn dialogue model to be trained based on the average value.
[0158] After determining the average value of n losses, the average value can be used directly to adjust the parameters of the multi-turn dialogue model to be trained, or the average value can be used as the sum of the average value and a constant selected based on experience to adjust the parameters of the multi-turn dialogue model to be trained.
[0159] The training method for a multi-turn dialogue model provided in this application introduces weight augmentation during the training process. This weight augmentation strengthens the connection between the first training text and the corresponding first real result, enabling a close connection between the preceding and following dialogue texts within the same multi-turn dialogue scenario. This allows the multi-turn dialogue model to focus on content in the first training text that is related to the first real result during training, thus reinterpreting the contextual information in the training text. This is beneficial for the multi-turn dialogue model to accurately predict subsequent sentences, thereby improving the model's prediction accuracy to a certain extent. Furthermore, it proposes adjusting parameters based on the average of multiple losses. This effectively avoids the "single-turn" nature (optimizing model parameters only based on the loss from predicting a single result in the same dialogue) when optimizing model parameters in multi-turn dialogue.
[0160] As described above, when training a multi-turn dialogue model using training text, inputting information from the training text in different orders can endow the trained multi-turn dialogue model with different capabilities. The following sections will describe the scenarios of performing forward training followed by backward training, and backward training followed by forward training.
[0161] Figure 7 This is a flowchart illustrating another training method for a multi-turn dialogue model provided in an embodiment of this application. For example... Figure 7 As shown, the training method for the multi-turn dialogue model provided in this application embodiment may include the following steps:
[0162] Step 710: Obtain a second training text from the training text containing multi-turn dialogues. The second training text includes a first training text and a first target text. The first training text and the second training text are both texts used to train the multi-turn dialogue model to be trained. The first target text is the first real result corresponding to the first training text.
[0163] The training text consists of a first part and a second part. The first training text includes all the content of the first part. The first target text is a text obtained from the second part of the training text in a forward-to-back order.
[0164] The training text is divided into a first part and a second part in chronological order. The first part of the training text is denoted by F1. The second part includes n texts arranged in ascending order from front to back: P1...P n Where n≥2; the first training text includes F1, and the second training text is F1+X1, where X1 is P1 to P... i The first target text is Pi, where 1 ≤ i ≤ n-1. The first part may include the first half of the training text.
[0165] In this embodiment, training texts can be selected from the training texts in a forward-to-back order for forward training of the multi-turn dialogue model to be trained. Specifically, when the second training text is F1+P1, the first training text can be F1, and the first target text can be P1. When the second training text is F1+P1+P2, the first training text can be F1+P1, and the first target text can be P2. When the second training text is F1+P1+P2+P3, the first training text can be F1+P1+P2, and the first target text can be P3. Following the pattern described above, when the second training text is F1+P1+…+P… n-1 At that time, the first training text can be F1+P1+…+P n-2 The first target text can be P n-1 .
[0166] Step 720: Determine the target vector corresponding to the second training text, and adjust the target vector into a target update vector through weight increase processing. The weight increase processing is used to strengthen the connection between the first target text and the first training text.
[0167] Determining the target vector corresponding to the second training text may include: inputting the second training text into the embedding layer to obtain the target vector corresponding to the second training text, or using a matrix to transform the second training text into the corresponding target vector.
[0168] Once the target vector is determined, weighting can be performed based on loss, enhancement formula, or custom enhancement methods.
[0169] The weighting process can be implemented by the association layer; the specific weighting process can be found in [reference needed]. Figure 4 Partial description.
[0170] Step 730: Input the target update vector into the multi-turn dialogue model to be trained to obtain the second loss for the second training text;
[0171] In this embodiment, the target update vector can be used as the input to the multi-turn dialogue model to be trained. Based on the prediction result output by the multi-turn dialogue model and the true result corresponding to the second training text, a second loss is determined for the second training text. The true result corresponding to the second training text can be at least one text in the training text (e.g., a text adjacent to the second training text). The cross-entropy loss function or the maximum likelihood function can be used to determine the second loss.
[0172] Step 740: Based on the second loss, adjust the parameters of the multi-turn dialogue model to be trained to obtain the trained multi-turn dialogue model;
[0173] As described above, multiple different second training texts can be determined for the same training text. And based on the different second training texts, multiple second losses can be determined.
[0174] Adjusting the parameters of the multi-turn dialogue model to be trained based on the second loss may include: adjusting the parameters of the multi-turn dialogue model to be trained according to each second loss obtained, or adjusting the parameters of the multi-turn dialogue model to be trained by combining multiple second losses for different second training texts.
[0175] Step 750: Obtain a fourth training text from the training text containing multi-turn dialogues. The fourth training text includes a third training text and a third target text. The third training text and the fourth training text are both texts used to train the multi-turn dialogue model to be trained. The third target text is the real result corresponding to the third training text.
[0176] The third target text is a single text obtained from the first part of the training text in reverse chronological order; the second part of the training text is denoted by F3; the first part includes m texts arranged in descending order from back to front: K m ...K1, where m≥2; the third training text includes F3, and the fourth training text is F3+X3, where X3 is K m To K j The third target text is K. j , where 2≤j≤m.
[0177] In this embodiment, after completing the forward training, texts for training can be selected from the training texts in reverse order to perform reverse training on the multi-turn dialogue model to be trained. Specifically, when the fourth training text is F3+K... m When the third training text is F3, the third target text can be Km. When the fourth training text is F3+K... m +K m-1 At that time, the third training text can be F3+K. m The third target text can be K m-1 When the fourth training text is F3+K m +K m-1 +K m-2 At that time, the third training text can be F3+K. m +K m-1 The third target text can be Km-2. Based on the pattern described above, when the fourth training text is F3+K... m When +…+K2, the third training text can be F3+K. m +…+K3, where the third target text can be K2.
[0178] Step 760: Determine the first specified vector corresponding to the fourth training text, and adjust the first specified vector to the first update vector through weight increase processing. The weight increase processing is used to strengthen the connection between the third target text and the third training text.
[0179] Determining the first specified vector corresponding to the fourth training text may include: inputting the fourth training text into the embedding layer to obtain the first specified vector corresponding to the fourth training text, or using a matrix to transform the fourth training text into the corresponding first specified vector.
[0180] After determining the first specified vector, weights can be increased based on loss, enhancement formula, or custom enhancement methods to obtain the first updated vector.
[0181] The weighting process can be implemented by the association layer; the specific weighting process can be found in [reference needed]. Figure 4 Partial description.
[0182] Step 770: Based on the first update vector, determine the fourth loss for the fourth training text;
[0183] In this embodiment, the first update vector can be used as the input to the multi-turn dialogue model to be trained. Based on the prediction result output by the multi-turn dialogue model and the real result corresponding to the fourth training text, a fourth loss is determined for the fourth training text. The real result corresponding to the fourth training text can be at least one text in the training text (e.g., a text adjacent to the fourth training text). The cross-entropy loss function or the maximum likelihood function can be used to determine the fourth loss.
[0184] Step 780: Based on the fourth loss, adjust the parameters of the trained multi-turn dialogue model.
[0185] As described above, multiple different fourth training texts can be determined for the same training text. And based on the different fourth training texts, multiple fourth losses can be determined.
[0186] Adjusting the parameters of the multi-turn dialogue model to be trained based on the fourth loss may include: adjusting the parameters of the multi-turn dialogue model to be trained according to each fourth loss obtained, or adjusting the parameters of the multi-turn dialogue model to be trained by combining multiple fourth losses for different fourth training texts.
[0187] The training method for the multi-turn dialogue model proposed in this application introduces a weighting process, which establishes connections between dialogue corpora in the same scene, facilitating the multi-turn dialogue model's full understanding of the context and improving prediction accuracy. Furthermore, it proposes a bidirectional training method, selecting texts in reverse order for model training. This improves the multi-turn dialogue model's ability to predict subsequent text based on preceding context during forward training, and enhances its ability to predict preceding text based on subsequent context during backward training. This strengthens the multi-turn dialogue model's understanding of the entire training text, further improving its prediction accuracy.
[0188] Since the loss corresponding to the third training text can reflect the prediction error of the multi-turn dialogue model and the degree of correlation between the third target text and the third training text as perceived by the multi-turn dialogue model, that is, the greater the loss, the weaker the correlation between the third target text and the third training text as perceived by the multi-turn dialogue model. Therefore, weighting based on the loss corresponding to the third training text can compensate for part of the prediction loss, which is beneficial for the multi-turn dialogue model to achieve better results in training. In one embodiment of this application, before obtaining the fourth training text from the training text containing multi-turn dialogue in step 750, the training method of the multi-turn dialogue model may further include: obtaining the third training text and the third target text from the training text; wherein, the third target text is at least one text adjacent to the third training text in the training text; obtaining the third prediction result corresponding to the third training text through the obtained trained multi-turn dialogue model; obtaining the third loss for the third training text based on the third prediction result and the third target text; the step of adjusting the first specified vector to the first update vector through weighting includes: adjusting the first specified vector to the first update vector through weighting based on the third loss. Thus, by using the third loss corresponding to the third training text to increase the weights, the connection between the third target text and the third training text is strengthened. The prediction results of the current round can be fed back into the input data of the next round, making up for the prediction error of the multi-round dialogue model, strengthening the multi-round dialogue model's attention to important texts in the third training text, and thus improving the prediction accuracy.
[0189] Referring to the description above, the third training text can be F3 or F3+K. m F3+K m +K m-1 ..., F3+K m +…+K3. The third target text that matches it can be K in sequence. m K m-1 K m-2 ... K2.
[0190] After obtaining the third training text, the third training text or the vector corresponding to the third training text can be input into the multi-turn dialogue model. Based on the output of the multi-turn dialogue model, the third prediction result corresponding to the third training text can be obtained.
[0191] After determining the third prediction result and the third target text, the third prediction result and the third target text can be substituted into the cross-entropy loss function or the maximum likelihood function to calculate the third loss for the third training text.
[0192] Based on the third loss, weighting can be performed to adjust the vector corresponding to the third training text in the target vector, amplify the similarity words between the third training text and the third target text, and adjust the first specified vector to the first updated vector.
[0193] To avoid the bias of updating model parameters based on only one prediction result, the parameters of the multi-turn dialogue model can be updated by combining multiple prediction results for the same dialogue scenario during actual training. In one embodiment of this application, the m texts in the first part correspond to m real results, and the third real result is one of the m real results. Step 780, adjusting the parameters of the multi-turn dialogue model based on the fourth loss, may include: calculating a loss once for each of the m texts to obtain m losses; wherein the third loss and the fourth loss are both one of the m losses; determining the average value of the m losses; and adjusting the parameters of the multi-turn dialogue model based on the average value. In this way, the parameters of the multi-turn dialogue model can be comprehensively optimized by using the multi-turn prediction result losses to simulate multi-turn interaction scenarios, enabling the multi-turn dialogue model to have comprehensive judgment capabilities and patterns for multi-turn dialogue.
[0194] The m losses can be multiple losses obtained from the third and fourth training texts. Specifically, they are based on the prediction result F3 output by the multi-turn dialogue model for the third training text and the true result K from the first part. m A third loss can be obtained. Based on the F3+K loss from the multi-turn dialogue model output for the fourth training text... m The predicted results and the actual results K in Part 1 m-1 A fourth loss can be obtained. Based on the F3+K loss of the fourth training text output by the multi-turn dialogue model... m +K m-1 The predicted results and the actual results K in Part 1 m-2 A second loss can be obtained... based on the F3+K output of the multi-turn dialogue model for the fourth training text. m The prediction result of +…+K2 and the true result K1 in the first part can be used to obtain a fourth loss. Thus, by training on a training text containing multi-turn dialogues, m losses can be obtained.
[0195] After determining the average value of m losses, the average value can be used directly to adjust the parameters of the multi-turn dialogue model to be trained, or the average value can be used as the sum of the average value and a constant selected based on experience to adjust the parameters of the multi-turn dialogue model to be trained.
[0196] Figure 8 This is a flowchart illustrating another training method for a multi-turn dialogue model provided in an embodiment of this application. For example... Figure 8 As shown, the training method for the multi-turn dialogue model provided in this application embodiment may include the following steps:
[0197] Step 810: Obtain a second training text from the training text containing multi-turn dialogues. The second training text includes a first training text and a first target text. The first training text and the second training text are both texts used to train the multi-turn dialogue model to be trained. The first target text is the first real result corresponding to the first training text.
[0198] The training text consists of a first part and a second part. The first training text includes all the content of the first part. The first target text is a text obtained from the second part of the training text in reverse chronological order.
[0199] The training text is divided into a first part and a second part in reverse order from back to front; the first part of the training text is denoted by F2; the second part includes n texts arranged in descending order from back to front: P n ...P1, where n≥2; the first training text includes F2, the second training text is F2+X2, and X2 is P... n To P i The first target text is P i , where 2≤i≤n.
[0200] In this embodiment, training texts can be selected from the training texts in reverse order to perform reverse training on the multi-turn dialogue model to be trained. Specifically, when the second training text is F2+P... n At that time, the first training text can be F2, and the first target text can be P. n When the second training text is F2+P n +P n-1 At that time, the first training text can be F2+P n The first target text can be P n-1 When the second training text is F2+P n +P n-1 +P n-2 At that time, the first training text can be F2+P n +P n-1 The first target text can be P n-2 Based on the pattern described above, when the second training text is F2+P... n When +…+P2, the first training text can be F2+P. n +…+P3, the first target text can be P2.
[0201] Step 820: Determine the target vector corresponding to the second training text, and adjust the target vector into a target update vector through weight increase processing. The weight increase processing is used to strengthen the connection between the first target text and the first training text.
[0202] Determining the target vector corresponding to the second training text may include: inputting the second training text into the embedding layer to obtain the target vector corresponding to the second training text, or using a matrix to transform the second training text into the corresponding target vector.
[0203] Once the target vector is determined, weighting can be performed based on loss, enhancement formula, or custom enhancement methods.
[0204] The weighting process can be implemented by the association layer; the specific weighting process can be found in [reference needed]. Figure 4 Partial description.
[0205] Step 830: Input the target update vector into the multi-turn dialogue model to be trained to obtain the second loss for the second training text;
[0206] In this embodiment, the target update vector can be used as the input to the multi-turn dialogue model to be trained. Based on the prediction result output by the multi-turn dialogue model and the true result corresponding to the second training text, a second loss is determined for the second training text. The true result corresponding to the second training text can be at least one text in the training text (e.g., a text adjacent to the second training text). The cross-entropy loss function or the maximum likelihood function can be used to determine the second loss.
[0207] Step 840: Based on the second loss, adjust the parameters of the multi-turn dialogue model to be trained to obtain the trained multi-turn dialogue model;
[0208] As described above, multiple different second training texts can be determined for the same training text. And based on the different second training texts, multiple second losses can be determined.
[0209] Adjusting the parameters of the multi-turn dialogue model to be trained based on the second loss may include: adjusting the parameters of the multi-turn dialogue model to be trained according to each second loss obtained, or adjusting the parameters of the multi-turn dialogue model to be trained by combining multiple second losses for different second training texts.
[0210] Step 850: Obtain a sixth training text from the training text containing multi-turn dialogues. The sixth training text includes a fifth training text and a fifth target text. The fifth training text and the sixth training text are both texts used to train the multi-turn dialogue model to be trained. The fifth target text is the real result corresponding to the fifth training text.
[0211] The fifth target text is a single text obtained from the first part of the training text in a forward-to-back order; the second part of the training text is denoted by F4; the first part includes y texts arranged in descending order from front to back: Q1...Q y Where y≥2; the fifth training text includes F4, and the sixth training text is F4+X4, where X4 is Q1 to Q d The third target text is Qd, where 1≤d≤y-1.
[0212] In this embodiment, after completing the forward and backward training, texts for training can be selected from the training texts in a forward-to-backward order to perform forward training on the multi-turn dialogue model to be trained. Specifically, when the sixth training text is F4+Q1, the fifth training text can be F4, and the fifth target text can be Q1. When the sixth training text is F4+Q1+Q2, the fifth training text can be F4+Q1, and the fifth target text can be Q2. When the sixth training text is F4+Q1+Q2+Q3, the fifth training text can be F4+Q1+Q2, and the fifth target text can be Q3. Following the pattern described above, when the sixth training text is F4+Q1+…+Q… y-1 At that time, the fifth training text can be F4+Q1+…+Q y-2 The fifth target text can be Q. y-1 .
[0213] Step 860: Determine the second specified vector corresponding to the sixth training text, and adjust the second specified vector into a second update vector through weight increase processing. The weight increase processing is used to strengthen the connection between the fifth target text and the fifth training text.
[0214] Determining the second specified vector corresponding to the sixth training text may include: inputting the sixth training text into the embedding layer to obtain the second specified vector corresponding to the sixth training text, or using a matrix to transform the sixth training text into the corresponding second specified vector.
[0215] After determining the second specified vector, weights can be increased based on the loss, enhancement formula, or custom enhancement method to obtain the second updated vector.
[0216] The weighting process can be implemented by the association layer; the specific weighting process can be found in [reference needed]. Figure 4 Partial description.
[0217] Step 870: Based on the second update vector, determine the sixth loss for the sixth training text;
[0218] In this embodiment, the second update vector can be used as the input to the multi-turn dialogue model to be trained. Based on the prediction result output by the multi-turn dialogue model and the real result corresponding to the sixth training text, a sixth loss is determined for the sixth training text. The real result corresponding to the sixth training text can be at least one text in the training text (e.g., a text adjacent to the sixth training text). The cross-entropy loss function or the maximum likelihood function can be used to determine the sixth loss.
[0219] Step 880: Based on the sixth loss, adjust the parameters of the trained multi-turn dialogue model.
[0220] As described above, multiple different sixth training texts can be determined for the same training text. And based on the different sixth training texts, multiple sixth losses can be determined.
[0221] Adjusting the parameters of the multi-turn dialogue model to be trained based on the sixth loss may include: adjusting the parameters of the multi-turn dialogue model to be trained according to each sixth loss obtained, or adjusting the parameters of the multi-turn dialogue model to be trained by combining multiple sixth losses for different sixth training texts.
[0222] The training method for the multi-turn dialogue model proposed in this application introduces a weighting process, which establishes connections between dialogue corpora in the same scene, facilitating the multi-turn dialogue model's full understanding of the context and improving prediction accuracy. Furthermore, it proposes a bidirectional training method, selecting texts in reverse order for model training. This improves the multi-turn dialogue model's ability to predict subsequent text based on preceding context during forward training, and enhances its ability to predict preceding text based on subsequent context during backward training. This strengthens the multi-turn dialogue model's understanding of the entire training text, further improving its prediction accuracy.
[0223] Since the loss corresponding to the fifth training text can reflect the prediction error of the multi-turn dialogue model and the degree of correlation between the fifth target text and the fifth training text as perceived by the multi-turn dialogue model, that is, the greater the loss, the weaker the correlation between the fifth target text and the fifth training text as perceived by the multi-turn dialogue model. Therefore, weighting based on the loss corresponding to the fifth training text can compensate for part of the prediction loss, which is beneficial for the multi-turn dialogue model to achieve better results in training. In one embodiment of this application, before obtaining the sixth training text from the training text containing multi-turn dialogue in step 850, the training method of the multi-turn dialogue model may further include: obtaining the fifth training text and the fifth target text from the training text; wherein, the fifth target text is at least one text adjacent to the fifth training text in the training text; obtaining the fifth prediction result corresponding to the fifth training text through the obtained trained multi-turn dialogue model; obtaining the fifth loss for the fifth training text based on the fifth prediction result and the fifth target text; the step of adjusting the second specified vector to the second update vector through weighting includes: adjusting the second specified vector to the second update vector through weighting based on the fifth loss. Thus, by using the fifth loss corresponding to the fifth training text to increase the weights, the connection between the fifth target text and the fifth training text is strengthened. The prediction results of the current round can be fed back into the input data of the next round, making up for the prediction error of the multi-round dialogue model. This strengthens the multi-round dialogue model's attention to important texts in the fifth training text, which is conducive to improving the prediction accuracy.
[0224] Referring to the description above, the fifth training text can be F4, F4+Q1, F4+Q1+Q2, ..., F4+Q1+...+Q y-2 The fifth target text that matches it can be Q1, Q2, Q3, ..., Q... y-1 .
[0225] After obtaining the fifth training text, the fifth training text or the vector corresponding to the fifth training text can be input into the multi-turn dialogue model. Based on the output of the multi-turn dialogue model, the fifth prediction result corresponding to the fifth training text can be obtained.
[0226] After determining the fifth prediction result and the fifth target text, the fifth prediction result and the fifth target text can be substituted into the cross-entropy loss function or the maximum likelihood function to calculate the fifth loss for the fifth training text.
[0227] Based on the fifth loss, weighting can be performed to adjust the vector corresponding to the fifth training text in the target vector, amplify the similarity words between the fifth training text and the fifth target text, and adjust the second specified vector to the second update vector.
[0228] To avoid the bias of updating model parameters based solely on a single prediction result, the parameters of the multi-turn dialogue model can be updated by combining multiple prediction results for the same dialogue scenario during actual training. In one embodiment of this application, the y texts in the first part correspond to y true results, and the fifth true result is one of the y true results. Step 880, adjusting the parameters of the multi-turn dialogue model based on the sixth loss, includes: calculating a loss once for each of the y texts to obtain y losses; wherein the fifth loss and the sixth loss are both one of the y losses; determining the average value of the y losses; and adjusting the parameters of the multi-turn dialogue model based on the average value. In this way, the parameters of the multi-turn dialogue model can be comprehensively optimized by using the multi-turn prediction result losses to simulate multi-turn interaction scenarios, enabling the multi-turn dialogue model to possess comprehensive judgment capabilities and patterns for multi-turn dialogue.
[0229] The y losses can be multiple losses obtained from the fifth and sixth training texts. Specifically, a fifth loss can be obtained based on the prediction result of the multi-turn dialogue model output for the fifth training text F4 and the true result Q1 in the first part. A sixth loss can be obtained based on the prediction result of the multi-turn dialogue model output for the sixth training text F4+Q1 and the true result Q2 in the first part. A sixth loss can be obtained based on the prediction result of the multi-turn dialogue model output for the fourth training text F4+Q1+Q2 and the true result Q3 in the first part. ... A sixth loss can be obtained based on the multi-turn dialogue model output for the sixth training text F4+Q1+...+Q y-1 The predicted results and the actual results in Part 1 Q y Thus, a sixth loss can be obtained. Therefore, training on a training text containing multi-turn dialogues can yield y losses.
[0230] After determining the average value of y losses, the average value can be used directly to adjust the parameters of the multi-turn dialogue model to be trained, or the average value can be used as the sum of the average value and a constant selected based on experience to adjust the parameters of the multi-turn dialogue model to be trained.
[0231] Figure 9 This is a flowchart of a multi-turn dialogue prediction method provided in an embodiment of this application. Figure 9 As shown, the multi-turn dialogue prediction method provided in this application embodiment may include the following steps:
[0232] Step 910: Obtain the feature vector corresponding to the target text, where the target text is the text to be predicted in a multi-turn dialogue.
[0233] The target text may include dialogue text generated in at least one multi-turn dialogue scenario. In the embodiments of this application, the target text can be input into an embedding layer to obtain the feature vector corresponding to the target text, or a matrix can be used to transform the target text into the corresponding feature vector.
[0234] Step 920: Input the feature vector corresponding to the target text into the trained multi-turn dialogue model.
[0235] The trained multi-turn dialogue model can be a pre-trained multi-turn dialogue model; a pre-trained multi-turn dialogue model can include a model that has been pre-trained multiple times based on a training dataset and has good performance in dialogue prediction.
[0236] After inputting the feature vector corresponding to the target text into the trained multi-turn dialogue model, the trained multi-turn dialogue model can perform subsequent operations.
[0237] Step 930: Perform dialogue prediction processing on the feature vector using the trained multi-turn dialogue model, and output the dialogue prediction result that matches the target text.
[0238] The trained multi-turn dialogue model is obtained using any of the multi-turn dialogue model training methods described above.
[0239] The multi-turn dialogue prediction method provided in this application uses a pre-trained multi-turn dialogue model to predict dialogue from target text, enabling rapid output of prediction results. Furthermore, because weight augmentation is introduced during the training of the multi-turn dialogue model, and this weight augmentation strengthens the connection between the first training text and its corresponding first real result, it allows for a close connection between the preceding and following dialogue texts within the same multi-turn dialogue scenario. This helps the multi-turn dialogue model to re-understand contextual information, resulting in higher accuracy in dialogue prediction from the pre-trained multi-turn dialogue model.
[0240] Figure 10 This is a training device for a multi-turn dialogue model provided in an embodiment of this application. For example... Figure 10 As shown, the training device 1000 for the multi-turn dialogue model provided in this application embodiment includes: an acquisition module 1010, a determination module 1020, and an adjustment module 1030.
[0241] The acquisition module 1010 is used to acquire a second training text from training text containing multi-turn dialogues. The second training text includes a first training text and a first target text. The first training text and the second training text are both texts used to train the multi-turn dialogue model to be trained. The first target text is the first real result corresponding to the first training text, and the first target text is at least one text in the training text that is adjacent to the first training text.
[0242] The determining module 1020 is used to determine the target vector corresponding to the second training text, and adjust the target vector into a target update vector through weight increase processing, the weight increase processing being used to strengthen the connection between the first target text and the first training text; input the target update vector into the multi-turn dialogue model to be trained to obtain a second loss for the second training text;
[0243] The adjustment module 1030 is used to adjust the parameters of the multi-turn dialogue model to be trained based on the second loss, so as to obtain the trained multi-turn dialogue model.
[0244] The training apparatus for the multi-turn dialogue model provided in this application introduces weight amplification processing during the training process of the multi-turn dialogue model. By strengthening the connection between the first training text and the first real result corresponding to the first training text through weight amplification processing, it can achieve close connection between the preceding and following dialogue texts in the same multi-turn dialogue scenario. This allows the multi-turn dialogue model to focus on the content in the first training text that is related to the first real result during the training process, and to re-understand the contextual information in the training text. This is beneficial for the multi-turn dialogue model to accurately predict subsequent sentences, and can thus solve the problem of low accuracy in prediction of multi-turn dialogue models in related technologies to a certain extent.
[0245] Optionally, in one embodiment of this application, the acquisition module 1010 is further configured to: acquire a first prediction result corresponding to the first training text through the multi-turn dialogue model to be trained; acquire a first loss for the first training text based on the first prediction result and the first target text; and in the process of adjusting the target vector into a target update vector through weight increase processing, the determination module 1020 is specifically configured to: adjust the target vector into a target update vector through weight increase processing based on the first loss.
[0246] Optionally, in one embodiment of this application, during the process of adjusting the target vector into a target update vector through weight augmentation processing based on the first loss, the determining module 1020 is specifically configured to: determine the similarity between the first target text and each sentence in the first training text to obtain S similarity weight sequences, wherein the first training text includes S texts, and S is a positive integer; perform weight augmentation processing on the S similarity weight sequences based on the first loss to obtain S target similarity weight sequences; multiply the vector to be updated in the target vector with the respective target similarity weight sequences in the S target similarity weight sequences to obtain the target update vector; wherein the vector to be updated is all or part of the vectors in the target vector that satisfy the specified conditions.
[0247] Optionally, in one embodiment of this application, during the process of increasing the weights of the S similarity weight sequences based on the first loss to obtain S target similarity weight sequences, the determining module 1020 is specifically used to: for each of the S similarity weight sequences, increase the weights using the following formula: V2 = V1 + (1 - Nmax) * L1 to obtain S target similarity weight sequences; where V1 is a specified value in the similarity weight sequence, the specified value is a weight value greater than a threshold, V2 is the weight value obtained after increasing the weights of V1, Nmax is the maximum weight value in the similarity weight sequence, and L1 is the first loss.
[0248] Optionally, in one embodiment of this application, the training text consists of a first part and a second part, wherein the first training text includes all the content of the first part; and the first target text is a text obtained from the second part of the training text in a forward-to-back order.
[0249] Optionally, in one embodiment of this application, the training text consists of a first part and a second part, wherein the first training text includes all the content of the first part; and the first target text is a text obtained from the second part of the training text in reverse chronological order.
[0250] Optionally, in one embodiment of this application, the training text is divided into a first part and a second part in order from front to back; the first part of the training text is denoted by F1; the second part includes n texts arranged in ascending order from front to back: P1...Pn, where n≥2; the first training text includes F1, the second training text is F1+X1, X1 is P1 to Pi, the first target text is Pi, where 1≤i≤n-1.
[0251] Optionally, in one embodiment of this application, the training text is divided into a first part and a second part in reverse order from back to front; the first part of the training text is denoted by F2; the second part includes n texts arranged in descending order from back to front: Pn...P1, where n≥2; the first training text includes F2, the second training text is F2+X2, X2 is Pn to Pi, the first target text is Pi, where 2≤i≤n.
[0252] Optionally, in one embodiment of this application, the first part includes the first half of the training text.
[0253] Optionally, in one embodiment of this application, the first part includes the latter half of the training text.
[0254] Optionally, in one embodiment of this application, the n texts in the second part correspond to n real results, and the first real result is one of the n real results. In the process of adjusting the parameters of the multi-turn dialogue model to be trained based on the second loss to obtain the trained multi-turn dialogue model, the adjustment module 1030 is specifically used to: calculate the loss once for each of the n texts to obtain n losses; wherein, the first loss and the second loss for the first training text are both one of the n losses; determine the average value of the n losses; and adjust the parameters of the multi-turn dialogue model based on the average value.
[0255] Optionally, in one embodiment of this application, during the process of inputting the target update vector into the multi-turn dialogue model to be trained to obtain the second loss for the second training text, the determining module 1020 is specifically used to: input the target update vector into the multi-turn dialogue model to obtain the second prediction result corresponding to the second training text; and obtain the second loss for the second training text based on the second prediction result and the second target text; wherein the second target text is the second true result corresponding to the second training text, and the second target text is adjacent to the first target text.
[0256] Optionally, in one embodiment of this application, after adjusting the parameters of the multi-turn dialogue model to be trained based on the second loss to obtain the trained multi-turn dialogue model, the acquisition module 1010 is further configured to: acquire a fourth training text from the training text containing multi-turn dialogue, the fourth training text including a third training text and a third target text; wherein, the third training text and the fourth training text are both texts used to train the multi-turn dialogue model to be trained, and the third target text is the real result corresponding to the third training text; the determination module 1020 is further configured to: determine a first specified vector corresponding to the fourth training text, and adjust the first specified vector to a first update vector through weight increase processing, wherein the weight increase... The processing is used to strengthen the connection between the third target text and the third training text; based on the first update vector, a fourth loss is determined for the fourth training text; the adjustment module 1030 is further used to adjust the parameters of the multi-turn dialogue model based on the fourth loss; wherein, the third target text is a text obtained from the first part of the training text in reverse chronological order; wherein, the second part of the training text is denoted by F3; the first part includes m texts arranged in descending order from back to front: Km...K1, where m≥2; the third training text includes F3, the fourth training text is F3+X3, X3 is Km to Kj, the third target text is Kj, where 2≤j≤m.
[0257] Optionally, in one embodiment of this application, before obtaining the fourth training text from the training text containing multi-turn dialogue, the obtaining module 1010 is further configured to: obtain a third training text and a third target text from the training text; wherein, the third target text is at least one text adjacent to the third training text in the training text; obtain a third prediction result corresponding to the third training text through the obtained trained multi-turn dialogue model; obtain a third loss for the third training text based on the third prediction result and the third target text; in the process of adjusting the first specified vector to the first update vector through weight increase processing, the determining module 1020 is specifically configured to: adjust the first specified vector to the first update vector through weight increase processing based on the third loss.
[0258] Optionally, in one embodiment of this application, the m texts in the first part correspond to m real results, and the third real result is one of the m real results. In the process of adjusting the parameters of the multi-turn dialogue model based on the fourth loss, the adjustment module 1030 is specifically used to: calculate a loss once for each of the m texts to obtain m losses; wherein the third loss and the fourth loss are both one of the m losses; determine the average value of the m losses; and adjust the parameters of the multi-turn dialogue model based on the average value.
[0259] Optionally, in one embodiment of this application, after adjusting the parameters of the multi-turn dialogue model to be trained based on the second loss to obtain the trained multi-turn dialogue model, the acquisition module 1010 is further configured to: acquire a sixth training text from the training text containing multi-turn dialogue, the sixth training text including a fifth training text and a fifth target text; wherein, the fifth training text and the sixth training text are both texts used to train the multi-turn dialogue model to be trained, and the fifth target text is the real result corresponding to the fifth training text; the determination module 1020 is further configured to: determine a second specified vector corresponding to the sixth training text, and adjust the second specified vector to a second update vector through weight increase processing, wherein the weight increase processing... The adjustment module 1030 is used to strengthen the connection between the fifth target text and the fifth training text; based on the second update vector, a sixth loss is determined for the sixth training text; the adjustment module 1030 is further used to adjust the parameters of the multi-turn dialogue model based on the sixth loss; wherein, the fifth target text is a text obtained from the first part of the training text in a forward-to-back order; wherein, the second part of the training text is represented by F4; the first part includes y texts arranged in descending order from front to back: Q1...Qy, where y≥2; the fifth training text includes F4, the sixth training text is F4+X4, X4 is Q1 to Qd, the third target text is Qd, where 1≤d≤y-1.
[0260] Optionally, in one embodiment of this application, before obtaining the sixth training text from the training text containing multi-turn dialogue, the obtaining module 1010 is further configured to: obtain a fifth training text and a fifth target text from the training text; wherein, the fifth target text is at least one text in the training text that is adjacent to the fifth training text; obtain a fifth prediction result corresponding to the fifth training text through the obtained trained multi-turn dialogue model; obtain a fifth loss for the fifth training text based on the fifth prediction result and the fifth target text; in the process of adjusting the second specified vector to the second update vector through weight increase processing, the determining module 1020 is specifically configured to: adjust the second specified vector to the second update vector through weight increase processing based on the fifth loss.
[0261] Optionally, in one embodiment of this application, the y texts in the first part correspond to y real results, and the fifth real result is one of the y real results. In the process of adjusting the parameters of the multi-turn dialogue model based on the sixth loss, the adjustment module 1030 is specifically used to: calculate a loss once for each of the y texts to obtain y losses; wherein the fifth loss and the sixth loss are both one of the y losses; determine the average value of the y losses; and adjust the parameters of the multi-turn dialogue model based on the average value.
[0262] Figure 11 This is a structural block diagram of a multi-turn dialogue prediction device provided in an embodiment of this application. Figure 11 As shown, the multi-turn dialogue prediction device provided in this application embodiment includes: an acquisition module 1110, an input module 1120, and a processing module 1130.
[0263] The acquisition module 1110 is used to acquire the feature vector corresponding to the target text, wherein the target text is the text to be predicted in a multi-turn dialogue.
[0264] The input module 1120 is used to input the feature vector corresponding to the target text into the trained multi-turn dialogue model, wherein the trained multi-turn dialogue model is a pre-trained multi-turn dialogue model.
[0265] The processing module 1130 is used to perform dialogue prediction processing on the feature vector through the trained multi-turn dialogue model, and output a dialogue prediction result that matches the target text.
[0266] The trained multi-turn dialogue model is obtained using any of the multi-turn dialogue model training methods provided in this application.
[0267] The multi-turn dialogue prediction method provided in this application uses a pre-trained multi-turn dialogue model to predict dialogue from target text, enabling rapid output of prediction results. Furthermore, because weight augmentation is introduced during the training of the multi-turn dialogue model, and this weight augmentation strengthens the connection between the first training text and its corresponding first real result, it allows for a close connection between the preceding and following dialogue texts within the same multi-turn dialogue scenario. This helps the multi-turn dialogue model to re-understand contextual information, resulting in higher accuracy in dialogue prediction from the pre-trained multi-turn dialogue model.
[0268] In addition, such as Figure 12 As shown in the figure, this application embodiment also provides an electronic device 1200, which can be various types of computers, etc. The electronic device 1200 includes: a processor 1210 and a memory 1220, wherein the memory 1220 stores programs or instructions, and when the programs or instructions are executed by the processor 1210, they implement the steps of any of the methods described above.
[0269] This application also provides a readable storage medium on which a program or instructions are stored, which, when executed by the processor, implement the steps of any of the methods described above.
[0270] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0271] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0272] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0273] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0274] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0275] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0276] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0277] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0278] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0279] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A training method for a multi-turn dialogue model, characterized in that, include: Obtain a second training text from the training text containing multi-turn dialogues. The second training text includes a first training text and a first target text. The second training text is used to train the multi-turn dialogue model to be trained. The first target text is the first real result corresponding to the first training text. The first target text is at least one text in the training text that is adjacent to the first training text. The first prediction result corresponding to the first training text is obtained through the multi-turn dialogue model to be trained; Based on the first prediction result and the first target text, obtain the first loss for the first training text; The target vector corresponding to the second training text is determined, and the target vector is adjusted to a target update vector by weighting the first loss. The weighting process is used to strengthen the connection between the first target text and the first training text. Input the target update vector into the multi-turn dialogue model to be trained to obtain a second loss for the second training text; Based on the second loss, the parameters of the multi-turn dialogue model to be trained are adjusted to obtain the trained multi-turn dialogue model.
2. The method according to claim 1, characterized in that, The step of adjusting the target vector into a target update vector through weight augmentation based on the first loss includes: Determine the similarity between the first target text and each sentence in the first training text to obtain S similarity weight sequences, where the first training text includes S texts and S is a positive integer; Based on the first loss, the S similarity weight sequences are weighted to obtain S target similarity weight sequences. The target update vector is obtained by multiplying the vector to be updated in the target vector with the respective target similarity weight sequences in the S target similarity weight sequences; Wherein, the vector to be updated is all or part of the target vectors that satisfy the specified conditions.
3. The method according to claim 2, characterized in that, The step of weighting the S similarity weight sequences based on the first loss to obtain S target similarity weight sequences includes: For each of the S similarity weight sequences, the following formula applies: V2 = V1 + (1 - N) max ) L1 is processed by weighting to obtain S target similarity weight sequences; Wherein, V1 is a specified value in the similarity weight sequence, the specified value being a weight value greater than a threshold, V2 is the weight value obtained after weighting V1, and N... max L1 is the maximum weight value in the similarity weight sequence, and L1 is the first loss.
4. The method according to claim 1, characterized in that, The training text consists of a first part and a second part, wherein the first training text includes all the contents of the first part; The first target text is a text obtained from the second part in a forward-to-back order, or the first target text is a text obtained from the second part in a backward-to-forward order.
5. The method according to claim 4, characterized in that, The training text is divided into two parts in order from front to back; The first part of the training text is denoted by F1; The second part consists of n texts arranged in ascending order from front to back: P1...P n where n≥2; The first training text includes F1, and the second training text is F1+X1, where X1 is P1 to P2. i The first target text is P i , Where 1≤i≤n-1.
6. The method according to claim 4, characterized in that, The training text is divided into a first part and a second part in reverse order from back to front; the first part of the training text is represented by F2. The second part consists of n texts arranged in descending order from back to front: P n ...P1, where n≥2; The first training text includes F2, and the second training text is F2+X2, where X2 is P. n To P i The first target text is P i , Where 2≤i≤n.
7. The method according to claim 5 or 6, characterized in that, The first part includes the first half of the training text, or the first part includes the second half of the training text.
8. The method according to claim 5 or 6, characterized in that, The n texts in the second part correspond to n true results, and the first true result is one of the n true results. The step of adjusting the parameters of the multi-turn dialogue model to be trained based on the second loss includes: By calculating the loss once for each of the n texts, n losses are obtained; wherein, the first loss and the second loss for the first training text are both one of the n losses; Determine the average value of the n losses, including the second loss; Based on the average value, the parameters of the multi-turn dialogue model are adjusted.
9. The method according to claim 1, characterized in that, The step of inputting the target update vector into the multi-turn dialogue model to be trained to obtain a second loss for the second training text includes: Input the target update vector into the multi-turn dialogue model to be trained to obtain the second prediction result corresponding to the second training text; Based on the second prediction result and the second target text, obtain the second loss for the second training text; Wherein, the second target text is the second true result corresponding to the second training text, and the second target text is adjacent to the first target text.
10. The method according to claim 5, characterized in that, After adjusting the parameters of the multi-turn dialogue model to be trained based on the second loss to obtain the trained multi-turn dialogue model, the method further includes: A fourth training text is obtained from the training text containing multi-turn dialogues. The fourth training text includes a third training text and a third target text. The third training text and the fourth training text are both texts used to train the multi-turn dialogue model to be trained. The third target text is the real result corresponding to the third training text. A first specified vector corresponding to the fourth training text is determined, and the first specified vector is adjusted to a first update vector through weight increase processing. The weight increase processing is used to strengthen the connection between the third target text and the third training text. Based on the first update vector, a fourth loss is determined for the fourth training text; Based on the fourth loss, the parameters of the trained multi-turn dialogue model are adjusted. The third target text is a text obtained from the first part of the training text in reverse chronological order; The second part of the training text is denoted by F3; the first part includes m texts arranged in descending order from back to front: K m ...K1, where m≥2; The third training text includes F3, and the fourth training text is F3+X3, where X3 is K. m To K j The third target text is K. j , Where 2≤j≤m.
11. The method according to claim 10, characterized in that, Before obtaining the fourth training text from the training text containing multi-turn dialogues, the method further includes: Obtain a third training text and a third target text from the training text; wherein, the third target text is at least one text in the training text that is adjacent to the third training text; The third prediction result corresponding to the third training text is obtained by using the trained multi-turn dialogue model. Based on the third prediction result and the third target text, a third loss is obtained for the third training text; The step of adjusting the first specified vector to the first update vector through weight increase processing includes: adjusting the first specified vector to the first update vector through weight increase processing based on the third loss.
12. The method according to claim 11, characterized in that, The m texts in the first part correspond to m real results, and the third target text is one of the m real results. The adjustment of the parameters of the multi-turn dialogue model based on the fourth loss includes: By calculating the loss once for each of the m texts, m losses are obtained; wherein the third loss and the fourth loss are both one of the m losses. Determine the average value of the m losses; Based on the average value, the parameters of the multi-turn dialogue model are adjusted.
13. The method according to claim 6, characterized in that, After adjusting the parameters of the multi-turn dialogue model to be trained based on the second loss to obtain the trained multi-turn dialogue model, the method further includes: A sixth training text is obtained from the training text containing multi-turn dialogues. The sixth training text includes a fifth training text and a fifth target text. The fifth training text and the sixth training text are both texts used to train the multi-turn dialogue model to be trained. The fifth target text is the real result corresponding to the fifth training text. A second specified vector corresponding to the sixth training text is determined, and the second specified vector is adjusted to a second update vector through weight increase processing. The weight increase processing is used to strengthen the connection between the fifth target text and the fifth training text. Based on the second update vector, a sixth loss is determined for the sixth training text; Based on the sixth loss, the parameters of the trained multi-turn dialogue model are adjusted. The fifth target text is a text obtained from the first part of the training text in a forward-to-back order; The second part of the training text is denoted by F4; the first part includes y texts arranged in descending order from front to back: Q1...Q y , where y≥2; The fifth training text includes F4, and the sixth training text is F4+X4, where X4 is Q1 to Q. d The fifth target text is Q. d , Where 1≤d≤y-1.
14. The method according to claim 13, characterized in that, Before obtaining the sixth training text from the training text containing multi-turn dialogues, the method further includes: Obtain a fifth training text and a fifth target text from the training text; wherein, the fifth target text is at least one text in the training text that is adjacent to the fifth training text; The fifth prediction result corresponding to the fifth training text is obtained by using the trained multi-turn dialogue model. Based on the fifth prediction result and the fifth target text, obtain the fifth loss for the fifth training text; The step of adjusting the second specified vector into the second updated vector through weight increase processing includes: adjusting the second specified vector into the second updated vector through weight increase processing based on the fifth loss.
15. The method according to claim 14, characterized in that, In the first part, y texts correspond to y real results, and the fifth target text is one of the y real results. The adjustment of the parameters of the multi-turn dialogue model based on the sixth loss includes: By calculating the loss once for each of the y texts, y losses are obtained; wherein, the fifth loss and the sixth loss are both one of the y losses; Determine the average value of the y losses; Based on the average value, the parameters of the multi-turn dialogue model are adjusted.
16. A multi-turn dialogue prediction method, characterized in that, include: Obtain the feature vector corresponding to the target text, where the target text is the text to be predicted in a multi-turn dialogue. The feature vector corresponding to the target text is input into the trained multi-turn dialogue model. The trained multi-turn dialogue model performs dialogue prediction processing on the feature vector and outputs a dialogue prediction result that matches the target text. The trained multi-turn dialogue model is obtained using the training method according to any one of claims 1-15.
17. An electronic device, characterized in that, It includes a processor and a memory, the memory storing a program or instructions that, when executed by the processor, implement the steps of the training method for the multi-turn dialogue model as described in any one of claims 1-15 or the multi-turn dialogue prediction method as described in claim 16.
18. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the training method for a multi-turn dialogue model as described in any one of claims 1-15 or the multi-turn dialogue prediction method as described in claim 16.
Citation Information
Patent Citations
Local information perception dialogue method and system based on pre-training language model
CN114443827A