An adversarial training method for a retrieval-style multi-round dialogue model and related devices

CN116450780BActive Publication Date: 2026-08-07TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
TENCENT TECHNOLOGY (SHENZHEN) CO LTD
Filing Date
2021-12-28
Publication Date
2026-08-07

AI Technical Summary

Technical Problem

[0004]然而,如果在输入检索式多轮对话模型的提问文本中添加轻微的扰动,就会导致检索式多轮对话模型输出错误的目标回复文本,因此,现有的检索式多轮对话模型很容易被欺骗或遭受攻击,模型稳定性及泛化能力均较差

Benefits of technology

本申请实施例提供了一种检索式多轮对话模型的对抗训练方法及相关装置,在获取到检索式多轮对话模型对应的提问样本集合和回复样本集合后,可以针对提问样本集合中的各个提问样本分别进行关键语素转换,生成相应的语素对抗样本集合,并对各个提问样本进行样本顺序变换,生成相应的语序对抗样本集合,以及针对回复样本集合中的各个回复样本,分别获取与每个回复样本之间,存在语义差异且文本相似度符合设定文本条件的至少一个回复对抗样本,生成相应的回复对抗样本集合,最后基于语素对抗样本集合、语序对抗样本集合、回复对抗样本集合,对检索式多轮对话模型进行对抗训练,输出相应的目标模型。由于从多个层面对检索式多轮对话模型进行攻击,生成相应的对抗样本集合,并采用生成的对抗样本集合,对检索式多轮对话模型进行对抗训练,从而使得经过对抗训练后的检索式多轮对话模型不易受到欺骗和遭受攻击,增强了检索式多轮对话模型的泛化能力和鲁棒性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116450780B_ABST
    Figure CN116450780B_ABST
Patent Text Reader

Abstract

The application provides an adversarial training method of a retrieval type multi-round dialogue model and related devices, and relates to the technical field of computers. After obtaining a question sample set and a reply sample set, key morpheme conversion is performed on each question sample in the question sample set to generate a corresponding morpheme adversarial sample set, and sample order transformation is performed on each question sample to generate a corresponding syntactic adversarial sample set. At least one reply adversarial sample that exists a semantic difference and has a text similarity meeting a set text condition with each reply sample in the reply sample set is obtained, a corresponding reply adversarial sample set is generated, an adversarial training is performed on the retrieval type multi-round dialogue model based on the obtained adversarial sample set, and a corresponding target model is output. Thus, the generated adversarial sample set of multiple levels can be used to perform adversarial training on the retrieval type multi-round dialogue model, and the generalization ability and robustness of the retrieval type multi-round dialogue model can be enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to an adversarial training method and related apparatus for a retrieval-based multi-turn dialogue model. Background Technology

[0002] Retrieval-based multi-turn dialogue refers to selecting the optimal statement from a candidate corpus as the response of a chatbot based on the question text. It has the advantages of large information content and high fluency.

[0003] Specifically, the retrieval-based multi-turn dialogue method involves inputting the question text into a retrieval-based multi-turn dialogue model, performing text matching between the question text and each candidate response text in the candidate corpus based on the retrieval-based multi-turn dialogue model, and selecting the optimal response text from each candidate response text as the target response text corresponding to the dialogue context based on the matching results.

[0004] However, if a slight perturbation is added to the question text input to the retrieval-based multi-turn dialogue model, the retrieval-based multi-turn dialogue model will output the wrong target response text. Therefore, existing retrieval-based multi-turn dialogue models are easily fooled or attacked, and the model stability and generalization ability are poor.

[0005] For example, if the original question text is "How is the weather today?", the retrieval-based multi-turn dialogue model will output the response text "The weather is very nice today". If the original question text is changed to "How is the weather today?", the retrieval-based multi-turn dialogue model will output the response text "Today is Monday". Summary of the Invention

[0006] This application provides an adversarial training method and related apparatus for a retrieval-based multi-turn dialogue model, which can enhance the generalization ability and robustness of the retrieval-based multi-turn dialogue model.

[0007] The specific technical solutions provided in this application are as follows: Adversarial training of a retrieval-based multi-turn dialogue model includes: Obtain the question sample set and the response sample set; For each question sample in the question sample set, key morphemes are transformed to generate a corresponding morpheme adversarial sample set, and the sample order of each question sample is transformed to generate a corresponding word order adversarial sample set. For each response sample in the response sample set, at least one corresponding response adversarial sample is obtained to generate a corresponding response adversarial sample set. Each response adversarial sample and the corresponding response sample have semantic differences and their text similarity meets the set text conditions. Based on the set of adversarial samples of morphemes, the set of adversarial samples of word order, and the set of adversarial samples of responses, the retrieval-based multi-turn dialogue model is trained adversarially, and the corresponding target model is output.

[0008] An adversarial training device for a retrieval-based multi-turn dialogue model includes: The collection acquisition module is used to acquire the question sample collection and the response sample collection; The first adversarial sample generation module is used to perform key morpheme transformation on each question sample in the question sample set to generate a corresponding morpheme adversarial sample set, and to perform sample order transformation on each question sample to generate a corresponding word order adversarial sample set. The second adversarial sample generation module is used to obtain at least one corresponding adversarial sample for each response sample in the response sample set and generate a corresponding response adversarial sample set, wherein each response adversarial sample and the corresponding response sample have semantic differences and the text similarity meets the set text conditions. The model adversarial training module is used to perform adversarial training on the retrieval-based multi-turn dialogue model based on the morpheme adversarial sample set, the word order adversarial sample set, and the response adversarial sample set, and output the corresponding target model.

[0009] Optionally, the first adversarial example generation module is specifically used for: For each question sample in the question sample set, perform at least one of the following operations: Identify the words contained in a question sample, and replace each word with a synonym to obtain the morpheme adversarial sample corresponding to the question sample; The source language and target language associated with the question sample are determined, and the question sample is translated from the source language to the target language to obtain the corresponding intermediate question sample. The intermediate question sample is then translated from the target language back to the source language to obtain the morpheme adversarial sample corresponding to the intermediate question sample.

[0010] Optionally, the first adversarial example generation module is further configured to: For each of the aforementioned words, perform the following operations respectively: Obtain at least one candidate word corresponding to a given word, wherein the at least one candidate word is obtained based on the context of the given question sample; Determine the semantic information corresponding to each of the at least one candidate word and the semantic similarity between them and the semantic information corresponding to the word; From the at least one candidate word, select one candidate word whose semantic similarity meets the set semantic conditions, and use it as the synonym of the one word; Replace the word with the synonym.

[0011] Optionally, the first adversarial example generation module is further configured to: Determine the original sample order of each question sample in the question sample set, and perform a random sample order transformation on the original sample order to obtain the target sample order; Each question sample, sorted according to the order of the target sample, is used as a set of adversarial sample orders.

