Role dialogue simulation method, device, equipment and storage medium

Through the classification of dialogue materials and the construction of pre-training models, combined with position coding and repetitive screening sampling technology, the problem of insufficient flexibility in character intelligent dialogue simulation is solved, and the diversity and adaptability of dialogue simulation are achieved.

CN114822812BActive Publication Date: 2024-09-13PING AN TECH (SHENZHEN) CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202210370868.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-11
Publication Date
2024-09-13
Estimated Expiration
2042-04-11

AI Technical Summary

Technical Problem

Intelligent dialogue between characters in the existing dialogue simulation system is not flexible enough, has a single scenario, and cannot meet diverse dialogue needs.

Method used

By acquiring and classifying dialogue data, we build a pre-trained dialogue model, use position coding and matrix calculation to generate dialogue, and combine it with repetitive screening and sampling technology to generate dialogue that matches actual scenarios.

Benefits of technology

It achieves the flexibility of conversation simulation, and the generated replies are not limited to fixed answers, but can understand specific language scenarios and adapt to diverse application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114822812B
    Figure CN114822812B
Patent Text Reader

Abstract

The present invention relates to natural language processing technology, and discloses a method for simulating role dialogue, including: classifying dialogue materials into roles and cleaning texts to obtain training texts corresponding to different roles, using a constructed pre-trained dialogue model to perform position encoding, matrix calculation and prediction calculation on the training texts to obtain prediction results, and determining whether to stop training according to the correlation results calculated from the prediction results, and if the training is stopped, obtaining a dialogue model; performing text processing on user input, inputting the processed text into the dialogue model for calculation to obtain output results, performing repeatability screening and sampling on the output results to obtain target output results, judging whether sentence generation is completed according to the output results, and when sentence generation is completed, splicing the target output results to obtain a reply dialogue. The present invention also proposes a role dialogue simulation device, an electronic device and a storage medium. The present invention can improve the flexibility of role intelligent dialogue simulation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of natural language processing technology, and in particular to a role dialogue simulation method, device, electronic device and computer-readable storage medium. Background Art

[0002] With the rapid development of artificial intelligence, the application of computer technology in the field of intelligent question and answer and dialogue simulation has gradually increased. For example, in the field of medical consultation, targeted inquiries are required about the patient's physical condition, symptoms, disease development and other information, which is an important source for doctors to obtain information about patients' symptoms. Nowadays, natural language processing technology can be used to build an intelligent consultation dialogue system to alleviate the information asymmetry between doctors and patients and promote the efficient use of medical resources. Simulating the dialogue between users and doctors is the core of realizing intelligent medical consultation and disease diagnosis. In the dialogue simulation system of the prior art, template question and answer and question and answer library question and answer methods are often used, which have the problems of single scene and insufficient flexibility of role intelligent dialogue simulation. Summary of the invention

[0003] The present invention provides a method, device and computer-readable storage medium for simulating character dialogue, the main purpose of which is to solve the problem that the character intelligent dialogue simulation is not flexible enough.

[0004] To achieve the above object, the present invention provides a role dialogue simulation method, comprising:

[0005] Acquire a dialogue corpus, perform role classification and text cleaning on the dialogue corpus, and obtain training texts corresponding to different roles;

[0006] Constructing a pre-trained dialogue model, and using the pre-trained dialogue model to positionally encode the training texts corresponding to the different roles to obtain a text matrix;

[0007] Performing matrix calculation and prediction calculation on the text matrix to obtain a predicted dialogue, calculating a relevance result according to the predicted dialogue and the training text, and determining whether the relevance result is greater than a preset threshold;

[0008] If the correlation result is less than or equal to the threshold, the text matrix is ​​updated, and the process returns to the step of performing matrix calculation and prediction calculation on the text matrix;

[0009] If the relevance result is greater than the threshold, the training is stopped to obtain a dialogue model;

[0010] Determine the role of the dialogue model according to preset conditions, obtain user input, perform text processing on the user input, and obtain a target text;

[0011] Inputting the target text into the dialogue model to obtain a model output result, performing repetitive screening and sampling on the model output result to obtain a target output result, and judging whether sentence generation is completed according to the target output result;

[0012] If the sentence generation is not finished, return to the step of inputting the target text into the dialogue model.

[0013] If the sentence generation is completed, the target output results are concatenated to obtain a reply dialogue.

[0014] Optionally, the performing role classification and text cleaning on the dialogue corpus to obtain training texts corresponding to different roles includes:

[0015] Inputting the dialogue data into a preset classification model to obtain a role prediction result corresponding to the dialogue data;

[0016] Classifying the dialogue corpus according to the role prediction results to obtain corpus corresponding to each role;

[0017] Eliminate the preset characters in the corpus corresponding to each role to obtain a first text corresponding to each role;

