Dialogue generation method and device, electronic equipment and medium
By constructing training data pairs and optimizing the medical dialogue generation model using a kernel sampling algorithm, the problem of low efficiency in existing technologies is solved, achieving more efficient dialogue generation and higher quality generated responses.
Patent Information
- Application Number
- CN202310879218.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-18
- Publication Date
- 2026-02-13
- Estimated Expiration
- 2043-07-18
AI Technical Summary
Existing medical dialogue generation models are inefficient in digital healthcare scenarios, mainly due to the high requirements for labeled data, which leads to the low efficiency of supervised fine-tuning methods.
By acquiring a dialogue dataset, multiple model responses are generated using a kernel sampling algorithm, and training data pairs are constructed. The similarity is calculated using a preset index formula, and the loss function is optimized to train the dialogue generation model and improve generation efficiency.
It improves the optimization efficiency of the dialogue generation model, enhances the efficiency of dialogue generation, and generates responses that are closer to real responses, thereby improving the efficiency of dialogue generation in digital healthcare scenarios.
Smart Images

Figure CN116860944B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of artificial intelligence, and in particular to a dialogue generation method and device, electronic equipment and a storage medium. BACKGROUND
[0002] In the field of digital medicine, Internet hospitals are also being popularized, and patients hope to be able to inquire and get accurate replies in Internet hospitals. Behind the inquiry in the Internet hospital is to reply to the patient through a medical dialogue model. The medical dialogue model can learn a large amount of medical text and doctor-patient dialogue to simulate the communication between doctors and patients, and collect symptom information to provide diagnosis or provide drug recommendations. Therefore, the optimization of the medical dialogue model is very important. The existing optimization model method is usually realized by a supervised fine-tuning method. The supervised fine-tuning method requires very high-quality labeled data to train the model to stimulate the generation ability of the large model. However, this method requires high-quality labeled data, which results in low efficiency of dialogue generation. Therefore, it is urgent to propose a more efficient dialogue generation method. SUMMARY
[0003] The present application provides a dialogue generation method, device, electronic equipment and storage medium, which mainly aims to improve the efficiency of dialogue generation in the digital medical field.
[0004] To achieve the above-mentioned purpose, the present application provides a dialogue generation method, comprising:
[0005] Obtaining a dialogue data set, extracting dialogue splicing data and reference reply data in the dialogue data set, and constructing a training data pair according to the dialogue splicing data and the reference reply data;
[0006] Inputting the dialogue splicing data in the training data pair into a preset dialogue generation model, and generating a plurality of model replies corresponding to the dialogue splicing data according to a kernel sampling algorithm;
[0007] Calculating the similarity between the plurality of model replies and the reference reply data by using a preset index formula, obtaining a plurality of similarity values, constructing a final optimization loss function of the dialogue generation model based on the plurality of similarity values, training the dialogue generation model by using the final optimization loss function, and obtaining a standard generation model;
[0008] Inputting the to-be-processed data into the standard generation model to obtain a dialogue set corresponding to the to-be-processed data.
[0009] Optionally, the extracting the dialogue splicing data in the dialogue data set comprises:
[0010] identify a dialogue identifier corresponding to different dialogue data in the dialogue data set, and perform data partitioning on the dialogue data set according to the dialogue identifier to obtain a plurality of dialogue data;
[0011] The plurality of dialogue data are spliced to obtain dialogue splicing data.
[0012] Optionally, the generating a plurality of model replies corresponding to the dialogue splicing data according to the core sampling algorithm comprises:
[0013] The dialogue splicing data is input into the dialogue generation model to obtain a plurality of initial replies.
[0014] The plurality of initial replies are sorted according to a pre-constructed core sampling matrix to obtain sorted initial replies.
[0015] Extracting the replies in the sorted initial replies that meet the preset screening requirements as a screening reply set, and randomly sampling the replies in the screening reply set to obtain a plurality of model replies.
[0016] Optionally, before the sorting the plurality of initial replies according to the pre-constructed core sampling matrix, the method further comprises:
[0017] Obtaining a preset reference threshold and a temperature parameter, and constructing a core sampling function according to the reference threshold and the temperature parameter;
[0018] According to the core sampling function, a corresponding core sampling matrix is constructed.
[0019] Optionally, the extracting the replies in the sorted initial replies that meet the preset screening requirements as a screening reply set comprises:
[0020] Identifying the reply probability corresponding to different initial replies in the sorted initial replies, and adding the probabilities of the replies one by one according to the order of the sorted initial replies;
[0021] When the added probability value after adding one by one is greater than a preset reference threshold, the initial reply before adding is taken as the screening reply set.
[0022] Optionally, the constructing a final optimization loss function of the dialogue generation model based on the plurality of similarity values comprises:
[0023] According to a preset sorting value calculation formula, a training sorting value of the training data pair is calculated, and a sorting loss function is constructed according to the training sorting value and the plurality of similarity values;
[0024] A reply loss function corresponding to the real reply is constructed, and the sorting loss function and the reply loss function are summed to obtain a final optimization loss function.
[0025] Optionally, the training of the dialogue generation model by using the final optimization loss function comprises:
[0026] calculating a final optimization loss value of a training data pair in the dialogue generation model according to the final optimization loss function;
[0027] comparing the final optimization loss value with a preset reference threshold value, when the final optimization loss value is greater than or equal to the reference threshold value, adjusting parameters of the dialogue generation model until the final optimization loss value of the dialogue generation model after parameter adjustment is less than the reference threshold value, and taking the dialogue generation model after parameter adjustment as a standard generation model;
[0028] when the final optimization loss value is less than the reference threshold value, taking the dialogue generation model as a standard generation model.
[0029] To solve the above problems, the present application further provides a dialogue generation device, which comprises:
[0030] a data pair construction module configured to obtain a dialogue data set, extract dialogue concatenation data and reference reply data in the dialogue data set, and construct a training data pair according to the dialogue concatenation data and the reference reply data;
[0031] a model reply generation module configured to input the dialogue concatenation data in the training data pair into a preset dialogue generation model, and generate a plurality of model replies corresponding to the dialogue concatenation data according to a kernel sampling algorithm;
[0032] a model training module configured to calculate a similarity between the plurality of model replies and the reference reply data by using a preset index formula, obtain a plurality of similarity values, construct a final optimization loss function of the dialogue generation model based on the plurality of similarity values, train the dialogue generation model by using the final optimization loss function, and obtain a standard generation model;
[0033] a dialogue generation module configured to input to-be-processed data into the standard generation model, and obtain a dialogue set corresponding to the to-be-processed data.
[0034] To solve the above problems, the present application further provides an electronic device, which comprises:
[0035] at least one processor; and
[0036] a memory in communication connection with the at least one processor; wherein
[0037] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the dialogue generation method described above.
[0038] To address the aforementioned problems, the present invention also provides a storage medium storing at least one computer program, which is executed by a processor in an electronic device to implement the dialogue generation method described above.
[0039] In this embodiment of the invention, multiple model responses to a preset dialogue generation model are generated using a kernel sampling algorithm. The preset dialogue generation model is then optimized based on these responses. During optimization, an index formula is used as a reward function to measure the quality of the dialogue generation model. This eliminates the need for additional complex algorithms and network structures, further improving the optimization efficiency of the dialogue generation model. This also enhances the efficiency of generating dialogue sets corresponding to the data to be processed based on the dialogue generation model. Therefore, the dialogue generation method, apparatus, electronic device, and storage medium proposed in this invention can address the problem of low dialogue generation efficiency in digital healthcare scenarios. Attached Figure Description
[0040] Figure 1 This is a flowchart illustrating a dialogue generation method provided in an embodiment of the present invention;
[0041] Figure 2 for Figure 1 A detailed implementation flowchart of one of the steps;
[0042] Figure 3 This is a functional block diagram of a dialogue generation device provided in an embodiment of the present invention;
[0043] Figure 4 This is a schematic diagram of the structure of an electronic device that implements the dialogue generation method according to an embodiment of the present invention.
[0044] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0045] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0046] The embodiment of the application provides a dialogue generation method. The execution subject of the dialogue generation method includes at least one of electronic devices capable of being configured to execute the method provided by the embodiment of the application, such as a server and a terminal. In other words, the dialogue generation method can be executed by software or hardware installed in a terminal device or a server device, and the software can be a blockchain platform. The server includes but is not limited to a single server, a server cluster, a cloud server or a cloud server cluster, etc. The server can be a stand-alone server, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content distribution networks (CDN), and basic cloud computing services such as big data and artificial intelligence platforms.
[0047] Referring to Figure 1 FIG. 1 is a flowchart of a dialogue generation method provided by an embodiment of the application. In this embodiment, the dialogue generation method includes the following steps.
[0048] S1, obtaining a dialogue data set, extracting dialogue splicing data and reference reply data in the dialogue data set, and constructing a training data pair according to the dialogue splicing data and the reference reply data.
[0049] In the embodiment of the application, the dialogue data set is a data set composed of one or more questions and answers between users, wherein the dialogue data set can be a communication dialogue between a doctor and a patient in the medical care field, can involve inquiry of symptom information, provide professional advice for diagnosis or drug advice in related fields, etc.
[0050] For example, the dialogue data set can be Doctor A: "According to your test report and information, you can be diagnosed as hypertension." Patient B: "What should I pay attention to in daily life?" Doctor A: "We generally recommend that you pay attention to monitoring blood pressure and pay more attention to your diet and lifestyle in daily life." Patient B: "OK, thank you, doctor."
[0051] Specifically, the extracting dialogue splicing data in the dialogue data set includes:
[0052] identifying dialogue identifiers corresponding to different dialogue data in the dialogue data set, and performing data division on the dialogue data set according to the dialogue identifiers to obtain a plurality of dialogue data;
[0053] The plurality of dialogue data are spliced to obtain dialogue splicing data.
[0054] In detail, the dialogue identifier corresponding to different dialogue data refers to a user generating the dialogue data, so the dialogue identifier can be a doctor A, or the dialogue identifier is a patient B, the dialogue data set is divided according to the dialogue identifier of the doctor A, all dialogues about the doctor A are summarized together, the dialogue data set is divided according to the dialogue identifier of the patient B, all dialogues about the patient B are summarized together, the plurality of dialogue data is spliced to obtain dialogue splicing data, that is, all data in the dialogue data set is spliced.
[0055] Further, reference reply data in the dialogue data set is extracted, wherein the reference reply data is a data set for answering a question. The training data pair is constructed according to the dialogue splicing data and the reference reply data, and the training data pair is (context, response).
[0056] S2, the dialogue splicing data in the training data pair is input into a preset dialogue generation model, and a plurality of model replies corresponding to the dialogue splicing data are generated according to a kernel sampling algorithm.
[0057] In the embodiment of the application, the preset dialogue generation model can be applied to the communication and diagnosis process in the medical care field to generate dialogue, wherein the dialogue generation model can be composed of a neural network.
[0058] Specifically, referring to Figure 2 As shown in the figure, the plurality of model replies corresponding to the dialogue splicing data are generated according to the kernel sampling algorithm, comprising:
[0059] S21, the dialogue splicing data is input into the dialogue generation model to obtain a plurality of initial replies;
[0060] S22, the plurality of initial replies are sorted according to a pre-constructed kernel sampling matrix to obtain sorted initial replies;
[0061] S23, extracts the replies in the sorted initial replies that meet the preset screening requirements as a screening reply set, and randomly samples the replies in the screening reply set to obtain a plurality of model replies.
[0062] In detail, the kernel sampling algorithm (Nucleus Sampling) can solve the problem of repeated generation of text, so that the kernel sampling algorithm can be used in the application to solve the problem that the plurality of initial replies generated by the dialogue generation model may exist repeatedly, and the dialogue generation model is optimized.
[0063] Further, before the plurality of initial replies are sorted according to the pre-constructed kernel sampling matrix, the method further comprises:
[0064] Obtain a preset reference threshold and temperature parameters, and construct a kernel sampling function based on the reference threshold and temperature parameters;
[0065] Construct the corresponding kernel sampling matrix based on the kernel sampling function.
[0066] Specifically, the step of extracting responses that meet preset filtering requirements from the sorted initial responses as a filtered response set includes:
[0067] Identify the response probabilities corresponding to different initial responses in the sorted initial responses, and add the response probabilities one by one according to the order of the sorted initial responses;
[0068] When the sum of the probabilities of each response exceeds a preset reference threshold, the initial responses before the summation are used as the set of responses to be filtered.
[0069] For example, the probability of responding to initial response A is 0.5, the probability of responding to initial response B is 0.3, and the probability of responding to initial response C is 0.1. The sorted initial responses are {initial response A, initial response B, initial response C}. The probabilities of the responses are added one by one according to the order of the sorted initial responses. When the preset reference threshold is 0.7, the sum of the probabilities of initial response A and initial response B is 0.8. Therefore, the sum of the probabilities after adding them one by one is greater than the preset reference threshold. Thus, initial response A and initial response B are selected as the filter response set.
[0070] S3. Calculate the similarity between the multiple model responses and the reference response data using a preset index formula to obtain multiple similarity values. Construct the final optimized loss function of the dialogue generation model based on the multiple similarity values. Use the final optimized loss function to train the dialogue generation model to obtain a standard generation model.
[0071] In this embodiment of the invention, the step of calculating the similarity between the multiple model responses and the reference response data using a preset index formula to obtain multiple similarity values includes:
[0072] The preset index formula is:
[0073]
[0074] in, For the first Each model responds with a corresponding similarity value. To pre-set the penalty factor, Let n be the number of response segments in the model response, where n is the nth response segment in the model response. The segment similarity value is the value between the nth response segment in the model response and the response segment corresponding to the reference response data.
[0075] Specifically, the step of constructing the final optimized loss function of the dialogue generation model based on the multiple similarity values includes:
[0076] The training ranking value of the training data pair is calculated according to the preset ranking value calculation formula, and a ranking loss function is constructed based on the training ranking value and the multiple similarity values.
[0077] Construct a response loss function corresponding to the reference response data, and sum the sorting loss function and the response loss function to obtain the final optimized loss function.
[0078] Specifically, for each training data pair, the training ranking value corresponding to the training data pair is calculated as follows:
[0079]
[0080] in, For the first The training ranking values of each model. For reference, the response data, For reference, the modulus corresponding to the response data. For time parameters, For fixed parameters, This is for probability calculation.
[0081] Furthermore, the ranking loss function is:
[0082]
[0083] in, This is the sorting loss value. For the first Each model responds with a corresponding similarity value. For the first The training ranking values of each model. For the first Each model responds with a corresponding similarity value. For the first The training ranking values of each model.
[0084] Specifically, the recovery loss function is:
[0085]
[0086] in, To recover the loss value, For time parameters, For reference, the response data, For probability calculation, These are fixed parameters.
[0087] Further, the training of the dialogue generation model by using the final optimization loss function comprises:
[0088] According to the final optimization loss function, a final optimization loss value of a training data pair in the dialogue generation model is calculated.
[0089] The final optimization loss value is compared with a preset reference threshold value, when the final optimization loss value is greater than or equal to the reference threshold value, the dialogue generation model is adjusted in parameters until the final optimization loss value of the dialogue generation model after parameter adjustment is less than the reference threshold value, and the dialogue generation model after parameter adjustment is taken as a standard generation model.
[0090] When the final optimization loss value is less than the reference threshold value, the dialogue generation model is taken as the standard generation model.
[0091] In detail, the dialogue generation model is trained by using the final optimization loss function to obtain a standard generation model, and the obtained standard generation model is an optimized model, which can make the generated reply closer to the real reply in the subsequent dialogue generation process, thereby improving the dialogue generation quality.
[0092] S4, input the to-be-processed data into the standard generation model to obtain a dialogue set corresponding to the to-be-processed data.
[0093] In the embodiment of the application, the to-be-processed data refers to question data requiring a corresponding reply to be generated, which can be a question of a patient in different scenarios in the field of digital medical treatment. The to-be-processed data is input into the standard generation model to obtain a dialogue set corresponding to the to-be-processed data.
[0094] In the embodiment of the application, the plurality of model replies of the preset dialogue generation model are generated by using the kernel sampling algorithm, and the preset dialogue generation model is optimized by using the model replies. In the optimization process, the index formula is used as a reward function for measuring the quality of the dialogue generation model, without the need for additional complex algorithms and network structures, thereby further improving the optimization efficiency of the dialogue generation model and improving the efficiency of generating the dialogue set corresponding to the to-be-processed data according to the dialogue generation model. Therefore, the dialogue generation method provided by the application can improve the low efficiency of dialogue generation in the field of digital medical treatment.
[0095] As Figure 3 shown in the figure is a functional module diagram of a dialogue generation device provided by an embodiment of the application.
[0096] The dialogue generation device 100 can be installed in an electronic device. According to the implemented functions, the dialogue generation device 100 can include a data pair construction module 101, a model reply generation module 102, a model training module 103, and a dialogue generation module 104. The modules of the present application can also be referred to as units, which refer to a series of computer program segments that can be executed by an electronic device processor and can complete a fixed function, which are stored in the memory of the electronic device.
[0097] In the present embodiment, the functions of each module / unit are as follows:
[0098] The data pair construction module 101 is configured to obtain a dialogue data set, extract dialogue concatenation data and reference reply data in the dialogue data set, and construct training data pairs according to the dialogue concatenation data and the reference reply data.
[0099] The model reply generation module 102 is configured to input the dialogue concatenation data in the training data pairs into a preset dialogue generation model, and generate a plurality of model replies corresponding to the dialogue concatenation data according to a kernel sampling algorithm.
[0100] The model training module 103 is configured to calculate the similarity between the plurality of model replies and the reference reply data using a preset index formula, obtain a plurality of similarity values, construct a final optimization loss function of the dialogue generation model based on the plurality of similarity values, train the dialogue generation model using the final optimization loss function, and obtain a standard generation model.
[0101] The dialogue generation module 104 is configured to input the to-be-processed data into the standard generation model to obtain a dialogue set corresponding to the to-be-processed data.
[0102] In detail, the specific implementation of each module of the dialogue generation device 100 is as follows:
[0103] Step one, obtaining a dialogue data set, extracting dialogue concatenation data and reference reply data in the dialogue data set, and constructing training data pairs according to the dialogue concatenation data and the reference reply data.
[0104] In the present embodiment, the dialogue data set is a data set composed of one or more questions and answers between users, wherein the dialogue data set can be a communication dialogue between a doctor and a patient in the medical care field, can involve inquiry of symptom information, provide professional advice for diagnosis or drug advice, and the like.
[0105] For example, the dialogue dataset can be Doctor A: "According to your test report and information, you can be diagnosed with hypertension." Patient B: "What should I pay attention to in daily life?" Doctor A: "For hypertension, we generally recommend monitoring blood pressure and paying more attention to diet and lifestyle in daily life." Patient B: "OK, thank you, doctor."
[0106] Specifically, the dialogue splicing data in the dialogue dataset is extracted, including:
[0107] Identify the dialogue identifier corresponding to different dialogue data in the dialogue dataset, and divide the dialogue dataset according to the dialogue identifier to obtain a plurality of dialogue data;
[0108] Splice the plurality of dialogue data to obtain dialogue splicing data.
[0109] In detail, the dialogue identifier corresponding to different dialogue data refers to the user who generates the dialogue data, so the dialogue identifier can be Doctor A, or the dialogue identifier is Patient B. According to the dialogue identifier of Doctor A, the dialogue dataset is divided, and all dialogues about Doctor A are summarized together. According to the dialogue identifier of Patient B, the dialogue dataset is divided, and all dialogues about Patient B are summarized together. The plurality of dialogue data is spliced to obtain dialogue splicing data, that is, all data in the dialogue dataset are spliced.
[0110] Further, the reference reply data in the dialogue dataset is extracted, wherein the reference reply data is a data set for answering the question. According to the dialogue splicing data and the reference reply data, a training data pair is constructed, and the training data pair is (context, response).
[0111] Step 2, input the dialogue splicing data in the training data pair into the preset dialogue generation model, and generate a plurality of model replies corresponding to the dialogue splicing data according to the kernel sampling algorithm.
[0112] In the embodiment of the application, the preset dialogue generation model can be applied to the communication and diagnosis process in the medical care field to generate dialogue, wherein the dialogue generation model can be composed of a neural network.
[0113] Specifically, the plurality of model replies corresponding to the dialogue splicing data are generated according to the kernel sampling algorithm, including:
[0114] Input the dialogue splicing data into the dialogue generation model to obtain a plurality of initial replies;
[0115] According to the pre-constructed kernel sampling matrix, the plurality of initial replies are sorted to obtain sorted initial replies.
[0116] extracting the replies in the sorted initial replies that meet preset screening requirements as a screening reply set, and randomly sampling the replies in the screening reply set to obtain a plurality of model replies.
[0117] In detail, the nucleus sampling algorithm can solve the problem of repeated generated text, so that the adoption of the nucleus sampling algorithm in the application can solve the problem of repeated initial replies generated by the dialogue generation model, thereby optimizing the dialogue generation model.
[0118] Further, before the sorting processing of the plurality of initial replies according to the pre-constructed nucleus sampling matrix, the method further comprises:
[0119] obtaining a preset reference threshold and a temperature parameter, and constructing a nucleus sampling function according to the reference threshold and the temperature parameter;
[0120] constructing a corresponding nucleus sampling matrix according to the nucleus sampling function.
[0121] Specifically, the extracting the replies in the sorted initial replies that meet preset screening requirements as a screening reply set comprises:
[0122] identifying the reply probability corresponding to different initial replies in the sorted initial replies, and adding the probabilities of the replies one by one according to the order of the sorted initial replies;
[0123] When the added probability value after adding one by one is greater than the preset reference threshold, the initial reply before adding is taken as the screening reply set.
[0124] For example, the reply probability of initial reply A is 0.5, the reply probability of initial reply B is 0.3, and the reply probability of initial reply C is 0.1. The sorted initial replies are {initial reply A, initial reply B, initial reply C}. When the preset reference threshold is 0.7, the added value of the probabilities of initial reply A and initial reply B is 0.8, so the added probability value after adding one by one is greater than the preset reference threshold, and initial reply A and initial reply B are taken as the screening reply set.
[0125] Step three, calculating the similarity between the plurality of model replies and the reference reply data by using a preset index formula to obtain a plurality of similarity values, constructing a final optimization loss function of the dialogue generation model based on the plurality of similarity values, training the dialogue generation model by using the final optimization loss function to obtain a standard generation model.
[0126] In this embodiment of the invention, the step of calculating the similarity between the multiple model responses and the reference response data using a preset index formula to obtain multiple similarity values includes:
[0127] The preset index formula is:
[0128]
[0129] in, For the first Each model responds with a corresponding similarity value. To pre-set the penalty factor, Let n be the number of response segments in the model response, where n is the nth response segment in the model response. The segment similarity value is the value between the nth response segment in the model response and the response segment corresponding to the reference response data.
[0130] Specifically, the step of constructing the final optimized loss function of the dialogue generation model based on the multiple similarity values includes:
[0131] The training ranking value of the training data pair is calculated according to the preset ranking value calculation formula, and a ranking loss function is constructed based on the training ranking value and the multiple similarity values.
[0132] Construct a response loss function corresponding to the reference response data, and sum the sorting loss function and the response loss function to obtain the final optimized loss function.
[0133] Specifically, for each training data pair, the training ranking value corresponding to the training data pair is calculated as follows:
[0134]
[0135] in, For the first The training ranking values of each model. For reference, the response data, For reference, the modulus corresponding to the response data. For time parameters, For fixed parameters, This is for probability calculation.
[0136] Furthermore, the ranking loss function is:
[0137]
[0138] in, This is the sorting loss value. For the first Each model responds with a corresponding similarity value. For the first a training ranking value of the i-th model, a corresponding similarity value of the i-th model, a training ranking value of the i-th model, a corresponding similarity value of the i-th model, a training ranking value of the i-th model.
[0139] Specifically, the reply loss function is:
[0140]
[0141] wherein, a reply loss value, a time parameter, reference reply data, a probability calculation, a fixed parameter.
[0142] Further, the training processing of the dialogue generation model by using the final optimization loss function to obtain a standard generation model comprises:
[0143] calculating a final optimization loss value of a training data pair in the dialogue generation model according to the final optimization loss function;
[0144] comparing the final optimization loss value with a preset reference threshold value, when the final optimization loss value is greater than or equal to the reference threshold value, adjusting parameters of the dialogue generation model until the final optimization loss value of the dialogue generation model after parameter adjustment is less than the reference threshold value, and taking the dialogue generation model after parameter adjustment as a standard generation model;
[0145] when the final optimization loss value is less than the reference threshold value, taking the dialogue generation model as a standard generation model.
[0146] In detail, the training processing of the dialogue generation model by using the final optimization loss function to obtain a standard generation model, the obtained standard generation model is an optimized model, and in the subsequent dialogue generation process, the generated reply can be closer to the real reply, thereby improving the dialogue generation quality.
[0147] Step four, inputting the to-be-processed data into the standard generation model to obtain a dialogue set corresponding to the to-be-processed data.
[0148] In the embodiment of the application, the to-be-processed data refers to question data that needs to generate corresponding replies, which can be questions of patients in different scenarios in the field of digital medicine, and the to-be-processed data is input into the standard generation model to obtain a dialogue set corresponding to the to-be-processed data.
[0149] In the embodiment of the present application, the preset dialogue generation model is generated by a core sampling algorithm to generate a plurality of model replies, and the preset dialogue generation model is optimized according to the model reply. In the optimization process, an index formula is used as a reward function to measure the quality of the dialogue generation model. No additional complex algorithm and network structure are required, which further improves the optimization efficiency of the dialogue generation model. The efficiency of generating a dialogue set corresponding to the to-be-processed data according to the dialogue generation model is improved. Therefore, the dialogue generation device provided by the present application can improve the low efficiency of dialogue generation in the digital medical scene.
[0150] As shown in Figure 4 is a structural schematic diagram of an electronic device for implementing a dialogue generation method according to an embodiment of the present application.
[0151] The electronic device 1 can include a processor 10, a memory 11, a communication bus 12, and a communication interface 13, and can further include a computer program stored in the memory 11 and executable on the processor 10, such as a dialogue generation program.
[0152] In some embodiments, the processor 10 can be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same function or different functions. The processor 10 includes one or more central processing units (CPU), microprocessors, digital processing chips, graphics processors, combinations of various control chips, etc. The processor 10 is the control core of the electronic device. It connects all components of the electronic device through various interfaces and lines, executes programs or modules stored in the memory 11 (such as executing a dialogue generation program), and calls data stored in the memory 11 to perform various functions and process data of the electronic device.
[0153] The memory 11 includes at least one type of readable storage medium, such as a flash memory, a mobile hard disk, a multimedia card, a card-type memory (e.g., an SD or DX memory, etc.), a magnetic memory, a disk, an optical disk, etc. The memory 11 can be an internal storage unit of an electronic device in some embodiments, such as a mobile hard disk of the electronic device. The memory 11 can also be an external storage device of the electronic device in other embodiments, such as a plug-in mobile hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device. Further, the memory 11 can include both an internal storage unit and an external storage device of the electronic device. The memory 11 can be used not only to store application software and various data installed in the electronic device, such as the code of the dialogue generation program, but also to temporarily store data that has been output or will be output.
[0154] The communication bus 12 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. The bus is configured to enable connection and communication between the memory 11 and at least one processor 10, etc.
[0155] The communication interface 13 is used for communication between the electronic device and other devices, including a network interface and a user interface. Optionally, the network interface can include a wired interface and / or a wireless interface (e.g., a WI-FI interface, a Bluetooth interface, etc.), which is usually used to establish a communication connection between the electronic device and other electronic devices. The user interface can be a display, an input unit (such as a keyboard), and optionally, the user interface can also be a standard wired interface, a wireless interface. Optionally, in some embodiments, the display can be an LED display, a liquid crystal display, a touch liquid crystal display, an OLED (Organic Light-Emitting Diode) touch, etc. The display can also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device and to display a visualized user interface.
[0156] Figure 4 Only the electronic device with components is shown, and those skilled in the art can understand that, Figure 4The illustrated structure does not constitute a limitation on the electronic device 1, and can include fewer or more components than illustrated, or combine certain components, or arrange different components.
[0157] For example, although not shown, the electronic device can also include a power supply (such as a battery) to power the various components. Preferably, the power supply can be logically connected to the at least one processor 10 through a power management device, so that the power management device can implement functions such as charge management, discharge management, and power consumption management. The power supply can also include one or more direct current or alternating current power supplies, recharging devices, power supply fault detection circuits, power supply converters or inverters, power supply status indicators, and any other components. The electronic device can also include various sensors, Bluetooth modules, Wi-Fi modules, and the like, which are not described here.
[0158] It should be understood that the embodiments are only for illustration and are not limited in the scope of the patent application by this structure.
[0159] The dialogue generation program stored in the memory 11 in the electronic device 1 is a combination of multiple instructions, which, when executed in the processor 10, can implement:
[0160] Obtain a dialogue data set, extract dialogue concatenation data and reference reply data in the dialogue data set, and construct a training data pair according to the dialogue concatenation data and the reference reply data;
[0161] Input the dialogue concatenation data in the training data pair into a preset dialogue generation model, and generate multiple model replies corresponding to the dialogue concatenation data according to a kernel sampling algorithm;
[0162] Calculate the similarity between the multiple model replies and the reference reply data using a preset index formula to obtain multiple similarity values, construct a final optimization loss function of the dialogue generation model based on the multiple similarity values, train the dialogue generation model using the final optimization loss function, and obtain a standard generation model;
[0163] Input the data to be processed into the standard generation model to obtain a dialogue set corresponding to the data to be processed.
[0164] Specifically, the specific implementation method of the processor 10 on the above instructions can refer to the description of the related steps in the corresponding embodiments of the drawings, which is not described here.
[0165] Further, the modules / units integrated in the electronic device 1 are stored in a storage medium if they are realized in the form of software function units and sold or used as independent products. The storage medium can be volatile or non-volatile. For example, the computer readable medium can include any entity or device capable of carrying the computer program code, a recording medium, a U disk, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM).
[0166] The application further provides a storage medium, which stores a computer program. The computer program can realize the following when executed by a processor of an electronic device:
[0167] Obtaining a dialogue data set, extracting dialogue concatenation data and reference reply data in the dialogue data set, and constructing a training data pair according to the dialogue concatenation data and the reference reply data;
[0168] Inputting the dialogue concatenation data in the training data pair into a preset dialogue generation model, and generating a plurality of model replies corresponding to the dialogue concatenation data according to a kernel sampling algorithm;
[0169] Calculating the similarity between the plurality of model replies and the reference reply data by using a preset index formula, obtaining a plurality of similarity values, constructing a final optimization loss function of the dialogue generation model based on the plurality of similarity values, training the dialogue generation model by using the final optimization loss function, and obtaining a standard generation model;
[0170] Inputting the to-be-processed data into the standard generation model, and obtaining a dialogue set corresponding to the to-be-processed data.
[0171] In several embodiments provided in the application, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For example, the division of the modules is only a logical function division. In actual implementation, another division mode can be used.
[0172] The modules described as separate components can or can not be physically separated, and the components displayed as modules can or can not be physical units, i.e., they can be located in one place or distributed on multiple network units. According to actual needs, some or all of the modules can be selected to achieve the purpose of the embodiment scheme.
[0173] In addition, each function module in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of hardware plus software function modules.
[0174] It is obvious for those skilled in the art that the present application is not limited to the details of the above exemplary embodiments, and the present application can be implemented in other specific forms without departing from the spirit or essential characteristics of the present application.
[0175] Therefore, from any point of view, the embodiments should be regarded as exemplary and non-limiting, and the scope of the present application is defined by the appended claims rather than the above description, and therefore all changes falling within the meaning and scope of the equivalent elements of the claims are intended to be included in the present application. Any additional reference signs in the claims should not be considered as limiting the claims involved.
[0176] The blockchain referred to in the present application is a new application mode of distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm and other computer technologies. Blockchain, in essence, is a decentralized database, which is a series of data blocks associated using cryptographic methods, each data block containing information of a batch of network transactions, used to verify the validity (anti-fake) of the information and generate the next block. The blockchain can include a blockchain underlying platform, a platform product service layer, and an application service layer, etc.
[0177] The embodiments of the present application can acquire and process related data based on artificial intelligence technology. Among them, artificial intelligence (Artificial Intelligence, AI) is to use digital computers or digital computer controlled machines to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0178] In addition, it is obvious that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. The plurality of units or devices stated in the system claims can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names and not to indicate any particular order.
[0179] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application and are not limiting. Although the present application has been described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that the technical solutions of the present application can be modified or replaced equivalently without departing from the spirit and scope of the technical solutions of the present application.
Claims
1. A dialogue generation method, characterized by, The method comprises: Obtaining a dialogue data set, extracting dialogue splicing data and reference reply data in the dialogue data set, and constructing a training data pair according to the dialogue splicing data and the reference reply data, the reference reply data being a data set for answering questions, the extracting the dialogue splicing data in the dialogue data set comprising: identifying dialogue identifiers corresponding to different dialogue data in the dialogue data set, performing data division on the dialogue data set according to the dialogue identifiers to obtain a plurality of dialogue data, and performing splicing processing on the plurality of dialogue data to obtain dialogue splicing data; Inputting the dialogue splicing data in the training data pair into a preset dialogue generation model, and generating a plurality of model replies corresponding to the dialogue splicing data according to a kernel sampling algorithm; Calculating the similarity between the plurality of model replies and the reference reply data by using a preset index formula to obtain a plurality of similarity values, constructing a final optimization loss function of the dialogue generation model based on the plurality of similarity values, training the dialogue generation model by using the final optimization loss function, and obtaining a standard generation model; Inputting the to-be-processed data into the standard generation model to obtain a dialogue set corresponding to the to-be-processed data.
2. The dialogue generation method of claim 1, wherein, The generating a plurality of model replies corresponding to the dialogue splicing data according to the kernel sampling algorithm comprises: Inputting the dialogue splicing data into the dialogue generation model to obtain a plurality of initial replies; Performing sorting processing on the plurality of initial replies according to a pre-constructed kernel sampling matrix to obtain sorted initial replies; Extracting replies that meet a preset screening requirement from the sorted initial replies as a screening reply set, and performing random sampling on the replies in the screening reply set to obtain a plurality of model replies.
3. The dialogue generation method of claim 2, wherein, Before the performing sorting processing on the plurality of initial replies according to the pre-constructed kernel sampling matrix, the method further comprises: Obtaining a preset reference threshold and a temperature parameter, and constructing a kernel sampling function according to the reference threshold and the temperature parameter; Constructing a corresponding kernel sampling matrix according to the kernel sampling function.
4. The dialogue generation method of claim 2, wherein, The extracting replies that meet a preset screening requirement from the sorted initial replies as a screening reply set comprises: Identifying reply probabilities corresponding to different initial replies in the sorted initial replies, and adding the reply probabilities one by one according to the order of the sorted initial replies; When the added probability value after adding the reply probabilities one by one is greater than a preset reference threshold, adding the initial reply before the adding as a screening reply set.
5. The dialogue generation method of claim 1, wherein, The constructing a final optimization loss function of the dialogue generation model based on the plurality of similarity values comprises: Calculating a training sorting value of the training data pair according to a preset sorting value calculation formula, constructing a sorting loss function according to the training sorting value and the plurality of similarity values; Constructing a reply loss function corresponding to the reference reply data, and performing summation processing on the sorting loss function and the reply loss function to obtain a final optimization loss function.
6. The dialogue generation method of claim 1, wherein, The training the dialogue generation model by using the final optimization loss function to obtain a standard generation model comprises: calculating a final optimization loss value of a training data pair in the dialogue generation model according to the final optimization loss function; comparing the final optimization loss value with a preset reference threshold value, when the final optimization loss value is greater than or equal to the reference threshold value, adjusting parameters of the dialogue generation model until the final optimization loss value of the dialogue generation model after parameter adjustment is less than the reference threshold value, and taking the dialogue generation model after parameter adjustment as a standard generation model; when the final optimization loss value is less than the reference threshold value, taking the dialogue generation model as a standard generation model.
7. A dialogue generation device characterized by comprising: The device comprises: a data pair construction module configured to obtain a dialogue data set, extract dialogue concatenation data and reference reply data in the dialogue data set, and construct a training data pair according to the dialogue concatenation data and the reference reply data, the reference reply data being a data set for answering a question, the extracting the dialogue concatenation data in the dialogue data set comprising: identifying dialogue identifiers corresponding to different dialogue data in the dialogue data set, performing data division on the dialogue data set according to the dialogue identifiers to obtain a plurality of dialogue data, and performing concatenation processing on the plurality of dialogue data to obtain dialogue concatenation data; a model reply generation module configured to input dialogue concatenation data in the training data pair into a preset dialogue generation model, and generate a plurality of model replies corresponding to the dialogue concatenation data according to a kernel sampling algorithm; a model training module configured to calculate similarities between the plurality of model replies and the reference reply data by using a preset index formula, obtain a plurality of similarity values, construct a final optimization loss function of the dialogue generation model based on the plurality of similarity values, train the dialogue generation model by using the final optimization loss function, and obtain a standard generation model; a dialogue generation module configured to input to-be-processed data into the standard generation model, and obtain a dialogue set corresponding to the to-be-processed data.
8. An electronic device, comprising: The electronic device comprises: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the dialogue generation method in any one of claims 1 to 6.
9. A storage medium storing a computer program, characterized in that, The computer program is executed by the processor to implement the dialogue generation method in any one of claims 1 to 6.
Citation Information
Patent Citations
Emotion controllable reply generation method using fine tuning and reordering strategies
CN113139042A
Role dialogue simulation method and device, equipment and storage medium
CN114822812A