[0012] Optionally, the second adversarial example generation module is specifically used for: For each response sample in the aforementioned response sample set, perform the following operations: Obtain at least one candidate text sample corresponding to a response sample; wherein the semantic similarity between the semantic information corresponding to each candidate text sample and the semantic information corresponding to the response sample meets the set semantic conditions; Determine the text similarity between the at least one candidate text sample and the one response sample; From the at least one candidate text sample, at least one response adversarial sample whose text similarity meets the set text conditions is selected.

[0013] Optionally, the model adversarial training module is specifically used for: Based on the morpheme adversarial sample set and the word order adversarial sample set, a question adversarial sample set is obtained; Based on the set of adversarial questions and the set of adversarial responses, the retrieval-based multi-turn dialogue model is iteratively trained until a set convergence condition is met. One iteration of the training process includes: Based on the question adversarial samples extracted from the question adversarial sample set and at least one response adversarial sample extracted from the response adversarial sample set, the retrieval-based multi-turn dialogue model performs text matching between the question adversarial samples and the at least one response adversarial sample to determine the corresponding matching results; the corresponding loss value is determined based on the matching results, and the parameters of the retrieval-based multi-turn dialogue model are adjusted based on the loss value. The retrieval-based multi-turn dialogue model with the adjusted parameters is used as the corresponding target model.

[0014] An electronic device provided in this application includes a processor and a memory, wherein the memory stores program code, and when the program code is executed by the processor, the processor performs the steps of any of the above-described adversarial training methods for a retrieval-based multi-turn dialogue model.

[0015] This application provides a computer-readable storage medium including program code. When the program code is run on an electronic device, the program code is used to cause the electronic device to perform the steps of any of the above-described adversarial training methods for a retrieval-based multi-turn dialogue model.

[0016] This application provides a computer program product, including a computer program / instruction, which, when run on a computer, causes the computer to execute the adversarial training method of the above-described retrieval-based multi-turn dialogue model.

[0017] The beneficial effects of this application are as follows: This application provides an adversarial training method and related apparatus for a retrieval-based multi-turn dialogue model. After obtaining the question sample set and response sample set corresponding to the retrieval-based multi-turn dialogue model, key morpheme transformations can be performed on each question sample in the question sample set to generate a corresponding morpheme adversarial sample set. The sample order of each question sample can be transformed to generate a corresponding word order adversarial sample set. For each response sample in the response sample set, at least one response adversarial sample with semantic differences and text similarity meeting set conditions can be obtained to generate a corresponding response adversarial sample set. Finally, adversarial training is performed on the retrieval-based multi-turn dialogue model based on the morpheme adversarial sample set, word order adversarial sample set, and response adversarial sample set to output the corresponding target model. Because the retrieval-based multi-turn dialogue model is attacked from multiple levels, generating corresponding adversarial sample sets, and then using these generated adversarial sample sets for adversarial training, the adversarially trained retrieval-based multi-turn dialogue model is less susceptible to deception and attacks, thus enhancing its generalization ability and robustness.

[0018] Other features and advantages of this application will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the application. The objectives and other advantages of this application may be realized and obtained by means of the structures particularly pointed out in the written description, claims, and drawings. Attached Figure Description

[0019] Figure 1 This is a schematic diagram illustrating the application scenario in the embodiments of this application; Figure 2aThis is a flowchart illustrating the adversarial training method for a retrieval-based multi-turn dialogue model in an embodiment of this application. Figure 2b This is a schematic diagram illustrating the determination of the response adversarial sample corresponding to the response sample in an embodiment of this application; Figure 3 This is a schematic diagram illustrating the process of adversarial training of a retrieval-based multi-turn dialogue model in an embodiment of this application. Figure 4 This is a flowchart illustrating the process of determining the adversarial sample corresponding to the response sample in an embodiment of this application. Figure 5 This is a schematic diagram of the encoder structure in an embodiment of this application; Figure 6a This is a schematic diagram of the overall process of the adversarial training method for the retrieval-based multi-turn dialogue model in the embodiments of this application. Figure 6b This is a logical diagram illustrating the determination of adversarial morpheme samples corresponding to question samples in an embodiment of this application. Figure 6c This is another logical diagram illustrating the determination of adversarial morpheme samples corresponding to question samples in the embodiments of this application; Figure 6d This is a logical diagram illustrating the determination of the set of adversarial sentences corresponding to the set of question samples in this application embodiment; Figure 6e This is a logical diagram illustrating the determination of the response adversarial sample corresponding to the response sample in an embodiment of this application; Figure 7 This is a schematic diagram of the adversarial training device for the retrieval-based multi-turn dialogue model in the embodiments of this application; Figure 8 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application; Figure 9 This is a schematic diagram of the structure of another electronic device in an embodiment of this application. Detailed Implementation

[0020] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings of the embodiments of this application. Obviously, the described embodiments are only some embodiments of the technical solutions of this application, and not all embodiments. Based on the embodiments recorded in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the technical solutions of this application.

[0021] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the invention described herein can be implemented in sequences other than those illustrated or described herein.

[0022] The following explanations of some terms used in the embodiments of this application are provided to facilitate understanding by those skilled in the art.

[0023] Adversarial examples: Attackers can create slight perturbations to interfere with input samples, causing the model to output arbitrary incorrect results that the attacker wants. Such offensive input samples are called adversarial examples, that is, samples that cause the model to make misjudgments.

[0024] Adversarial training: The process of retraining an already trained model using adversarial examples as training data.

[0025] The word “exemplary” as used below means “serving as an example, embodiment, or illustration.” Any embodiment illustrated as an “exemplary” need not be construed as superior to or better than other embodiments.

[0026] The terms "first" and "second" used in this document are for descriptive purposes only and should not be construed as indicating relative importance or implying the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.

[0027] The design concept of the embodiments of this application is briefly introduced below: The retrieval-based multi-turn dialogue method refers to inputting the question text into a retrieval-based multi-turn dialogue model, performing text matching between the question text and each candidate response text in the candidate corpus based on the retrieval-based multi-turn dialogue model, and selecting the optimal response text from each candidate response text as the target response text corresponding to the dialogue context based on the matching results.

[0028] However, if a slight perturbation is added to the question text input to the retrieval-based multi-turn dialogue model, the retrieval-based multi-turn dialogue model will output the wrong target response text. Therefore, existing retrieval-based multi-turn dialogue models are easily fooled or attacked, and the model stability and generalization ability are poor.