[0018] Performing semantic recognition on the first text, calculating the distance between the semantic recognition result and a preset text vector, deleting the text corresponding to the semantic recognition result whose distance value is less than a preset threshold, and obtaining a second text corresponding to each character;

[0019] The second texts corresponding to each character are concatenated to obtain the training texts corresponding to each character.

[0020] Optionally, the step of concatenating the second texts corresponding to each role to obtain the training text corresponding to each role includes:

[0021] Selecting a role from multiple roles as a target role, and using a second text corresponding to the target role as a target text;

[0022] The average sentence length is calculated based on the target text, and the length of the target text is set according to the average sentence length. The target text with the set length is concatenated from beginning to end to obtain a training text corresponding to the target role.

[0023] Optionally, the building of a pre-trained dialogue model includes:

[0024] The model is divided into four parts: the first part is the vector generation layer, the second part is the first vector processing layer, the third part is the second vector processing layer, and the fourth part is the prediction layer.

[0025] Adding a position encoding structure and an Embedding structure in the vector generation layer;

[0026] Adding a LayerNorm structure, a Masked Multi self-Attention structure, and a residual connection structure to the first vector processing layer;

[0027] Adding a LayerNorm structure, a Feed Forward structure, and a residual connection structure in the second vector processing layer;

[0028] Add the LayerNorm structure and prediction function in the prediction layer.

[0029] Optionally, performing matrix calculation and prediction calculation on the text matrix to obtain a predicted dialogue includes:

[0030] Using the first vector processing layer to normalize, perform attention calculation and residual calculation on the text matrix to obtain a first vector matrix;

[0031] Using the text matrix of the second vector processing layer to perform normalization, feedforward neural adjustment, and residual calculation to obtain a second vector matrix;

[0032] Normalizing the second vector matrix using the prediction layer, and inputting the normalized result into a prediction function to obtain a prediction result, wherein the prediction result includes a predicted word and an end character;

[0033] Determine whether the prediction result is a predicted character or an end character;

[0034] If the prediction result is predicted text, return to the step of using the first vector processing layer to normalize, calculate attention and calculate residual on the text matrix to obtain a first vector matrix;

[0035] If the predicted result is an end character, all the predicted results are concatenated to obtain a predicted dialogue.

[0036] Optionally, the calculating a relevance result according to the predicted dialogue and the training text includes:

[0037] Obtaining training texts of other characters other than the character corresponding to the predicted dialogue, and using the training texts of the other characters as comparison texts;

[0038] Generate a comparison matrix according to the comparison text, and perform linearization processing on the comparison matrix to obtain a first linear vector;

[0039] The first linear vector is feature compressed to obtain a second linear vector, a correlation of a word vector corresponding to the predicted dialogue is extracted from the second linear vector, and the correlation result is input into a preset probability output function to obtain a correlation result.

[0040] Optionally, the repetitive screening and sampling of the model output results to obtain target output results includes:

[0041] Obtain all output results of the dialogue model after the last terminator;

[0042] Performing repeatability test on the model output result and all the output results;

[0043] If a repeated output result appears, the repeated output result is removed from the dialogue model according to a preset repetitiveness penalty, and the model output result is regenerated using the dialogue model, and the step of performing repetitiveness detection on the model output result and all the output results is returned;

[0044] If no repeated output results appear, random sampling is performed among the model output results, and the sampling results are used as the target output results.

[0045] In order to solve the above problems, the present invention also provides a role dialogue simulation device, the device comprising:

[0046] A text generation module is used to obtain dialogue data, perform role classification and text cleaning on the dialogue data to obtain training texts corresponding to different roles, determine the roles of the dialogue model according to preset conditions, obtain user input, perform text processing on the user input, and obtain target text;

[0047] A text matrix generation module is used to construct a pre-trained dialogue model, and use the pre-trained dialogue model to position encode the training texts corresponding to the different roles to obtain a text matrix;

[0048] A model training module is used to perform matrix calculation and prediction calculation on the text matrix to obtain a predicted dialogue, calculate a relevance result based on the predicted dialogue and the training text, and determine whether the relevance result is greater than a preset threshold; if the relevance result is less than or equal to the threshold, update the text matrix, and return to the step of performing matrix calculation and prediction calculation on the text matrix; if the relevance result is greater than the threshold, stop training and obtain a dialogue model;

[0049] A model prediction module, used for inputting the target text into the dialogue model to obtain a model output result, and performing repetitive screening and sampling on the model output result to obtain a target output result;

[0050] The reply dialogue generation module is used to splice the target output results to obtain a reply dialogue.

[0051] In order to solve the above problem, the present invention further provides an electronic device, the electronic device comprising:

[0052] at least one processor; and,

[0053] a memory communicatively connected to the at least one processor; wherein,

