Contrastive learning, query and human-machine dialogue method, electronic device and storage medium
By constructing a loss function for similar and dissimilar sample pairs, the training process of the task model is optimized, which solves the problem of performance improvement of contrastive learning schemes in specific scenarios in existing technologies, and achieves more efficient task model training and more accurate human-computer dialogue.
Patent Information
- Application Number
- CN202210782581.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-05
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2042-07-05
AI Technical Summary
Existing contrastive learning schemes still have room for improvement in training task models for specific scenarios, especially in constructing high-quality augmented samples and optimizing loss functions.
By constructing similar and dissimilar sample pairs, and using similarity and dissimilarity to build the encoder loss function of the task model, the function value of the loss function is proportional to the similarity of similar sample pairs and the similarity of dissimilar sample pairs. Through contrastive learning, through the encoder method of the task model, and by implementing the inverse proportionality of sample similarity, the confidence of training samples and the performance of the task model are improved.
It improved the training effect of the task model, enhanced the performance and generalization ability of the task model, and improved the accuracy and efficiency of query and human-computer dialogue.
Smart Images

Figure CN115329055B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a comparative learning, querying and human-computer dialogue method, electronic device and storage medium. Background Technology
[0002] Contrastive Learning (CL) is a self-supervised learning method that uses unlabeled training data to generate pairs of augmentations. Then, a classification task is defined as a pretext task based on the augmentations to learn optimized deep embeddings.
[0003] The prerequisite for contrastive learning is to treat an instance as a class and learn an invariant instance representation.
[0004] However, current contrastive learning schemes still have room for improvement in training task models for specific scenarios. Summary of the Invention
[0005] In view of this, embodiments of the present invention provide a comparative learning, querying, and human-computer dialogue method, an electronic device, and a storage medium to at least partially solve the above-mentioned problems.
[0006] According to a first aspect of the present invention, a contrastive learning method is provided, comprising: constructing similar sample pairs and dissimilar sample pairs based at least on similar augmented samples and labeled samples of training samples; constructing a loss function for an encoder of a task model based on the similarity of the similar sample pairs and the similarity of the dissimilar sample pairs, wherein the function value of the loss function is proportional to the similarity of the similar sample pairs and inversely proportional to the similarity of the dissimilar sample pairs; and training the encoder of the task model based on the loss function.
[0007] In another implementation of the present invention, constructing similar sample pairs and dissimilar sample pairs based at least on similar enhanced samples and labeled samples of the training samples includes: constructing a first similar sample pair and a first dissimilar sample pair based on the training samples and their similar enhanced samples; and constructing a first similar sample pair and a first dissimilar sample pair based on the similar enhanced samples and labeled samples of the training samples.
[0008] In another implementation of the present invention, the step of constructing the loss function of the encoder of the task model based on the similarity of the similar sample pairs and the similarity of the dissimilar sample pairs includes: determining a first loss function based on the similarity of the first similar sample pairs and the similarity of the first dissimilar sample pairs, and determining a second loss function based on the similarity of the second similar sample pairs and the similarity of the second dissimilar sample pairs; and determining the loss function of the encoder of the task model based on the first loss function and the second loss function.
[0009] In another implementation of the present invention, the step of constructing a first similar sample pair and a first dissimilar sample pair based on training samples and their similar enhanced samples includes: determining a first training sample and its corresponding first similar enhanced sample as the first similar sample pair; and determining a second similar enhanced sample corresponding to the first training sample and the second training sample as the first dissimilar sample pair.
[0010] In another implementation of the present invention, the step of constructing similar sample pairs and dissimilar sample pairs based on training samples and their similar enhanced samples further includes: determining the first training sample and the second training sample as the first dissimilar sample pair.
[0011] In another implementation of the present invention, the step of constructing a first similar sample pair and a first dissimilar sample pair based on the similarity-enhanced sample and the labeled sample of the training sample includes: determining a first fusion sample of the first training sample and the first similarity-enhanced sample, and a labeled sample of the first fusion sample, as the second similar sample pair; and determining a labeled sample of the first fusion sample and the second fusion sample as the second dissimilar sample pair.
[0012] In another implementation of the present invention, the method further includes: inputting the initial sample into an encoder having a first random inactivation probability and a second random inactivation probability to obtain the training sample and the similar enhancement sample, respectively.
[0013] In another implementation of the present invention, the first function value of the first loss function is directly proportional to the similarity of the first similar sample pair, and the first function value is inversely proportional to the similarity of the first dissimilar sample pair. The second function value of the second loss function is directly proportional to the similarity of the second similar sample pair, and the second function value is inversely proportional to the similarity of the second dissimilar sample pair.
[0014] In another implementation of the present invention, the method further includes: training the task model based on a third loss function.
[0015] According to a second aspect of the present invention, a query method is provided, comprising: obtaining simplified query data; inputting the simplified query data into a query rewriting model to obtain contextual query data, wherein the query rewriting model is trained according to the method described in the first aspect; and performing a query based on the contextual query data to obtain a query result.
[0016] According to a third aspect of the present invention, a human-computer dialogue method is provided, comprising: acquiring a dialogue request; parsing the dialogue request to obtain simplified query data; using a query method to perform a query based on the simplified data to obtain a query result; and generating a dialogue response to the dialogue request based on the query result.
[0017] According to a fourth aspect of the present invention, an electronic device is provided, comprising: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other via the communication bus; the memory is used to store at least one executable instruction, wherein the executable instruction causes the processor to perform an operation corresponding to the method described in any one of the first to third aspects.
[0018] According to a fifth aspect of the present invention, a computer storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method described in any one of the first to third aspects.
[0019] In the embodiments of the present invention, similar sample pairs and dissimilar sample pairs are constructed based at least on similar augmented samples and labeled samples of the training samples. This results in augmented samples composed of similar and dissimilar sample pairs having higher quality. Based on the inventive concept of contrastive learning, the function value of the constructed loss function is proportional to the similarity of similar sample pairs and inversely proportional to the similarity of dissimilar sample pairs. This loss function improves the confidence of the training samples, rather than simply augmenting the training samples themselves. Therefore, it improves the performance of the trained task model. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings.
[0021] Figure 1 This is a schematic block diagram of a dialogue system based on an example.
[0022] Figure 2This is a flowchart illustrating the steps of a comparative learning method according to an embodiment of the present invention.
[0023] Figure 3 for Figure 2 A schematic diagram of the comparative learning process in the embodiment.
[0024] Figure 4 This is a flowchart of the steps of a query method according to another embodiment of the present invention.
[0025] Figure 5 This is a flowchart of the steps of a human-computer dialogue method according to another embodiment of the present invention.
[0026] Figure 6 This is a schematic diagram of the structure of an electronic device according to another embodiment of the present invention. Detailed Implementation
[0027] To enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions in the embodiments of the present invention will be clearly and thoroughly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art should fall within the protection scope of the present invention.
[0028] The specific implementation of the embodiments of the present invention will be further described below with reference to the accompanying drawings.
[0029] With the continuous development of computer technology and the continuous progress of artificial intelligence technology, intelligent conversational systems such as Context-based Information Retrieval (CIR) systems can be developed. Conversational information retrieval systems are information retrieval systems with conversational interfaces that allow users to interact with the system to find information orally or in writing through multi-turn dialogues in natural language, which greatly facilitates the efficiency of human-computer interaction.
[0030] In conversational information retrieval systems, rewriting models trained on dialogue question rewriting tasks are beneficial for converting simplified query data into corresponding complete contextual query data without omissions, thereby enabling the query data to be better processed by the information retrieval system.
[0031] Figure 1This is a schematic block diagram of an example dialogue system. The example dialogue system includes a front-end device 110, a dialogue server 120, and a database 130. The front-end device 110 may be a user device, including a human-computer interaction module. The front-end device 110 generates query data, for example, simplified query data, through the human-computer interaction module. The front-end device 110 then transmits the simplified query data to the dialogue server 120 via a communication module (not shown).
[0032] Specifically, the front-end device 110 can be a terminal device such as an embedded device or an IoT device, or a non-embedded device such as a desktop computer or server. Embedded devices may have an embedded operating system, such as a real-time operating system, installed, and communicate with the dialogue server 120 via a network communication model. As an IoT device, the front-end device 110 can be a smart device such as a smart home appliance, including but not limited to smartwatches, smart speakers, smart air conditioners, and smart doorbells. The smart device can engage in intelligent dialogue with the user through a human-computer interaction module, such as voice interaction or computer vision interaction. It performs initial processing based on the user's dialogue commands and sends them to the dialogue server 120 for further processing, or directly forwards them to the dialogue server 120 for further processing.
[0033] The dialogue server 120 includes a rewriting module, a query module, and a text generation module. The rewriting module simplifies the generation of context query data from the query data and retrieves information from a database such as the dialogue database 130 based on the context query data. Then, the query module transmits the retrieved information to the text generation module to generate text as the query result, which is then returned to the human-computer interaction module of the front-end device 110.
[0034] It should be understood that the query module in this example can be configured for different functions. For example, based on contextual query data, it can generate Structured Query Language (SQL) statements for querying (i.e., a database query scenario). The query module can also obtain corresponding response text or keywords based on contextual query data, and then the text generation module can generate more natural language-like text based on the response keywords or response text (i.e., a customer dialogue scenario). Furthermore, the response text or keywords can be based on the target language, and the contextual query data can be based on the source language, thus making the generated text a translation of the contextual query data (i.e., a translation query scenario). Alternatively, both the response text or keywords and the contextual query data can be based on the source language, and the generated text on the target language; this is another example of a translation query scenario.
[0035] Since the context query data is generated based on simplified query data, the reliability of the generated context query data depends on the configuration of the rewriting module. Therefore, when the rewriting module is implemented through a rewriting model, the performance of the rewriting model becomes particularly important. Furthermore, using simplified query data as input avoids excessive user input, improving the intelligence of the rewriting module. In this case, the reasoning ability of the rewriting model becomes especially crucial. Similarly, because simplified query data is used as input, the number of samples in the context query data is often small. Ensuring the intelligence of the rewriting model while training a rewriting model with strong reasoning and generalization abilities presents considerable challenges.
[0036] This invention employs the concept of contrastive learning to optimize the loss function as much as possible (e.g., minimize the loss function), thereby enabling the trained task model to have stronger performance, such as prediction accuracy and generalization ability. Figure 2 This is a flowchart illustrating the steps of a contrastive learning method according to an embodiment of the present invention. The solution of this embodiment can be applied to any suitable electronic device with data processing capabilities, including but not limited to: servers, mobile terminals (such as mobile phones, tablets, etc.), and PCs. For example, in the model training phase, a computing device configured with a CPU (processor unit) + GPU (acceleration unit) architecture (e.g., a data center) can be used to train the encoder-decoder model based on training samples. The computing device, such as a data center, can be deployed in cloud servers such as dedicated clouds, private clouds, or hybrid clouds. Correspondingly, in the inference phase, a computing device configured with a CPU (processor unit) + GPU (acceleration unit) architecture can also be used for inference operations.
[0037] The comparative learning method in this embodiment includes:
[0038] S210: Construct similar sample pairs and dissimilar sample pairs based at least on similar augmented samples and labeled samples from the training samples.
[0039] It should be understood that similarity-enhanced samples can be obtained by performing any enhancement processing on the training samples. For example, coarse-grained enhancement can be performed on the training samples. When the training samples are text samples, the text samples can be translated and then back-translated. Sample enhancement processing can be performed on each training sample, where each training sample and its corresponding similarity-enhanced sample can form a similar sample pair, and any other two different samples can form a dissimilar sample pair.
[0040] S220: Based on the similarity of similar sample pairs and the similarity of dissimilar sample pairs, construct the loss function of the encoder of the task model. The value of the loss function is directly proportional to the similarity of similar sample pairs and inversely proportional to the similarity of dissimilar sample pairs.
[0041] It should be understood that the task model is based on an encoder-decoder structure, such as a query rewriting model. A query rewriting model is used to generate contextual query data from simplified query data, where the query data can be text data or composite data.
[0042] S230: An encoder for training task models based on a loss function.
[0043] It should be understood that the encoder's loss function corresponds to the encoder itself. The encoder and decoder of the task model can be trained based on the corresponding generative loss function (e.g., the third loss function described below). The total loss function of the task model can be composed of the generative loss function and the encoder's loss function, for example, by weighting the generative loss function and the encoder's loss function. The encoder's loss function can serve as a supplement and adjustment to the generative loss function. The parameters of the task model can be adjusted based on the total loss function while training the encoder and decoder to maximize the total loss function.
[0044] In the embodiments of the present invention, similar sample pairs and dissimilar sample pairs are constructed based at least on similar augmented samples and labeled samples of the training samples. This results in augmented samples composed of similar and dissimilar sample pairs having higher quality. Based on the inventive concept of contrastive learning, the function value of the constructed loss function is proportional to the similarity of similar sample pairs and inversely proportional to the similarity of dissimilar sample pairs. This loss function improves the confidence of the training samples, rather than simply augmenting the training samples themselves. Therefore, it improves the performance of the trained task model.
[0045] In other examples, training samples and similar augmented samples can be obtained by inputting initial samples into an encoder with a first random inactivation probability and a second random inactivation probability, thereby improving the generalization ability of the task model based on the random inactivation probability.
[0046] In other examples, similar sample pairs and dissimilar sample pairs are constructed based at least on similar augmented samples and labeled samples of the training samples, including: constructing a first similar sample pair and a first dissimilar sample pair based on the training samples and their similar augmented samples; and constructing a first similar sample pair and a first dissimilar sample pair based on the similar augmented samples and labeled samples of the training samples. That is, similar sample pairs include a first similar sample pair and a second similar sample pair, and dissimilar sample pairs include a first dissimilar sample pair and a second dissimilar sample pair.
[0047] In other examples, the loss function of the encoder of the task model is constructed based on the similarity of similar sample pairs and the similarity of dissimilar sample pairs. This includes: determining a first loss function based on the similarity of a first similar sample pair and the similarity of a first dissimilar sample pair, and determining a second loss function based on the similarity of a second similar sample pair and the similarity of a second dissimilar sample pair; and determining the loss function of the encoder of the task model based on the first and second loss functions. The first loss function focuses on describing the internal contrast loss, and the second loss function focuses on describing the external contrast loss, thereby improving the effectiveness of the loss function.
[0048] In some examples, based on training samples and their similar augmented samples, a first similar sample pair and a first dissimilar sample pair are constructed, including: determining a first training sample and its corresponding first similar augmented sample as a first similar sample pair; determining a second similar augmented sample corresponding to the first training sample and the second training sample as a first dissimilar sample pair, thereby further improving the quality of similar and dissimilar sample pairs and facilitating the construction of a more effective loss function.
[0049] Furthermore, based on the training samples and their similar enhanced samples, similar sample pairs and dissimilar sample pairs are constructed. The contrastive learning method also includes: determining the first training sample and the second training sample as the first dissimilar sample pair.
[0050] Specifically, for text samples, the initial text sample (an example of the initial sample) can be input into the encoder for the first and second times respectively to obtain the first similar sample pair consisting of two similar text samples. The initial text sample can be a paragraph, sentence, clause, etc. The internal contrast loss is the loss constructed based on the similarity of the first similar sample pair and the similarity of the first dissimilar sample pair.
[0051] Alternatively, the first similar sample pair can also consist of the initial text sample and the similar text sample obtained from its first input to the encoder.
[0052] Alternatively, the first similar sample pair can also consist of the initial text sample and the similar text sample obtained by inputting it into the encoder a second time.
[0053] Furthermore, the first similar sample pair can also be a weighted sum of three: a similar sample pair consisting of two similar text samples, the initial text sample and the similar text sample obtained by inputting it into the encoder for the first time, and the initial text sample and the similar text sample obtained by inputting it into the encoder for the second time.
[0054] In other examples, based on the similar augmented samples and labeled samples of the training samples, a first similar sample pair and a first dissimilar sample pair are constructed, including: determining a first fusion sample of the first training sample and the first similar augmented sample, and a labeled sample of the first fusion sample, as a second similar sample pair; determining the labeled samples of the first fusion sample and the second fusion sample as a second dissimilar sample pair, thereby further improving the quality of the similar sample pairs and dissimilar sample pairs, which is beneficial for constructing a more effective loss function.
[0055] Specifically, for text samples, the external contrast loss is constructed based on the similarity of the second similar sample pair and the similarity of the second dissimilar sample pair, that is, the pairwise distance between the fused sample of similar text samples and the ground truth rewrite in the sample space.
[0056] The following will combine Figure 3 Describe similar and dissimilar sample pairs, and the loss function constructed based on similar and dissimilar sample pairs.
[0057] Figure 3 for Figure 2 This is a schematic diagram of the contrastive learning process in this embodiment. The task model in this example can be a query rewriting model, and it is based on an encoder-decoder structure. The task model in this example includes a word embedding layer 310, an encoder 320, and a decoder 330. This example focuses on training the encoder 320, that is, training the encoder based on training samples and their augmented samples.
[0058] Specifically, the first initial sample output from the word embedding layer 310 can be input into the encoder 320. The encoder 320 has random deactivation probabilities. Under the first random deactivation probability, it outputs the first training sample, and under the second random deactivation probability, it outputs the first similarity enhancement sample. Correspondingly, the second initial sample is input into the encoder 320 to obtain the second training sample and the second similarity training sample.
[0059] The first training sample and the first similar enhanced sample form a first similar sample pair; the first training sample and the second training sample form a first dissimilar sample pair; and the first training sample and the second similar enhanced sample pair form a dissimilar sample pair.
[0060] For a batch with N instances and augmented examples of the same size, for each data sample, the corresponding augmented data is treated as a positive sample, while the remaining 2(N-1) data records are treated as negative samples. The contrastive loss function in the batch can be expressed as:
[0061]
[0062] N is the batch size, and X is a word embedding matrix. 2N Positive pairs in X are recorded one by one, which means that every pair in the odd and even rows of X constitutes a positive pair, so X 2N The loss function for all combinations of samples formed is as follows:
[0063]
[0064] Specifically, the first function value of the first loss function is directly proportional to the similarity of the first similar sample pair and inversely proportional to the similarity of the first dissimilar sample pair. The second function value of the second loss function is directly proportional to the similarity of the second similar sample pair and inversely proportional to the similarity of the second dissimilar sample pair, thereby further improving the ability to construct a more effective loss function.
[0065] In other examples, contrastive learning methods also include training the task model based on a third loss function, thereby improving the overall training performance of the task model, which includes both the encoder and decoder.
[0066] In one example, the loss function used for contrastive learning (encoder) is the sum of the first loss function and the second loss function:
[0067] L C =L icl +L ecl ,
[0068] The first loss function is: L icl =L cl (Combine[Q′;Q″]) , for constructing the first similar sample pair and the second dissimilar sample pair of the first loss function, the first training sample and the first similar augmented sample form the first similar sample pair, the first training sample and the second training sample form the first dissimilar sample pair, and the first training sample and the second similar augmented sample pair form the dissimilar sample pair. The Combine function is used to combine Q' and Q″. Q' and Q″ are two sample matrices (e.g., query embedding matrices) from the same input sample, and the first similar sample pair and the first dissimilar sample pair are constructed using Q' and Q″. The Combine function represents concatenating two N×m embedding matrices one-to-one into a 2N×m matrix. L cl It is a batch comparison loss function.
[0069] The second loss function is:
[0070] in, This is the labeled sample matrix of sample matrices Q' and Q''. The `combine` function is used to calculate the mean (as an example of weighted processing) between Q' and Q''. The combination of the first training sample and the first similarity enhancement sample, and the labeled sample of the first fusion sample, are determined as the second similar sample pair; the labeled samples of the first fusion sample and the second fusion sample are determined as the second dissimilar sample pair, that is, through Q', Q” and A second similar sample pair and a second dissimilar sample pair were constructed.
[0071] With both the encoder and decoder trained, the total loss function Lall is as follows:
[0072] L all =L G +w LC , where L G The generator loss (encoder-decoder) is used for the task model; the loss function used for contrastive learning is L. C w is the loss weight, based on L all When training the task model, the parameters of the task model are adjusted so that L all The maximum value is obtained.
[0073] Figure 4 This is a flowchart illustrating the steps of a query method according to another embodiment of the present invention. The solution of this embodiment can be applied to any suitable electronic device with data processing capabilities, including but not limited to: servers, mobile terminals (such as mobile phones, tablets, etc.), and PCs. For example, in the model training phase, a computing device (e.g., a data center) configured with a CPU (processor unit) + GPU (acceleration unit) architecture can be used to train the encoder-decoder model based on training samples. The computing device, such as in a data center, can be deployed in cloud servers such as dedicated clouds, private clouds, or hybrid clouds. Correspondingly, in the inference phase, a computing device configured with a CPU (processor unit) + GPU (acceleration unit) architecture can also be used for inference operations.
[0074] The query method in this embodiment includes:
[0075] S410: Obtain simplified query data.
[0076] S420: Based on simplified query data, input into the query rewriting model to obtain context query data.
[0077] S430: Perform a query based on the context query data to obtain the query results.
[0078] In the embodiments of the present invention, similar sample pairs and dissimilar sample pairs are constructed based at least on similar augmented samples and labeled samples of the training samples. This results in augmented samples composed of similar and dissimilar sample pairs having higher quality. Based on the inventive concept of contrastive learning, the function value of the constructed loss function is proportional to the similarity of similar sample pairs and inversely proportional to the similarity of dissimilar sample pairs. This loss function improves the confidence of the training samples, rather than simply augmenting the training samples themselves. Therefore, it improves the performance of the trained task model.
[0079] Figure 5 This is a flowchart of the steps of a human-computer dialogue method according to another embodiment of the present invention.
[0080] The human-computer dialogue method in this embodiment includes:
[0081] S510: Obtain a dialogue request.
[0082] S520: Parse the dialogue request to obtain simplified query data.
[0083] S530: Using query methods, perform queries based on simplified data to obtain query results.
[0084] S540: Based on the query results, generate a dialogue response to the dialogue request.
[0085] It should be understood that the query method can be... Figure 4 The query method of the embodiment.
[0086] It should also be understood that, Figure 1 In the example, parsing based on the dialogue request can be performed in the human-computer interaction module or in the dialogue server 120.
[0087] The human-computer dialogue method of this invention improves the accuracy of data query by training a query rewriting model through a collaborative training method, thereby improving the efficiency of human-computer dialogue.
[0088] Reference Figure 6 The diagram shows a schematic of an electronic device according to another embodiment of the present invention. The specific embodiments of the present invention do not limit the specific implementation of the electronic device.
[0089] like Figure 6 As shown, the electronic device may include: a processor 602, a communications interface 604, a memory 606 storing a program 610, and a communications bus 608.
[0090] The processor, communication interface, and memory communicate with each other via a communication bus.
[0091] A communication interface is used to communicate with other electronic devices or servers.
[0092] The processor is used to execute programs, specifically the relevant steps in the above method embodiments.
[0093] Specifically, the program may include program code, which includes computer operation instructions.
[0094] The processor may be a CPU, an Application Specific Integrated Circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present invention. The one or more processors included in a smart device may be of the same type, such as one or more CPUs; or they may be of different types, such as one or more CPUs and one or more ASICs.
[0095] Memory is used to store programs. Memory may include high-speed RAM, and may also include non-volatile memory, such as at least one disk drive.
[0096] Specifically, the program can be used to enable the processor to perform the following operations: construct similar sample pairs and dissimilar sample pairs based on training samples and their similar augmented samples; construct a loss function for the encoder of the task model based on the similarity of the similar sample pairs and the similarity of the dissimilar sample pairs, wherein the function value of the loss function is proportional to the similarity of the similar sample pairs and inversely proportional to the similarity of the dissimilar sample pairs; and train the encoder of the task model based on the loss function.
[0097] Alternatively, the program can specifically cause the processor to perform the following operations: obtain simplified query data; input the simplified query data into the query rewriting model to obtain context query data; and perform a query based on the context query data to obtain the query result.
[0098] Alternatively, the program can specifically cause the processor to perform the following operations: obtain a dialogue request; parse the dialogue request to obtain simplified query data; use a query method to perform a query based on the simplified data to obtain query results; and generate a dialogue response to the dialogue request based on the query results.
[0099] Furthermore, the specific implementation of each step in the program can be found in the corresponding descriptions of the steps and units in the above method embodiments, and will not be repeated here. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the devices and modules described above can be referred to the corresponding process descriptions in the foregoing method embodiments, and will not be repeated here.
[0100] It should be noted that, depending on the implementation needs, the various components / steps described in the embodiments of the present invention can be broken down into more components / steps, or two or more components / steps or parts of the operation of components / steps can be combined into new components / steps to achieve the purpose of the embodiments of the present invention.
[0101] The methods described above according to embodiments of the present invention can be implemented in hardware, firmware, or as software or computer code that can be stored in a recording medium (such as a CD-ROM, RAM, floppy disk, hard disk, or magneto-optical disk), or as computer code originally stored on a remote recording medium or a non-transitory machine-readable medium and subsequently stored on a local recording medium, downloaded via a network. Thus, the methods described herein can be processed by software stored on a recording medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware (such as an ASIC or FPGA). It is understood that the computer, processor, microprocessor controller, or programmable hardware includes storage components (e.g., RAM, ROM, flash memory, etc.) capable of storing or receiving software or computer code, which, when accessed and executed by the computer, processor, or hardware, implements the methods described herein. Furthermore, when a general-purpose computer accesses code used to implement the methods shown herein, the execution of the code transforms the general-purpose computer into a dedicated computer for executing the methods shown herein.
[0102] Those skilled in the art will recognize that the units and method steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of the embodiments of the present invention.
[0103] The above embodiments are only used to illustrate the embodiments of the present invention, and are not intended to limit the embodiments of the present invention. Those skilled in the art can make various changes and modifications without departing from the spirit and scope of the embodiments of the present invention. Therefore, all equivalent technical solutions also fall within the scope of the embodiments of the present invention, and the patent protection scope of the embodiments of the present invention should be defined by the claims.
Claims
1. A human-computer dialogue method, comprising: determining a first training sample and a corresponding first similar augmented sample as a first similar sample pair, and determining a second training sample and a corresponding second similar augmented sample as a first dissimilar sample pair; determining a first fused sample of the first training sample and the first similar augmented sample, and a labeled sample of the first fused sample as a second similar sample pair, and determining a second fused sample of the first fused sample and a labeled sample of the second fused sample as a second dissimilar sample pair; constructing a loss function of an encoder of a query rewriting model based on similarities of the similar sample pairs and the dissimilar sample pairs, a function value of the loss function being proportional to the similarities of the similar sample pairs and being inversely proportional to the similarities of the dissimilar sample pairs; training the encoder of the query rewriting model based on the loss function; analyzing a dialogue request to obtain simplified query data, and inputting the simplified query data into the query rewriting model to obtain context query data based on the simplified query data; performing a query based on the context query data to obtain a query result, and generating a dialogue reply to the dialogue request based on the query result.
2. The method of claim 1, wherein, The constructing of the loss function of the encoder of the query rewriting model based on the similarities of the similar sample pairs and the dissimilar sample pairs comprises: determining a first loss function based on the similarity of the first similar sample pair and the similarity of the first dissimilar sample pair, and determining a second loss function based on the similarity of the second similar sample pair and the similarity of the second dissimilar sample pair; determining the loss function of the encoder of the query rewriting model based on the first loss function and the second loss function.
3. The method of claim 1, wherein, The method further comprises: determining the first training sample and the second training sample as the first dissimilar sample pair.
4. The method of claim 2, wherein, The method further comprises: inputting an initial sample into the encoder with a first random inactivation probability and a second random inactivation probability to obtain the training sample and the similar augmented sample, respectively.
5. The method of claim 4, wherein, A first function value of the first loss function is proportional to the similarity of the first similar sample pair, and the first function value is inversely proportional to the similarity of the first dissimilar sample pair; wherein a second function value of the second loss function is proportional to the similarity of the second similar sample pair, and the second function value is inversely proportional to the similarity of the second dissimilar sample pair.
6. An electronic device, comprising: a processor, a memory, a communication interface, and a communication bus, the processor, the memory, and the communication interface completing communication with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction causes the processor to perform operations corresponding to the method in any one of claims 1-5.
7. A computer storage medium having a computer program stored thereon, the program being executed by a processor to implement the method in any one of claims 1-5.
Citation Information
Patent Citations
Pre-training model data processing method, electronic equipment and computer storage medium
CN114579606A