[0029] In view of this, this application proposes an adversarial training method and related apparatus for a retrieval-based multi-turn dialogue model. In this application embodiment, for the question sample set corresponding to the retrieval-based multi-turn dialogue model, key morpheme transformation can be performed on each question sample to generate a corresponding morpheme adversarial sample set, and the sample order of each question sample can be transformed to generate a corresponding word order adversarial sample set. For the response sample set corresponding to the retrieval-based multi-turn dialogue model, at least one response adversarial sample with semantic differences and text similarity meeting set text conditions can be obtained from each response sample to generate a corresponding response adversarial sample set. Therefore, adversarial training of the retrieval-based multi-turn dialogue model can be performed based on the morpheme adversarial sample set, word order adversarial sample set, and response adversarial sample set, outputting a corresponding target model. This results in a target model with stronger generalization ability and robustness compared to the original retrieval-based multi-turn dialogue model.

[0030] The preferred embodiments of this application are described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit this application. Furthermore, the embodiments and features in the embodiments of this application can be combined with each other without conflict.

[0031] See Figure 1 The diagram illustrates an application scenario in this embodiment. The application scenario includes a terminal device 100 and a server 200. The terminal device 100 and the server 200 can communicate via a communication network. Optionally, the communication network can be a wired network or a wireless network. The terminal device 100 and the server 200 can be directly or indirectly connected via wired or wireless communication, which is not limited herein.

[0032] In this embodiment, the terminal device 100 is an electronic device used by a user, which may be a personal computer, mobile phone, tablet computer, laptop, e-book reader, smart home device, vehicle terminal, etc. The server 200 may be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery network (CDN), and big data and artificial intelligence platforms.

[0033] For example, a user can send a set of question samples and a set of response samples corresponding to a retrieval-based multi-turn dialogue model to a server 200 via a terminal device 100. The server 200 can then perform key morpheme transformation on each question sample in the question sample set to generate a corresponding set of morpheme adversarial samples, perform sample order transformation on each question sample in the question sample set to generate a corresponding set of word order adversarial samples, and obtain at least one response adversarial sample from each response sample in the response sample set that has semantic differences and whose text similarity meets set text conditions, generating a corresponding set of response adversarial samples. After obtaining the morpheme adversarial sample set, word order adversarial sample set, and response adversarial sample set, the server 200 can perform adversarial training on the retrieval-based multi-turn dialogue model based on these sets, outputting a corresponding target model, thereby enhancing the generalization ability and robustness of the retrieval-based multi-turn dialogue model.

[0034] It should be noted that, Figure 1 This paper provides an example of the application scenario of the adversarial training method for the retrieval-based multi-turn dialogue model of this application. However, the application scenarios applicable to the method in the actual embodiments of this application are not limited to this.

[0035] To further illustrate the technical solutions provided in the embodiments of this application, a detailed description is provided below in conjunction with the accompanying drawings and specific implementation methods. Although the embodiments of this application provide method operation steps as shown in the following embodiments or drawings, the method may include more or fewer operation steps based on conventional or non-inventive methods. In steps where there is no logically necessary causal relationship, the execution order of these steps is not limited to the execution order provided in the embodiments of this application. In actual processing or when the device executes the method, it may be executed sequentially or in parallel according to the method shown in the embodiments or drawings.

[0036] Figure 2a The flowchart shown is an adversarial training method for a retrieval-based multi-turn dialogue model provided in an embodiment of this application. This method can be executed by a server, for example... Figure 1 Server 200 in the middle. The following is in conjunction with the appendix. Figure 2a The adversarial training process of the retrieval-based multi-turn dialogue model in the embodiments of this application is described in detail.

[0037] Step S201: Obtain the question sample set and the response sample set.

[0038] The question sample set is the input text set corresponding to the retrieval-based multi-turn dialogue model, and the response sample set is the output text set corresponding to the retrieval-based multi-turn dialogue model.

[0039] Step S202: For each question sample in the question sample set, perform key morpheme transformation to generate a corresponding morpheme adversarial sample set, and perform sample order transformation on each question sample to generate a corresponding word order adversarial sample set.

[0040] For each set of question samples, at least one of the following three operations can be performed: The first approach involves performing the following operations on each question sample in the question sample set: Identify the words contained in a question sample, and replace each word with a synonym to obtain the morpheme adversarial sample corresponding to the question sample.

[0041] For example, if there is a question sample in the question sample set that is "you are so intelligent", then the word "intelligent" can be replaced with the synonym "smart". The text obtained after the synonym replacement is "you are so smart". That is, the original question sample is "you are so intelligent", and the morpheme adversarial sample obtained after the synonym replacement is "you are so smart".

[0042] When performing synonym replacement on each word identified in a question sample, the following operations can be performed on each identified word: obtain at least one candidate word corresponding to a word, wherein the at least one candidate word is obtained based on the context of the question sample; determine the semantic information corresponding to each of the at least one candidate word, the semantic similarity between the at least one candidate word and the semantic information corresponding to the word; select a candidate word whose semantic similarity meets the set semantic conditions from the at least one candidate word as the synonym of the word; and replace the word with the synonym.

[0043] The second approach involves performing the following operations on each question sample in the question sample set: The source and target languages ​​associated with a question sample are identified, and the question sample is translated from the source language to the target language to obtain the corresponding intermediate question sample. The intermediate question sample is then translated from the target language back to the source language to obtain the morpheme adversarial sample corresponding to the intermediate question sample.

[0044] For example, in the question sample set, there is a question sample "you are so intelligent". From this sample, we know the source language is English. Assuming the target language is French, translating the question text into French yields the intermediate question sample "Tu es si intelligente". Translating this intermediate question sample back into English results in "you are very clever". In other words, the original question sample "you are so intelligent", after being translated into French and then back into English, yields the adversarial sample "you are very clever".

[0045] The third method involves determining the original sample order of each question sample in the question sample set, performing a random sample order transformation on the original sample order to obtain the target sample order, and using each question sample sorted according to the target sample order as the set of adversarial sample orders.

[0046] By randomly shuffling the order of the question samples in the question sample set, the retrieval-based multi-turn dialogue model can be prompted to enhance its understanding of the question samples, rather than focusing more on the local text matching between the question samples and the various candidate responses in the candidate corpus. This can be used to attack the retrieval-based multi-turn dialogue model from a semantic level.

[0047] For example, the question sample set contains two question samples, "you are so intelligent" and "what's your favorite food", and the original sample order is "you are so intelligent" "what's your favorite food". After changing the order of this question sample, the target sample order is "what's your favorite food" "you are so intelligent". That is, the question sample set is "you are so intelligent" "what's your favorite food". After the random sample order change, the resulting adversarial sample set is "what's your favorite food" "you are so intelligent".

[0048] Step S203: For each response sample in the response sample set, obtain at least one corresponding response adversarial sample to generate the corresponding response adversarial sample set.