[0054] 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 so that the at least one processor can execute the role dialogue simulation method described above.

[0055] In order to solve the above problem, the present invention also provides a computer-readable storage medium, in which at least one computer program is stored. The at least one computer program is executed by a processor in an electronic device to implement the above-mentioned role dialogue simulation method.

[0056] The embodiment of the present invention processes the dialogue corpus and then uses the processed dialogue corpus as a training text output model for training, thereby obtaining a dialogue model. That is, through the constructed dialogue model, it is possible to understand the specific language scenario of the interlocutor in the dialogue corpus, thereby generating a dialogue that conforms to the actual application scenario; by repeatedly screening and sampling the output results of the dialogue model, the generated reply dialogue is not limited to fixed answers and is more flexible. Therefore, the role dialogue simulation method, device, electronic device and computer-readable storage medium proposed in the present invention can solve the problem that role intelligent dialogue simulation is not flexible enough. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] Figure 1 A schematic diagram of a flow chart of a method for simulating character dialogue provided by an embodiment of the present invention;

[0058] Figure 2 A schematic diagram of a process for role classification and text cleaning of dialogue data provided by an embodiment of the present invention;

[0059] Figure 3 A schematic diagram of a process for repeatability screening and sampling of model output results provided by an embodiment of the present invention;

[0060] Figure 4 A functional module diagram of a role dialogue simulation device provided by an embodiment of the present invention;

[0061] Figure 5 A schematic diagram of the structure of an electronic device for implementing the role dialogue simulation method provided by an embodiment of the present invention.

[0062] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0063] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0064] The embodiment of the present application provides a role dialogue simulation method. The execution subject of the role dialogue simulation method includes but is not limited to at least one of the electronic devices such as the server, the terminal, etc. that can be configured to execute the method provided by the embodiment of the present application. In other words, the role dialogue simulation method can be executed by software or hardware installed on 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 an independent server, or it can be a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and basic cloud computing services such as big data and artificial intelligence platforms.

[0065] Reference Figure 1 FIG. 2 is a flow chart of a method for simulating a role dialogue provided by an embodiment of the present invention. In this embodiment, the method for simulating a role dialogue includes:

[0066] S1. Acquire dialogue corpus, perform role classification and text cleaning on the dialogue corpus, and obtain training texts corresponding to different roles.

[0067] In the embodiment of the present invention, the dialogue data may be a dialogue data between a doctor and a patient, a dialogue data between a user and customer service, etc. in an actual application scenario.

[0068] In an embodiment of the present invention, a large amount of dialogue data can be captured from the Internet using crawler technology, or a large amount of dialogue data can be obtained from a pre-built storage area for storing various types of dialogue data using computer statements with crawling functions (such as java statements, python statements, etc.), wherein the storage area includes but is not limited to a database, a blockchain node, a network cache, etc.

[0069] In the embodiment of the present invention, please refer to Figure 2 As shown, the role classification and text cleaning of the dialogue corpus to obtain training texts corresponding to different roles include:

[0070] S21, inputting the dialogue data into a preset classification model to obtain a role prediction result corresponding to the dialogue data;

[0071] S22, classifying the dialogue corpus according to the role prediction result to obtain corpus corresponding to each role;

[0072] S23, removing the preset characters in the corpus corresponding to each role, to obtain a first text corresponding to each role;

[0073] S24, performing semantic recognition on the first text, calculating the distance between the semantic recognition result and the preset text vector, deleting the text corresponding to the semantic recognition result whose distance value is less than a preset threshold, and obtaining a second text corresponding to each role;

[0074] S25. Concatenate the second texts corresponding to each role respectively to obtain a training text corresponding to each role.

[0075] In an embodiment of the present invention, a natural language processing (NLP) model may be used to semantically recognize the first text corresponding to each role, and the semantic recognition result is expressed in the form of a text vector.

[0076] In the embodiment of the present invention, taking medical consultation as an example, the text corresponding to the patient role in the consultation text may contain physical condition, symptom information, living habits, examination report, etc. Among them, the examination report is not the text required for dialogue model training, so the text vector corresponding to the examination report can be used as the preset text vector. By calculating the distance value between the semantic recognition result and the preset text vector, it is determined whether the text corresponding to the role contains the text type. The smaller the distance value, the higher the vector correlation result. Then, if the correlation result is less than the preset threshold, it means that the first text corresponding to the speech recognition result is the text type corresponding to the preset text vector.

[0077] Specifically, the distance between the semantic recognition result and the preset text vector can be calculated by the following formula:

[0078]

[0079] Wherein, D is the distance value, R is the i-th preset text vector, T is the semantic recognition result, and θ is the preset coefficient.

[0080] In the embodiment of the present invention, the second texts corresponding to each role are concatenated to obtain the training texts corresponding to each role, including:

[0081] Selecting a role from multiple roles as a target role, and using a second text corresponding to the target role as a target text;

[0082] The average sentence length is calculated based on the target text, and the length of the target text is set according to the average sentence length. The target text with the set length is concatenated from beginning to end to obtain a training text corresponding to the target role.

[0083] Furthermore, the second text corresponding to each role may be processed to be of uniform length according to the average sentence length, and then the beginning and the end of the text may be concatenated to obtain the training text corresponding to each role.

[0084] In an embodiment of the present invention, after generating a training text corresponding to each role, different role labels can be set for the training text according to different roles. For example, the role label corresponding to the doctor is doctor, and the role label corresponding to the patient is patient. The role labels can be spliced ​​in front of the training text to form a role identification.

[0085] S2. Construct a pre-trained dialogue model, and use the pre-trained dialogue model to position-encode the training texts corresponding to the different roles to obtain a text matrix.

[0086] In an embodiment of the present invention, the pre-trained dialogue model may be composed of a decoder part of a multi-layer unidirectional Transformer, which is an autoregressive model. The pre-trained dialogue model includes but is not limited to a GPT-2 (Generative Pre-training 2.0) model.

[0087] In the embodiment of the present invention, the step of constructing a pre-trained dialogue model includes:

[0088] The model is divided into four parts: the first part is the vector generation layer, the second part is the first vector processing layer, the third part is the second vector processing layer, and the fourth part is the prediction layer.

[0089] Adding a position encoding structure and an Embedding structure in the vector generation layer;

[0090] Adding a LayerNorm structure, a Masked Multi self-Attention structure, and a residual connection structure to the first vector processing layer;

[0091] Adding a LayerNorm structure, a Feed Forward structure, and a residual connection structure in the second vector processing layer;

[0092] Add the LayerNorm structure and prediction function in the prediction layer.

[0093] In an embodiment of the present invention, the Embedding structure is used to concatenate word embedding with position coding, the LayerNorm structure is used to normalize the horizontal feature dimension of the input data, the Masked Multiself-Attention structure is used to calculate multiple attentions for the input Embedding and concatenate the calculation results, the residual connection structure superimposes the output results of the remaining structures in the processing layer through the residual network structure, and the FeedForward structure adjusts the feedforward neural factor according to the normalized matrix.

[0094] In the embodiment of the present invention, the position encoding of the training texts corresponding to the different roles by using the pre-trained dialogue model to obtain a text matrix includes:

[0095] Convert each word in the training text into a word vector to obtain a word vector set, and perform position encoding on the word vector set to obtain a positioning word vector set;

[0096] The positioning word vector set is converted into a positioning vector matrix, and a text matrix is ​​generated according to the dimension of the positioning vector matrix.

[0097] In the embodiment of the present invention, the Word2vec algorithm may be used to convert each word in the training text into a word vector.

[0098] In the embodiment of the present invention, performing position encoding on the word vector set includes:

[0099] Randomly extracting a word vector from the word vector set as a coordinate vector, and taking the position of the coordinate vector as a coordinate origin;

[0100] A position vector of each character vector in the character vector set is established according to the coordinate origin, and position encoding is performed on the character vector set using the position vector.

[0101] In the embodiment of the present invention, the farther the word vector is from the word vector corresponding to the encoded word, the larger the modulus of the position vector corresponding to the word vector is.

[0102] In an embodiment of the present invention, the dimension of the text matrix is ​​the same as that of the positioning vector matrix. For example, if the dimension of the positioning vector matrix is ​​m×n, the dimension of the generated text matrix is ​​also m×n. In an embodiment of the present invention, a random method can be used to generate the text matrix.

[0103] S3. Perform matrix calculation and prediction calculation on the text matrix to obtain a predicted dialogue, calculate a relevance result based on the predicted dialogue and the training text, and determine whether the relevance result is greater than a preset threshold.

[0104] In the embodiment of the present invention, performing matrix calculation and prediction calculation on the text matrix to obtain the predicted dialogue includes:

[0105] Using the first vector processing layer to normalize, perform attention calculation and residual calculation on the text matrix to obtain a first vector matrix;

[0106] Using the text matrix of the second vector processing layer to perform normalization, feedforward neural adjustment, and residual calculation to obtain a second vector matrix;

[0107] Normalizing the second vector matrix using the prediction layer, and inputting the normalized result into a prediction function to obtain a prediction result, wherein the prediction result includes a predicted word and an end character;

[0108] Determine whether the prediction result is a predicted character or an end character;

[0109] If the prediction result is predicted text, return to the step of using the first vector processing layer to normalize, calculate attention and calculate residual on the text matrix to obtain a first vector matrix;

[0110] If the predicted result is an end character, all the predicted results are concatenated to obtain a predicted dialogue.