[0049] For each response sample in the response sample set, the following operations can be performed: obtain at least one candidate text sample corresponding to a response sample, wherein the semantic similarity between the semantic information corresponding to each candidate text sample and the semantic information corresponding to the response sample meets the set semantic conditions; determine the text similarity between at least one candidate text sample and the response sample; and select at least one response adversarial sample whose text similarity meets the set text conditions from at least one candidate text sample.

[0050] For example, such as Figure 2b As shown, in the response sample set, one response sample is "you are sointelligent", candidate text sample A is "you are not so intelligent", candidate text sample B is "you are so stupid", and candidate sample C is "you are not so clever". We can determine the semantic information corresponding to candidate text sample A, its semantic similarity A with the semantic information corresponding to the response sample, and the text similarity A between candidate text sample A and the response sample; the semantic information corresponding to candidate text sample B, its semantic similarity B with the semantic information corresponding to the response sample, and the text similarity B between candidate text sample B and the response sample; and the semantic information corresponding to candidate text sample C, its semantic similarity C with the semantic information corresponding to the response sample, and the text similarity C between candidate text sample C and the response sample. After determining the semantic similarity between the semantic information corresponding to each candidate text sample and the semantic information corresponding to the response sample, as well as the text similarity between each candidate text sample and the response sample, candidate text sample A can be selected from candidate text sample A, candidate text sample B, and candidate text sample C as the response adversarial sample, i.e., the response sample is "you are sointelligent". Based on the semantic difference between the response sample and the text similarity meeting the set text conditions, the response adversarial sample that can be selected is "you are not so intelligent".

[0051] Step S204: Based on the morpheme adversarial sample set, word order adversarial sample set, and response adversarial sample set, perform adversarial training on the retrieval-based multi-turn dialogue model and output the corresponding target model.

[0052] Based on the morpheme adversarial sample set and the word order adversarial sample set, a question adversarial sample set can be obtained. Based on the question adversarial sample set and the response adversarial sample set, the retrieval-based multi-turn dialogue model is adversarially trained, and the corresponding target model is output.

[0053] Specifically, the adversarial training process of a retrieval-based multi-turn dialogue model can be as follows: Figure 3 As shown below, in conjunction with Figure 3 The adversarial training process of the retrieval-based multi-turn dialogue model in the embodiments of this application is described in detail.

[0054] Step S301: Obtain the set of adversarial samples for questions and the set of adversarial samples for responses.

[0055] The obtained question adversarial sample set and response adversarial sample set are obtained based on the above steps S202 and S203, respectively, which will not be described in detail here.

[0056] Step S302: Extract question adversarial samples from the question adversarial sample set, and correspondingly extract at least one response adversarial sample from the response adversarial sample set.

[0057] When conducting adversarial training on a retrieval-based multi-turn dialogue model, adversarial questions can be extracted from the set of adversarial question samples, and at least one adversarial response sample can be extracted from the set of adversarial response samples. The extracted adversarial question samples and at least one adversarial response sample are then used as adversarial training sample data.

[0058] Step S303: Input the extracted question adversarial sample and at least one response adversarial sample into the retrieval-based multi-turn dialogue model to obtain the corresponding text matching results.

[0059] The extracted question adversarial sample and at least one response adversarial sample are input into the retrieval-based multi-turn dialogue model. Based on the retrieval-based multi-turn dialogue model, the question adversarial sample and at least one response adversarial sample are respectively matched with text to obtain the corresponding text matching results.

[0060] Step S304: Determine the corresponding loss value based on the text matching results.

[0061] When calculating the loss value, a pre-defined loss function can be used. This function can be the cross-entropy loss function, such as the sigmoid function. Other loss functions used include, but are not limited to, multi-class cross-entropy loss, contrastive loss (related to metric learning), or triplet loss. Generally, the loss value determines how closely the actual output matches the expected output. A smaller loss value indicates that the actual output is closer to the expected output.

[0062] Step S305: Determine whether the loss value has converged to the preset target value; if not, proceed to step S306; if yes, proceed to step S307.

[0063] To determine whether the loss value has converged to the preset target value, if the loss value is less than or equal to the preset target value, or if the change in the loss value obtained from N consecutive training iterations is less than or equal to the preset target value, then the loss value is considered to have converged to the preset target value, indicating that the loss value has converged; otherwise, it indicates that the loss value has not yet converged.

[0064] Step S306: Adjust the parameters of the retrieval-based multi-turn dialogue model based on the determined loss value.

[0065] If the loss value does not converge, the model parameters are adjusted. After adjusting the model parameters, the process returns to step S302 to continue the next round of training.

[0066] Step S307: End adversarial training to obtain the corresponding target model.

[0067] If the loss value converges, the current retrieval-based multi-turn dialogue model is used as the target model.

[0068] Optionally, after obtaining the question adversarial sample set and the response adversarial sample set, the retrieval-based multi-turn dialogue model can also be adversarially trained based on these sets to output the corresponding target model. Furthermore, the process of retraining the retrieval-based multi-turn dialogue model using the question sample set, response sample set, question adversarial sample set, and response adversarial sample set is similar to the above. Figure 3 The adversarial training process for the model is similar and will not be described in detail here.

[0069] In one embodiment, in step S202 above, for each question sample in the question sample set, taking one question sample as an example, the process of obtaining the corresponding morpheme adversarial sample by replacing the words contained in the question sample with synonyms is described in detail.

[0070] First, the Natural Language Toolkit (NLTK) can be used to identify the list of verbs, nouns, and adjectives in the question sample. list It contains N words. i Then, use WordNet to query each word one by one. i If synonyms exist, replace the word in the existing question sample. i The system uses synonyms; if a synonym does not exist, it does not replace it. WordNet is an English dictionary based on cognitive linguistics, which can be structured into a "network of words" according to their meanings. Using WordNet, equivalent replacements can be performed on words or phrases appearing in the query sample, modifying the query sample without altering its semantics.

[0071] Optionally, when performing synonym replacement on each word in the question sample, a corresponding morpheme adversarial sample can be obtained for each synonym replacement.

[0072] For example, the question sample is "There is a beautiful lake." Both the words "beautiful" and "lake" have synonyms. The synonyms for "beautiful" are "good-looking" and "pretty," while the synonym for "lake" is "river." Replacing "beautiful" with the synonym "good-looking" in the question sample "There is a beautiful lake" yields morpheme adversarial sample A: "There is a beautiful lake." Replacing "beautiful" with the synonym "pretty" yields morpheme adversarial sample B: "There is a beautiful lake." Replacing "lake" with the synonym "river" yields morpheme adversarial sample C: "There is a beautiful river."

[0073] In another embodiment, in step S202 above, for each question sample in the question sample set, taking one question sample as an example, the process of translating the question sample from the source language to the target language and then translating it back from the target language to the source language is described in detail to obtain the corresponding morpheme adversarial sample.

[0074] The Transformer-based Sequence-to-Sequence translation model can first translate the question sample from the source language to the target language to obtain the corresponding intermediate question sample, and then translate the intermediate question sample from the target language back to the source language to obtain the corresponding morpheme adversarial sample.

[0075] The Sequence-to-Sequence translation model consists of two parts: an encoder and a decoder.

[0076] Figure 4 This describes the process of translating a query sample from the source language to the target language, and then from the target language back to the source language, based on a translation model, to obtain morpheme-based adversarial examples. The following section combines... Figure 4 This process will be described in detail.

[0077] Step S401: Based on the encoder in the translation model, map the question sample corresponding to the source language to the first hidden layer.

[0078] The question samples corresponding to the source language are input into the translation model. Based on the encoder in the translation model, the question samples corresponding to the source language can be mapped to the first hidden layer. The first hidden layer contains the mathematical expression of the question sample sequence corresponding to the source language.

[0079] Step S402: Based on the decoder in the translation model, the first hidden layer is mapped to the intermediate question samples corresponding to the target language.

[0080] Based on the decoder in the translation model, the obtained first hidden layer can be mapped to the intermediate question sample sequence corresponding to the target language, thereby generating the translated intermediate question sample corresponding to the target language.

[0081] Step S403: Based on the encoder in the translation model, the intermediate question samples corresponding to the target language are mapped to the second hidden layer.

[0082] After obtaining intermediate question samples corresponding to the target language, these samples can be input into the translation model. Based on the encoder in the translation model, the intermediate question samples corresponding to the target language can be mapped to a second hidden layer. This second hidden layer contains the mathematical expression of the intermediate question sample sequence corresponding to the target language.

[0083] Step S404: Based on the decoder in the translation model, the second hidden layer is mapped to adversarial samples of the source language.

[0084] Based on the decoder in the translation model, the obtained second hidden layer can be mapped to the morpheme adversarial sample sequence corresponding to the source language, thereby generating the translated morpheme adversarial sample corresponding to the source language.

[0085] Specifically, the encoder's model structure can be as follows: Figure 5 As shown, it includes positional encoding, masked multi-head attention, and feedforward layers. Positional encoding, also known as positional embedding, is necessary because the Transformer model lacks the iterative operations of recurrent neural networks. Therefore, the positional information of each word must be provided to the Transformer in order to recognize the sequential relationships in the language.

[0086] The multi-head attention layer with a mask includes self-attention and attention mask. Self-attention is a variant of the attention mechanism; it reduces reliance on external information and is better at capturing the internal correlations of data or features. It's a technique used by Transformers to transform the "understanding" of other related words into the words being processed by the human. Attention mask prevents invalid regions from participating in computation. Since the input source language text is of variable length, training requires truncating long texts to a fixed length and padding short texts to a fixed length. The padded portions of short texts have no computational significance. Attention mask prevents these invalid regions from participating in computation, effectively improving model performance.

[0087] After the multi-head attention layer and the feedforward network layer, a data normalization layer is connected to normalize the data before it is input into the next network layer. Normalizing the output data of each network layer helps to speed up the model's training and improve its training effect. The data normalization layer includes Layer Normalization and residual connections. The role of Layer Normalization is to normalize the hidden layers in the neural network to a standard normal distribution, i.e., independent and identically distributed. Residual connections are obtained by adding the values ​​before and after the operation, allowing the gradient to be backpropagated directly to the initial layer during training. Both Layer Normalization and residual connections accelerate model convergence.

[0088] The decoder can map the hidden layers obtained by the encoder to a target language sequence. Assuming the source language length is N and the target language length is M, decoding requires M steps. The input, output, and decoding process for each step are as follows: (1) Input: The output of the encoder, corresponding to the output of the decoder at position i-1; (2) Output: The probability distribution of the output word at position i; (3) Similar to a recurrent neural network, the output is calculated step by step based on the input to obtain a target language sequence of length M.

[0089] By translating the question sample from the source language to the target language and then back to the source language, text-level rewriting of the question sample can be performed while preserving semantics. Furthermore, by employing this process of translating the question sample from the source language to the target language and then back to the source language, corresponding morpheme adversarial samples can be obtained. This increases the diversity of morpheme adversarial samples at the text level, which can then be used to attack retrieval-based multi-turn dialogue models.

[0090] In another embodiment, in step S203 above, for each response sample in the response sample set, taking one response sample as an example, the process of obtaining at least one response adversarial sample corresponding to the response sample is described in detail.

[0091] First, based on the semantic information corresponding to the text, at least one candidate text sample is selected from the candidate corpus whose semantic similarity to the semantic information corresponding to the response sample meets the set semantic conditions. The candidate corpus may include a set of question samples and a set of candidate response samples. Each candidate response sample in the candidate response sample set is used to perform text matching with each question sample in the input retrieval-based multi-turn dialogue model. Based on the matching results, the corresponding response sample is selected from each candidate response sample. The set semantic conditions are that there is a semantic difference or semantic opposition; that is, at least one candidate text sample with a significant difference in semantic information from the response sample is selected from the candidate corpus. For example, if the question sample is "you are so intelligent," then the candidate text sample could be "you are not so intelligent."

[0092] Then, Best Match25 (BM25) is used to determine the text similarity between each candidate text sample and the response sample. BM25 is an algorithm used to calculate the text similarity score between two texts. BM25 consists of three parts: the relevance between each word q in the response sample query and the candidate text sample d, the similarity between word q and the query, and the weight of each word.

[0093] The formula for calculating BM25 is as follows: Where Q represents the response sample query, d represents the candidate text sample, and q i W represents the i-th word in the response sample query. i This represents the word weight corresponding to the i-th word in the response sample query, and the word weight corresponding to each word can be obtained by the Inverse Document Frequency (IDF).

[0094] By identifying at least one adversarial response sample that differs semantically from the response sample but is textually similar, an attack can be launched against the retrieval-based multi-turn dialogue model from a semantic perspective.

[0095] In summary, the overall process of the adversarial training method for the retrieval-based multi-turn dialogue model proposed in this application can be described as follows: Figure 6a As shown, it includes the following steps: Step S61, obtain a set of question samples and a set of reply samples.

[0096] Among them, the set of question samples and the set of reply samples respectively correspond to the input and output of the retrieval-based multi-turn dialogue model.

[0097] Step S621, for each question sample in the set of question samples, perform synonym replacement on the words included in each question sample to obtain a corresponding set of morpheme adversarial samples.

[0098] For example, as Figure 6b shown, if the question sample is "this beautiful little girl is very smart", the words included in this question sample can be identified first, which are "this", "beautiful", "little girl", "is", "very", "smart". Then, perform synonym replacement on each identified word. "beautiful" can be replaced with "pretty", and "smart" can be replaced with "intelligent". After synonym replacement, the obtained morpheme adversarial sample is "this pretty little girl is very intelligent".