[0111] In the embodiment of the present invention, the calculating of the relevance result according to the predicted dialogue and the training text includes:

[0112] Obtaining training texts of other characters other than the character corresponding to the predicted dialogue, and using the training texts of the other characters as comparison texts;

[0113] Generate a comparison matrix according to the comparison text, and perform linearization processing on the comparison matrix to obtain a first linear vector;

[0114] The first linear vector is feature compressed to obtain a second linear vector, a correlation of a word vector corresponding to the predicted dialogue is extracted from the second linear vector, and the correlation result is input into a preset probability output function to obtain a correlation result.

[0115] In the embodiment of the present invention, the probability output function may use a Softmax function to perform probability calculation according to the correlation to obtain a correlation result between the predicted dialogue and the training text.

[0116] If the relevance result is less than or equal to the threshold, execute S4, update the text matrix, and return to S3.

[0117] In the embodiment of the present invention, if the relevance result is less than or equal to the threshold, the input text may be re-position-encoded and re-joined, thereby re-adjusting the pre-trained dialogue model.

[0118] If the relevance result is greater than the threshold, S5 is executed to stop training and obtain a dialogue model.

[0119] In the embodiment of the present invention, if the relevance result is greater than the threshold, it means that the prediction of the pre-trained dialogue model is correct, and there is no need to update the text matrix and readjust the dialogue model.

[0120] S6. Determine the role of the dialogue model according to preset conditions, obtain user input, perform text processing on the user input, and obtain a target text.

[0121] In the embodiment of the present invention, the preset condition may be inputting a role instruction, and determining the role of the dialogue model according to the role instruction.

[0122] In the embodiment of the present invention, the step of performing text processing on the user input to obtain the target text is similar to the step of performing role classification and text cleaning on the dialogue corpus to obtain training texts corresponding to different roles in the above S1, and will not be elaborated here.

[0123] S7. Input the target text into the dialogue model to obtain a model output result, perform repetitive screening and sampling on the model output result to obtain a target output result, and determine whether sentence generation is completed based on the target output result.

[0124] In the embodiment of the present invention, the step of inputting the target text into the dialogue model to obtain the model output result is similar to the steps of constructing a pre-trained dialogue model in the above S2-S3, and using the pre-trained dialogue model to positionally encode the training texts corresponding to the different roles to obtain a text matrix, and performing matrix calculation and prediction calculation on the text matrix, which will not be elaborated here.

[0125] In the embodiment of the present invention, please refer to Figure 3 As shown, the model output results are repeatedly screened and sampled to obtain target output results, including:

[0126] S31, obtaining all output results of the dialogue model after the last end symbol;

[0127] S32, performing repeatability test on the model output result and all the output results;

[0128] If repeated output results appear, execute S33, remove the repeated output results in the dialogue model according to a preset repetitive penalty, regenerate the model output results using the dialogue model, and return to S32;

[0129] If no repeated output results appear, S34 is executed to perform random sampling in the model output results, and the sampling results are used as the target output results.

[0130] In the embodiment of the present invention, the penalty rule may be to add a penalty item weight parameter to penalize tokens with high repetitiveness in output results to reduce the generation probability.

[0131] In the embodiment of the present invention, the random sampling may be Softmax-Topk sampling.

[0132] In the embodiment of the present invention, whether the sentence generation is finished can be determined by judging whether there is a terminator in the target output result.

[0133] If the sentence generation is not finished, return to S7.

[0134] In the embodiment of the present invention, if the sentence generation is not completed, that is, the terminator is not detected, it means that the reply dialogue is not completely generated, and the dialogue model needs to continue to make predictions until the terminator is detected and the sentence generation is completed.

[0135] If the sentence generation is completed, S8 is executed to splice the target output results to obtain a reply dialogue.

[0136] In the embodiment of the present invention, when the sentence ends, the model output result obtained may be multiple output results, which does not form a complete dialogue. Therefore, it is necessary to splice the multiple output results to obtain a reply dialogue.

[0137] Furthermore, the plurality of target output results may be scored using a preset semantic scoring model, a weight of each target output result may be set according to the scoring result, and the plurality of target output results may be concatenated according to the weight.

[0138] In the embodiment of the present invention, the semantic scoring model includes but is not limited to Deep Structured Semantic Models (DSSM) and Natural Language Processing Models (NPL).

[0139] The embodiment of the present invention processes the dialogue corpus and then uses the processed dialogue corpus as a training text output model for training, thereby obtaining a dialogue model. That is, through the constructed dialogue model, the specific language scenario of the interlocutor in the dialogue corpus can be understood, and a dialogue that conforms to the actual application scenario can be generated; by repeatedly screening and sampling the output results of the dialogue model, the generated reply dialogue is not limited to fixed answers and is more flexible. Therefore, the role dialogue simulation method proposed in the present invention can solve the problem that role intelligent dialogue simulation is not flexible enough.