[0099] Step S622, for each question sample in the set of question samples, translate each question sample from the source language to the target language and then back to the source language to obtain a corresponding set of morpheme adversarial samples.

[0100] For example, as Figure 6c shown, if the question sample is "this beautiful little girl is very smart", it can be translated into Chinese first, and the intermediate question sample obtained is "这个漂亮的小女孩很聪明". Then, translate the intermediate question sample back into English, and the obtained morpheme adversarial sample is "This pretty little girl isso clever".

[0101] Step S623, randomly transform the original sample order of each question sample in the set of question samples into a target sample order to obtain a corresponding set of word order adversarial samples.

[0102] For example, as Figure 6dAs shown, the question sample set includes four question samples, arranged in the following order: 1. "This beautiful little girl is very smart", 2. "What's your favorite color", 3. "Where are you from", 4. "That is your bag". Randomly changing the order of these four question samples yields the following set of adversarial sentences: 1. "Where are you from", 2. "That is your bag", 3. "This beautiful little girl is very smart", 4. "What's your favorite color".

[0103] Step S624: For each response sample in the response sample set, obtain at least one response adversarial sample that has semantic differences and whose text similarity meets the set text conditions, and generate the corresponding response adversarial sample set.

[0104] For example, such as Figure 6e As shown, the response sample is "your favorite color is blue". We can first identify at least one candidate text sample that has a semantic difference from this response sample. These candidate text samples are "your favorite color is red", "your favorite color is not blue", "your favorite color among these 5 colors is red", and "your favorite color among these 5 colors is not blue". We then determine the text similarity between each of the four candidate text samples and the response sample. Based on the text similarity meeting the set text conditions, we can select the adversarial response samples "your favorite color is red" and "your favorite color is not blue" from the four candidate text samples.

[0105] Step S63: Based on the morpheme adversarial sample set, word order adversarial sample set, and response adversarial sample set, perform adversarial training on the retrieval-based multi-turn dialogue model and output the corresponding target model.

[0106] The adversarial training method for a retrieval-based multi-turn dialogue model provided in this application can perform synonym replacement on each question sample in the question sample set corresponding to the retrieval-based multi-turn dialogue model, or translate each question sample from the source language to the target language and then back from the target language to the source language, to obtain a corresponding morpheme adversarial sample set. Alternatively, the sample order of each question sample in the question sample set can be randomly transformed to obtain a corresponding word order adversarial sample set. Furthermore, for each response sample in the response sample set corresponding to the retrieval-based multi-turn dialogue model, at least one response adversarial sample with semantic differences and text similarity meeting set text conditions can be identified to obtain a corresponding response adversarial sample set. After obtaining the morpheme adversarial sample set, word order adversarial sample set, and response adversarial sample set, the retrieval-based multi-turn dialogue model can be adversarially trained based on these sets to output a corresponding target model. Because this approach adds perturbations and modifications to the input of the retrieval-based multi-turn dialogue model at multiple levels, such as phrases, sentences, and context, it can generate adversarial examples from different angles to attack the retrieval-based multi-turn dialogue model based solely on existing datasets without relying on the model itself. Furthermore, using adversarial examples generated at multiple levels to train the retrieval-based multi-turn dialogue model can increase its generalization ability and robustness.

[0107] and Figure 2a The adversarial training method for the retrieval-based multi-turn dialogue model shown is based on the same inventive concept. This application also provides an adversarial training device for a retrieval-based multi-turn dialogue model, which can be deployed in a server or terminal device. Since this device corresponds to the adversarial training method for the retrieval-based multi-turn dialogue model in this application, and the principle by which this device solves the problem is similar to that of the method, the implementation of this device can refer to the implementation of the above method; repeated details will not be elaborated further.

[0108] Figure 7 This illustration shows a schematic diagram of the structure of an adversarial training device for a retrieval-based multi-turn dialogue model provided in an embodiment of this application. Figure 7 As shown, the adversarial training device for the retrieval-based multi-turn dialogue model includes a set acquisition module 701, a first adversarial sample generation module 702, a second adversarial sample generation module 703, and a model adversarial training module 704.

[0109] Among them, the set acquisition module 701 is used to acquire the question sample set and the response sample set; The first adversarial sample generation module 702 is used to perform key morpheme transformation on each question sample in the question sample set to generate a corresponding morpheme adversarial sample set, and to perform sample order transformation on each question sample to generate a corresponding word order adversarial sample set. The second adversarial sample generation module 703 is used to obtain at least one corresponding adversarial sample for each response sample in the response sample set and generate a corresponding response adversarial sample set, wherein each response adversarial sample and the corresponding response sample have semantic differences and the text similarity meets the set text conditions. The model adversarial training module 704 is used to perform adversarial training on a retrieval-based multi-turn dialogue model based on a set of morpheme adversarial samples, a set of word order adversarial samples, and a set of response adversarial samples, and output the corresponding target model.

[0110] Optionally, the first adversarial example generation module 702 is specifically used for: For each question sample in the question sample set, perform at least one of the following operations: Identify the words contained in a question sample, and replace each word with a synonym to obtain a morpheme adversarial sample corresponding to the question sample. The source and target languages ​​associated with a question sample are determined, and a question sample is translated from the source language to the target language to obtain the corresponding intermediate question sample. The intermediate question sample is then translated from the target language back to the source language to obtain the morpheme adversarial sample corresponding to the intermediate question sample.

[0111] Optionally, the first adversarial example generation module 702 is also used for: Perform the following operations for each word: Obtain at least one candidate word corresponding to a given word. The at least one candidate word is obtained based on the context of a question sample. Determine the semantic information corresponding to at least one candidate word and the semantic similarity between it and the semantic information corresponding to a word; From at least one candidate word, select one candidate word whose semantic similarity meets the set semantic conditions, and use it as a synonym of the corresponding word; Replace a word with a synonym.

[0112] Optionally, the first adversarial example generation module 702 is also used for: Determine the original sample order of each question sample in the question sample set, and then perform a random sample order transformation on the original sample order to obtain the target sample order; Each question sample, sorted according to the order of the target sample, is used as a set of adversarial samples for word order.

[0113] Optionally, the second adversarial example generation module 703 is specifically used for: For each response sample in the response sample set, perform the following operations: Obtain at least one candidate text sample corresponding to a response sample; wherein the semantic similarity between the semantic information corresponding to each candidate text sample and the semantic information corresponding to a response sample meets the set semantic conditions; Determine the text similarity between at least one candidate text sample and a response sample; From at least one candidate text sample, select at least one response adversarial sample whose text similarity meets the set text conditions.

[0114] Optional, the model adversarial training module 704 is specifically used for: Based on the morpheme adversarial sample set and the word order adversarial sample set, a question adversarial sample set is obtained; Based on the question adversarial example set and the response adversarial example set, the retrieval-based multi-turn dialogue model is iteratively trained until the set convergence condition is met. One iteration of the training process includes: Based on the question adversarial samples extracted from the question adversarial sample set and at least one corresponding response adversarial sample extracted from the response adversarial sample set, the retrieval-based multi-turn dialogue model performs text matching between the question adversarial samples and at least one response adversarial sample to determine the corresponding matching results; the corresponding loss value is determined based on the matching results, and the parameters of the retrieval-based multi-turn dialogue model are adjusted based on the loss value. The parameter-adjusted retrieval-based multi-turn dialogue model is used as the corresponding target model.

[0115] Based on the same inventive concept as the above method and apparatus embodiments, this application also provides an electronic device.

[0116] In one embodiment, the electronic device may be a server, such as... Figure 1 The server 200 is shown. In this embodiment, the structure of the electronic device can be as follows: Figure 8 As shown, it includes a memory 801, a communication module 803, and one or more processors 802.

[0117] The memory 801 is used to store computer programs executed by the processor 802. The memory 801 may mainly include a program storage area and a data storage area. The program storage area may store the operating system and programs required to run instant messaging functions, etc.; the data storage area may store various instant messaging information and operation instruction sets, etc.

[0118] Memory 801 may be volatile memory, such as random-access memory (RAM); memory 801 may also be non-volatile memory, such as read-only memory, flash memory, hard disk drive (HDD), or solid-state drive (SSD); or memory 801 may be any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but is not limited thereto. Memory 801 may be a combination of the above-mentioned memories.

[0119] Processor 802 may include one or more central processing units (CPUs) or digital processing units, etc. Processor 802 is used to implement the adversarial training method of the above-mentioned retrieval-based multi-turn dialogue model when calling the computer program stored in memory 801.

[0120] The communication module 803 is used to communicate with terminal devices and other electronic devices. If the electronic device is a server, the server can receive a set of query samples and a set of response samples sent by the terminal device through the communication module 803.

[0121] This application does not limit the specific connection medium between the memory 801, the communication module 803, and the processor 802 described above. This disclosure embodiment... Figure 8 The memory 801 and the processor 802 are connected via a bus 804, and the bus 804 is in Figure 8 The connections between other components are shown in thick lines only and are not intended to be limiting. The 804 bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, Figure 8 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0122] In another embodiment, the electronic device can be any electronic device such as a mobile phone, tablet computer, POS (Point of Sales), in-vehicle computer, smart wearable device, or PC. Figure 1 The terminal device 100 shown is shown.

[0123] Figure 9 A structural block diagram of an electronic device provided in an embodiment of this application is shown. Figure 9As shown, the electronic device includes: a radio frequency (RF) circuit 910, a memory 920, an input unit 930, a display unit 940, a sensor 950, an audio circuit 960, a wireless fidelity (WiFi) module 970, a processor 980, and other components. Those skilled in the art will understand that... Figure 9 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0124] The following is combined with Figure 9 A detailed introduction to each component of the electronic device: The RF circuit 910 can be used to receive and transmit signals during information transmission or calls. In particular, it receives downlink information from the base station and processes it with the processor 980; in addition, it transmits uplink data to the base station.

[0125] The memory 920 can be used to store software programs and modules, such as the program instructions / modules corresponding to the adversarial training method and apparatus for the retrieval-based multi-turn dialogue model in the embodiments of this application. The processor 980 executes various functional applications and data processing of the electronic device by running the software programs and modules stored in the memory 920, such as the adversarial training method for the retrieval-based multi-turn dialogue model provided in the embodiments of this application. The memory 920 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs of at least one application, etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 920 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0126] The input unit 930 can be used to receive numeric or character information input by the user, and to generate key signal inputs related to user settings and function control of the terminal.

[0127] Optionally, the input unit 930 may include a touch panel 931 and other input devices 932.

[0128] The touch panel 931, also known as a touch screen, collects touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel 931), and performs corresponding operations according to a pre-set program, such as the user clicking on a shortcut icon of a function module. Optionally, the touch panel 931 may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch position and the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 980, and can also receive and execute commands from the processor 980. Furthermore, the touch panel 931 can be implemented using various types of touch technologies, such as resistive, capacitive, infrared, and surface acoustic wave.

[0129] Optionally, other input devices 932 may include, but are not limited to, one or more of the following: physical keyboard, function keys (such as volume control buttons, power buttons, etc.), trackball, mouse, joystick, etc.

[0130] Display unit 940 can be used to display information input by the user or interface information displayed to the user, as well as various menus of electronic devices. Display unit 940 is the display system of the terminal device, used to present the interface, such as displaying the desktop, the operation interface of an application, or the operation interface of a live streaming application.

[0131] The display unit 940 may include a display panel 941. Optionally, the display panel 941 may be configured as a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.

[0132] Furthermore, the touch panel 931 can cover the display panel 941. When the touch panel 931 detects a touch operation on or near it, it transmits the information to the processor 980 to determine the type of touch event. Subsequently, the processor 980 provides a corresponding interface output on the display panel 941 according to the type of touch event.

[0133] Although Figure 9 In this embodiment, the touch panel 931 and the display panel 941 are two separate components to realize the input and output functions of the electronic device. However, in some embodiments, the touch panel 931 and the display panel 941 can be integrated to realize the input and output functions of the terminal.

[0134] The electronic device may also include at least one sensor 950, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor. The ambient light sensor can adjust the brightness of the display panel 941 according to the ambient light level, and the proximity sensor can turn off the backlight of the display panel 941 when the electronic device is moved to the ear. As a type of motion sensor, an accelerometer sensor can detect the magnitude of acceleration in various directions (generally three axes). When stationary, it can detect the magnitude and direction of gravity and can be used for applications that identify the posture of the electronic device (such as landscape / portrait switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometers, taps), etc. Other sensors that may be configured in the electronic device, such as gyroscopes, barometers, hygrometers, thermometers, and infrared sensors, will not be described in detail here.

[0135] Audio circuit 960, speaker 961, and microphone 962 provide an audio interface between the user and electronic device. Audio circuit 960 converts received audio data into electrical signals and transmits them to speaker 961, where speaker 961 converts them into sound signals for output. On the other hand, microphone 962 converts collected sound signals into electrical signals, which are received by audio circuit 960, converted into audio data, and then output to processor 980 for processing. The audio data is then transmitted via RF circuit 910 to, for example, another electronic device, or output to memory 920 for further processing.

[0136] WiFi is a short-range wireless transmission technology. Electronic devices using the WiFi module 970 can help users send and receive emails, browse web pages, and access streaming media, providing users with wireless broadband internet access. Although Figure 9 WiFi module 970 is shown, but it is understood that it is not a necessary component of an electronic device and can be omitted as needed without changing the nature of the invention.