[0140] like Figure 4 , which is a functional module diagram of a role dialogue simulation device provided by an embodiment of the present invention.

[0141] The role dialogue simulation device 100 of the present invention can be installed in an electronic device. According to the functions to be implemented, the role dialogue simulation device 100 can include a text generation module 101, a text matrix generation module 102, a model training module 103, a model prediction module 104 and a reply dialogue generation module 105. The module of the present invention can also be called a unit, which refers to a series of computer program segments that can be executed by an electronic device processor and can complete fixed functions, which are stored in the memory of the electronic device.

[0142] In this embodiment, the functions of each module / unit are as follows:

[0143] The text generation module 101 is used to obtain dialogue data, perform role classification and text cleaning on the dialogue data to obtain training texts corresponding to different roles, determine the roles of the dialogue model according to preset conditions, obtain user input, perform text processing on the user input, and obtain target text;

[0144] The text matrix generation module 102 is used to construct a pre-trained dialogue model, and use the pre-trained dialogue model to position-code the training texts corresponding to the different roles to obtain a text matrix;

[0145] The model training module 103 is used to perform matrix calculation and prediction calculation on the text matrix to obtain a predicted dialogue, calculate a relevance result based on the predicted dialogue and the training text, and determine whether the relevance result is greater than a preset threshold; if the relevance result is less than or equal to the threshold, update the text matrix, and return to the step of performing matrix calculation and prediction calculation on the text matrix; if the relevance result is greater than the threshold, stop training and obtain a dialogue model;

[0146] The model prediction module 104 is used to input the target text into the dialogue model to obtain a model output result, and to perform repetitive screening and sampling on the model output result to obtain a target output result;

[0147] The reply dialogue generation module 105 is used to splice the target output results to obtain a reply dialogue.

[0148] In detail, each module described in the role dialogue simulation device 100 in the embodiment of the present invention is used in the same manner as described above. Figures 1 to 3 The same technical means are used as the role dialogue simulation method described in, and can produce the same technical effects, so I will not go into details here.

[0149] like Figure 5 FIG. 1 is a schematic diagram of the structure of an electronic device for implementing a method for simulating role dialogue provided by an embodiment of the present invention.

[0150] The electronic device 1 may include a processor 10, a memory 11, a communication bus 12, and a communication interface 13, and may also include a computer program stored in the memory 11 and executable on the processor 10, such as a character dialogue simulation program.

[0151] In some embodiments, the processor 10 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips. The processor 10 is the control core (ControlUnit) of the electronic device, and uses various interfaces and lines to connect various components of the entire electronic device, and executes or executes programs or modules stored in the memory 11 (for example, executing a role dialogue simulation program, etc.), and calls data stored in the memory 11 to execute various functions of the electronic device and process data.

[0152] The memory 11 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a mobile hard disk, a multimedia card, a card-type memory (for example, an SD or DX memory, etc.), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the memory 11 may be an internal storage unit of an electronic device, such as a mobile hard disk of the electronic device. In other embodiments, the memory 11 may also be an external storage device of an electronic device, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device. Further, the memory 11 may also include both an internal storage unit of the electronic device and an external storage device. The memory 11 may not only be used to store application software and various types of data installed in the electronic device, such as the code of a character dialogue simulation program, etc., but may also be used to temporarily store data that has been output or is to be output.

[0153] The communication bus 12 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is configured to realize connection and communication between the memory 11 and at least one processor 10, etc.

[0154] The communication interface 13 is used for communication between the above-mentioned electronic device and other devices, including a network interface and a user interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device and other electronic devices. The user interface may be a display (Display), an input unit (such as a keyboard (Keyboard)), and optionally, the user interface may also be a standard wired interface, a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode, organic light-emitting diode) touch device, etc. Among them, the display may 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 visual user interface.

[0155] Figure 5 Only an electronic device with components is shown, and those skilled in the art will understand that Figure 5The structure shown does not constitute a limitation on the electronic device 1, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.

[0156] For example, although not shown, the electronic device may also include a power source (such as a battery) for supplying power to each component. Preferably, the power source may be logically connected to the at least one processor 10 through a power management device, so that the power management device can realize functions such as charging management, discharging management, and power consumption management. The power source may also include one or more DC or AC power sources, recharging devices, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components. The electronic device may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.

[0157] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.

[0158] The role dialogue simulation program stored in the memory 11 of the electronic device 1 is a combination of multiple instructions. When running in the processor 10, it can achieve:

[0159] Acquire a dialogue corpus, perform role classification and text cleaning on the dialogue corpus, and obtain training texts corresponding to different roles;

[0160] Constructing a pre-trained dialogue model, and using the pre-trained dialogue model to positionally encode the training texts corresponding to the different roles to obtain a text matrix;