[0137] The processor 980 is the control center of the electronic device, connecting various parts of the device through various interfaces and lines. It executes various functions and processes data by running or executing software programs and / or modules stored in the memory 920, and by calling data stored in the memory 920. Optionally, the processor 980 may include one or more processing units; optionally, the processor 980 may integrate an application processor and a modem processor. The application processor mainly processes software programs such as the operating system, applications, and functional modules within the applications, such as the adversarial training method for the retrieval-based multi-turn dialogue model provided in this application embodiment. The modem processor mainly processes wireless communication. It is understood that the aforementioned modem processor may not be integrated into the processor 980.

[0138] Understandable. Figure 9 The structure shown is for illustrative purposes only; the electronic device may also include components that are more advanced than those shown. Figure 9 The more or fewer components shown, or having the same Figure 9 The different configurations shown. Figure 9 The components shown can be implemented using hardware, software, or a combination thereof.

[0139] According to one aspect of this application, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the adversarial training method for the retrieval-based multi-turn dialogue model described in the above embodiments.

[0140] The program product may employ any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0141] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.

Claims

1. An adversarial training method for a retrieval-based multi-turn dialogue model, characterized in that, include: Obtain a question sample set and a response sample set; the question sample set is the input text set corresponding to the retrieval-based multi-turn dialogue model, and the response sample set is the output text set corresponding to the retrieval-based multi-turn dialogue model; For each question sample in the question sample set, key morphemes are transformed to generate a corresponding set of adversarial morphemes. Determine the original sample order of each question sample in the question sample set, perform a random sample order transformation on the original sample order to obtain the target sample order, and take each question sample sorted according to the target sample order as the grammatical adversarial sample set; For each response sample in the response sample set, the following operations are performed: obtain at least one candidate text sample corresponding to a response sample; wherein, each candidate text sample has a semantic difference from the response sample; determine the text similarity between the at least one candidate text sample and the response sample; select at least one response adversarial sample from the at least one candidate text sample whose text similarity meets the set text conditions; Based on the morpheme adversarial sample set, the word order adversarial sample set, and the response adversarial sample set, the retrieval-based multi-turn dialogue model is adversarially trained, and the corresponding target model is output. The step of performing key morpheme transformation on each question sample in the question sample set to generate a corresponding morpheme adversarial sample set includes: For each question sample in the aforementioned question sample set, perform the following operations: Identify the words contained in a question sample, and replace each word with a synonym to obtain the morpheme adversarial sample corresponding to the question sample; The source language and target language associated with the question sample are determined, and the question sample is translated from the source language to the target language to obtain the corresponding intermediate question sample. The intermediate question sample is then translated from the target language back to the source language to obtain the morpheme adversarial sample corresponding to the intermediate question sample.

2. The method as described in claim 1, characterized in that, The process of replacing each word with a synonym includes: For each of the aforementioned words, perform the following operations respectively: Obtain at least one candidate word corresponding to a given word, wherein the at least one candidate word is obtained based on the context of the given question sample; Determine the semantic information corresponding to each of the at least one candidate word and the semantic similarity between them and the semantic information corresponding to the word; From the at least one candidate word, select one candidate word whose semantic similarity meets the set semantic conditions, and use it as the synonym of the one word; Replace the word with the synonym.

3. The method as described in claim 1 or 2, characterized in that, The adversarial training of the retrieval-based multi-turn dialogue model is performed based on the morpheme adversarial sample set, the word order adversarial sample set, and the response adversarial sample set, and the corresponding target model is output, including: Based on the morpheme adversarial sample set and the word order adversarial sample set, a question adversarial sample set is obtained; Based on the set of adversarial questions and the set of adversarial responses, the retrieval-based multi-turn dialogue model is iteratively trained until a set convergence condition is met. One iteration of the training process includes: Based on the question adversarial samples extracted from the question adversarial sample set and at least one response adversarial sample extracted from the response adversarial sample set, the retrieval-based multi-turn dialogue model performs text matching between the question adversarial samples and the at least one response adversarial sample to determine the corresponding matching results; the corresponding loss value is determined based on the matching results, and the parameters of the retrieval-based multi-turn dialogue model are adjusted based on the loss value. The retrieval-based multi-turn dialogue model with the adjusted parameters is used as the corresponding target model.

4. An adversarial training device for a retrieval-based multi-turn dialogue model, characterized in that, include: The set acquisition module is used to acquire a question sample set and a response sample set; the question sample set is the input text set corresponding to the retrieval-based multi-turn dialogue model, and the response sample set is the output text set corresponding to the retrieval-based multi-turn dialogue model. The first adversarial sample generation module is used to perform key morpheme transformation on each question sample in the question sample set to generate a corresponding morpheme adversarial sample set; determine the original sample order of each question sample in the question sample set; perform random sample order transformation on the original sample order to obtain the target sample order; and take each question sample sorted according to the target sample order as the word order adversarial sample set. The second adversarial sample generation module is used to perform the following operations for each response sample in the response sample set: obtaining at least one candidate text sample corresponding to a response sample; wherein, each candidate text sample has a semantic difference with the response sample; determining the text similarity between the at least one candidate text sample and the response sample; and selecting at least one adversarial response sample whose text similarity meets the set text conditions from the at least one candidate text sample. The model adversarial training module is used to perform adversarial training on the retrieval-based multi-turn dialogue model based on the morpheme adversarial sample set, the word order adversarial sample set, and the response adversarial sample set, and output the corresponding target model. The first adversarial sample generation module, when performing key morpheme transformation on each question sample in the question sample set to generate a corresponding morpheme adversarial sample set, specifically performs the following operations on each question sample in the question sample set: identifying each word contained in a question sample and performing synonym replacement on each word to obtain a morpheme adversarial sample corresponding to the question sample; determining the source language and target language associated with the question sample and translating the question sample from the source language to the target language to obtain a corresponding intermediate question sample; and translating the intermediate question sample from the target language back to the source language to obtain a morpheme adversarial sample corresponding to the intermediate question sample.

5. An electronic device, characterized in that, It includes a processor and a memory, wherein the memory stores program code that, when executed by the processor, causes the processor to perform the steps of any of the methods described in claims 1 to 3.

6. A computer-readable storage medium, characterized in that, It includes program code that, when run on an electronic device, causes the electronic device to perform the steps of any of the methods described in claims 1 to 3.

7. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method described in any one of claims 1 to 3.

Citation Information

Patent Citations

  • Adversarial sample generation method and device, electronic equipment and storage medium

    CN111046176A

  • Question and answer data processing method and device based on artificial intelligence and electronic equipment

    CN111209384A

  • Question and answer model training method and device, question and answer method and device, equipment and storage medium

    CN113033664A

  • Model training method and device, electronic equipment and storage medium

    CN113807098A