[0161] Performing matrix calculation and prediction calculation on the text matrix to obtain a predicted dialogue, calculating a relevance result according to the predicted dialogue and the training text, and determining whether the relevance result is greater than a preset threshold;

[0162] If the correlation result is less than or equal to the threshold, the text matrix is ​​updated, and the process returns to the step of performing matrix calculation and prediction calculation on the text matrix;

[0163] If the relevance result is greater than the threshold, the training is stopped to obtain a dialogue model;

[0164] Determine the role of the dialogue model according to preset conditions, obtain user input, perform text processing on the user input, and obtain a target text;

[0165] Inputting the target text into the dialogue model to obtain a model output result, performing repetitive screening and sampling on the model output result to obtain a target output result, and judging whether sentence generation is completed according to the target output result;

[0166] If the sentence generation is not finished, return to the step of inputting the target text into the dialogue model.

[0167] If the sentence generation is completed, the target output results are concatenated to obtain a reply dialogue.

[0168] Specifically, the specific implementation method of the processor 10 for the above instructions can refer to the description of the relevant steps in the corresponding embodiment of the accompanying drawings, which will not be repeated here.

[0169] Furthermore, if the module / unit integrated in the electronic device 1 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. The computer-readable 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 USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).

[0170] The present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor of an electronic device, the computer program can implement:

[0171] Acquire a dialogue corpus, perform role classification and text cleaning on the dialogue corpus, and obtain training texts corresponding to different roles;

[0172] Constructing a pre-trained dialogue model, and using the pre-trained dialogue model to positionally encode the training texts corresponding to the different roles to obtain a text matrix;

[0173] Performing matrix calculation and prediction calculation on the text matrix to obtain a predicted dialogue, calculating a relevance result according to the predicted dialogue and the training text, and determining whether the relevance result is greater than a preset threshold;

[0174] If the correlation result is less than or equal to the threshold, the text matrix is ​​updated, and the process returns to the step of performing matrix calculation and prediction calculation on the text matrix;

[0175] If the relevance result is greater than the threshold, the training is stopped to obtain a dialogue model;

[0176] Determine the role of the dialogue model according to preset conditions, obtain user input, perform text processing on the user input, and obtain a target text;

[0177] Inputting the target text into the dialogue model to obtain a model output result, performing repetitive screening and sampling on the model output result to obtain a target output result, and judging whether sentence generation is completed according to the target output result;

[0178] If the sentence generation is not finished, return to the step of inputting the target text into the dialogue model.

[0179] If the sentence generation is completed, the target output results are concatenated to obtain a reply dialogue.

[0180] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.

[0181] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0182] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.

[0183] It is obvious to those skilled in the art that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.

[0184] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present invention is limited by the appended claims rather than the above description, so it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any attached figure mark in the claims should not be regarded as limiting the claims involved.

[0185] The blockchain referred to in this invention is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.

[0186] In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the system claim can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.

[0187] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.

Claims

1. A role dialogue simulation method, characterized in that: The method comprises: Acquire a dialogue corpus, perform role classification and text cleaning on the dialogue corpus, and obtain training texts corresponding to different roles; Constructing a pre-trained dialogue model, and using the pre-trained dialogue model to positionally encode the training texts corresponding to the different roles to obtain a text matrix; Performing matrix calculation and prediction calculation on the text matrix to obtain a predicted dialogue, calculating a relevance result according to the predicted dialogue and the training text, and determining whether the relevance result is greater than a preset threshold; If the correlation result is less than or equal to the threshold, the text matrix is ​​updated, and the process returns to the step of performing matrix calculation and prediction calculation on the text matrix; If the relevance result is greater than the threshold, the training is stopped to obtain a dialogue model; Determine the role of the dialogue model according to preset conditions, obtain user input, perform text processing on the user input, and obtain a target text; Inputting the target text into the dialogue model to obtain a model output result, performing repetitive screening and sampling on the model output result to obtain a target output result, and judging whether sentence generation is completed according to the target output result; If the sentence generation is not finished, returning to the step of inputting the target text into the dialogue model; If the sentence generation is completed, the target output results are concatenated to obtain a reply dialogue.

2. The character dialogue simulation method according to claim 1, characterized in that: The step of performing role classification and text cleaning on the dialogue data to obtain training texts corresponding to different roles includes: Inputting the dialogue data into a preset classification model to obtain a role prediction result corresponding to the dialogue data; Classifying the dialogue corpus according to the role prediction results to obtain corpus corresponding to each role; Eliminate the preset characters in the corpus corresponding to each role to obtain a first text corresponding to each role; Performing semantic recognition on the first text, calculating the distance between the semantic recognition result and a preset text vector, deleting the text corresponding to the semantic recognition result whose distance value is less than a preset threshold, and obtaining a second text corresponding to each character; The second texts corresponding to each character are concatenated to obtain the training texts corresponding to each character.

3. The character dialogue simulation method according to claim 2, characterized in that: The step of respectively concatenating the second texts corresponding to each character to obtain the training text corresponding to each character includes: Selecting a role from multiple roles as a target role, and using a second text corresponding to the target role as a target text; The average sentence length is calculated based on the target text, and the length of the target text is set according to the average sentence length. The target text with the set length is concatenated from beginning to end to obtain a training text corresponding to the target role.

4. The character dialogue simulation method according to claim 1, characterized in that: The constructing of the pre-trained dialogue model includes: The model is divided into four parts: the first part is the vector generation layer, the second part is the first vector processing layer, the third part is the second vector processing layer, and the fourth part is the prediction layer. Adding a position encoding structure and an Embedding structure in the vector generation layer; Adding a LayerNorm structure, a Masked Multi self-Attention structure, and a residual connection structure to the first vector processing layer; Adding a LayerNorm structure, a Feed Forward structure, and a residual connection structure in the second vector processing layer; Add the LayerNorm structure and prediction function in the prediction layer.

5. The character dialogue simulation method according to claim 4, characterized in that: The performing matrix calculation and prediction calculation on the text matrix to obtain a prediction dialogue includes: Using the first vector processing layer to normalize, perform attention calculation and residual calculation on the text matrix to obtain a first vector matrix; Using the text matrix of the second vector processing layer to perform normalization, feedforward neural adjustment, and residual calculation to obtain a second vector matrix; Normalizing the second vector matrix using the prediction layer, and inputting the normalized result into a prediction function to obtain a prediction result, wherein the prediction result includes a predicted word and an end character; Determine whether the prediction result is a predicted character or an end character; If the prediction result is predicted text, return to the step of using the first vector processing layer to normalize, calculate attention, and calculate residual on the text matrix to obtain a first vector matrix; If the predicted result is an end character, all the predicted results are concatenated to obtain a predicted dialogue.

6. The character dialogue simulation method according to claim 1, characterized in that: The calculating the relevance result according to the predicted dialogue and the training text includes: Obtaining training texts of other characters other than the character corresponding to the predicted dialogue, and using the training texts of the other characters as comparison texts; Generate a comparison matrix according to the comparison text, and perform linearization processing on the comparison matrix to obtain a first linear vector; The first linear vector is feature compressed to obtain a second linear vector, a correlation of a word vector corresponding to the predicted dialogue is extracted from the second linear vector, and the correlation result is input into a preset probability output function to obtain a correlation result.

7. The role dialogue simulation method according to any one of claims 1 to 6, characterized in that: The repetitive screening and sampling of the model output results to obtain the target output results includes: Obtain all output results of the dialogue model after the last terminator; Performing repeatability test on the model output result and all the output results; If a repeated output result appears, the repeated output result is removed from the dialogue model according to a preset repetitiveness penalty, and the model output result is regenerated using the dialogue model, and the step of performing repetitiveness detection on the model output result and all the output results is returned; If no repeated output results appear, random sampling is performed among the model output results, and the sampling results are used as the target output results.

8. A role dialogue simulation device, characterized in that: The device comprises: A text generation module is used to obtain dialogue data, classify the dialogue data into roles, clean the text, obtain training texts corresponding to different roles, determine the roles of the dialogue model according to preset conditions, obtain user input, perform text processing on the user input, and obtain target text; A text matrix generation module is used to construct a pre-trained dialogue model, and use the pre-trained dialogue model to position encode the training texts corresponding to the different roles to obtain a text matrix; A model training module is used to perform matrix calculation and prediction calculation on the text matrix to obtain a predicted dialogue, calculate a relevance result based on the predicted dialogue and the training text, and determine whether the relevance result is greater than a preset threshold; if the relevance result is less than or equal to the threshold, update the text matrix, and return to the step of performing matrix calculation and prediction calculation on the text matrix; if the relevance result is greater than the threshold, stop training and obtain a dialogue model; A model prediction module, used for inputting the target text into the dialogue model to obtain a model output result, and performing repetitive screening and sampling on the model output result to obtain a target output result; The reply dialogue generation module is used to splice the target output results to obtain a reply dialogue.

9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; 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 so that the at least one processor can execute the role dialogue simulation method as described in any one of claims 1 to 7.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the role dialogue simulation method as described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Text dialogue method and device, electronic equipment and storage medium

    CN112685536A

  • Dialogue reply method and device, dialogue model training method and device, and storage medium

    CN113378583A

  • Text processing method and device, storage medium and computer equipment

    CN114048731A

  • Labeling method for role, labeling device for role, electronic apparatus and storage medium

    JP2021170394A