Dialogue model training method, generation method, training device, equipment and medium
Through the semantic feature extraction of dialogue information and the classification of candidate answers, the empirical calibration error and target loss function values are calculated, and the model parameters are adjusted, which solves the problem of large size and low accuracy of the model in retrieval dialogue technology, and small size is achieved. High-precision dialogue model training improves the accuracy and calibration effect of dialogue model.
Patent Information
- Application Number
- CN202210820808.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-13
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2042-07-13
AI Technical Summary
The existing retrieval dialogue technology model is large in size and has a long calculation time, resulting in poor calibration results and low accuracy, and it is impossible to effectively handle the high accuracy and good calibration requirements in multiple rounds of dialogue.
By obtaining dialogue information and multiple candidate answers, semantic feature extraction and classification, empirical calibration error and target loss function values are calculated, model parameters are adjusted for iterative training, and a small-volume and high-precision search dialogue model is obtained.
While maintaining the small size and high accuracy of the dialogue model, it greatly improves the model calibration effect and improves the accuracy of the dialogue model.
Smart Images

Figure CN115080702B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to a dialogue model training method, generation method, training device, equipment and medium. Background Art
[0002] Retrieval-based dialogue technology is an artificial intelligence interactive technology that aims to model the relationship between contextual semantics and candidate answers, and find the best candidate answers through various matching algorithms. It can quickly mine implicit information in texts, help with content recommendations, public opinion monitoring, and assist in decision-making. However, the models used in current retrieval-based dialogue technology are large in size, take a long time to compute, and have the problem of overfitting, resulting in poor calibration and low accuracy. Summary of the invention
[0003] The purpose of this application is to solve one of the technical problems existing in the related art to at least a certain extent.
[0004] To this end, one purpose of an embodiment of the present application is to provide a dialogue model training method, generation method, training device, equipment and medium, which can greatly improve the model calibration effect and improve the accuracy of the dialogue model while maintaining the small size and high precision of the dialogue model.
[0005] To achieve the above objectives, a first aspect of an embodiment of the present application provides a dialogue model training method, comprising:
[0006] Acquire dialogue information and a plurality of candidate answers, and input the dialogue information and the plurality of candidate answers into a search-based dialogue model, wherein the dialogue information is a dialogue consisting of a plurality of sentences;
[0007] Extracting features from the conversation information to obtain semantic features;
[0008] For each candidate answer, classify the candidate answer according to the semantic feature to obtain first probability information, wherein the first probability information includes a probability value that the candidate answer is a correct answer to the sentence, and a probability value that the candidate answer is an incorrect answer to the sentence;
[0009] Calculating an empirical calibration error of the retrieval-based dialogue model according to the first probability information, and calculating a target loss function value according to the empirical calibration error;
[0010] The parameters of the retrieval-based dialogue model are adjusted according to the target loss value, and the retrieval-based dialogue model is iteratively trained until the target loss function value is minimized, thereby obtaining a trained retrieval-based dialogue model.
[0011] In some embodiments, classifying the candidate answers according to the semantic features to obtain first probability information includes:
[0012] Extracting evidence according to the semantic features to obtain evidence information that the candidate answer is classified into each category, the category including a correct answer and an incorrect answer; the evidence information includes evidence that the candidate answer is classified as the correct answer, and evidence that the candidate answer is classified as the incorrect answer;
[0013] The first probability information is obtained according to the evidence information.
[0014] In some embodiments, obtaining the first probability information according to the evidence information includes:
[0015] Calculating the Dirichlet intensity and the probability parameter of each category according to the evidence information;
[0016] The first probability information is obtained according to the probability parameter and the Dirichlet intensity.
[0017] In some embodiments, the calculating the Dirichlet intensity and the probability parameter of each category according to the evidence information includes:
[0018] Mapping the evidence information of each category through an activation function to obtain an evidence mapping value of each category, wherein the evidence mapping value is a non-negative number;
[0019] Calculating a probability parameter for each category according to the sum of the evidence mapping value and a preset value;
[0020] The Dirichlet intensity is calculated based on the sum of the probability parameters for all classes.
[0021] In some embodiments, calculating the empirical calibration error of the retrieval-based dialogue model according to the first probability information, and calculating the target loss function value according to the empirical calibration error, includes:
[0022] Calculate the empirical calibration error of the retrieval-based dialogue model according to the first probability information, and calculate the empirical calibration error loss function value according to the empirical calibration error;
[0023] Calculating a cross entropy loss function value of the search-based dialogue model according to the first probability information;
[0024] The sum of the empirical calibration error loss function value and the cross entropy loss function value is taken as the target loss function value.
[0025] In some embodiments, the empirical calibration error loss function value is expressed by the following formula:
[0026] i∈[1,n] and i is an integer, j∈[1,M] and j is an integer; where L ECE represents the empirical calibration error loss function value, T represents the temperature parameter, n represents the number of sentences, M represents the number of intervals mapped by the first probability information, and A j represents the accuracy in the jth interval, p ik represents the probability value of the candidate answer being classified as the kth category for the i-th sentence, ρ j is the midpoint value of the jth interval, and T represents the temperature parameter.
[0027] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application provides a dialogue model training device, comprising:
[0028] An input module, used to obtain dialogue information and multiple candidate answers, and input the dialogue information and the multiple candidate answers into the search-based dialogue model, wherein the dialogue information is a dialogue composed of multiple sentences;
[0029] A semantic feature extraction module, used to extract features from the dialogue information to obtain semantic features;
[0030] A classification module, configured to classify each candidate answer according to the semantic feature to obtain first probability information, wherein the first probability information includes a probability value of the candidate answer being a correct answer to the sentence and a probability value of the candidate answer being an incorrect answer to the sentence;
[0031] A loss function calculation module, used to calculate the empirical calibration error of the retrieval-based dialogue model according to the first probability information, and calculate the target loss function value according to the empirical calibration error;
[0032] A parameter adjustment module, used for adjusting the parameters of the retrieval dialogue model according to the target loss function value;
[0033] The iterative training module is used to iteratively train the retrieval-based dialogue model until the target loss function value is minimized, thereby obtaining a trained retrieval-based dialogue model.
[0034] To achieve the above objective, a third aspect of the embodiments of the present application further provides a method for generating a dialogue, including:
[0035] Acquire current dialogue information, and input the current dialogue information into a search-based dialogue model, wherein the search-based dialogue model is trained according to the dialogue model training method described above;
[0036] The search-based dialogue model obtains a second probability value according to the current dialogue information, where the second probability value is a probability value of all preset candidate answers being correct answers to the current dialogue information;
[0037] The search-based dialogue model sorts all the candidate answers according to the second probability value, and outputs the candidate answer with the largest second probability value as the target answer.
[0038] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application also provides an electronic device, which includes a memory, a processor, a program stored on the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory. When the program is executed by the processor, the above-mentioned dialogue model training method or dialogue generation method is realized.
[0039] To achieve the above-mentioned purpose, the fifth aspect of an embodiment of the present application also provides a computer-readable storage medium, which stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the above-mentioned dialogue model training method or dialogue generation method.
[0040] The dialogue model training method, generation method, training device, equipment and medium disclosed in the embodiments of the present application obtain dialogue information and multiple candidate answers, and input the dialogue information and the multiple candidate answers into a retrieval-based dialogue model, wherein the dialogue information is a dialogue composed of multiple sentences; feature extraction is performed on the dialogue information to obtain semantic features; for each candidate answer, the candidate answer is classified according to the semantic features to obtain first probability information, wherein the first probability information includes a probability value of the candidate answer being a correct answer to the sentence, and a probability value of the candidate answer being an incorrect answer to the sentence; the empirical calibration error of the retrieval-based dialogue model is calculated according to the first probability information, and the target loss function value is calculated according to the empirical calibration error; the parameters of the retrieval-based dialogue model are adjusted according to the target loss value, and the retrieval-based dialogue model is iteratively trained until the target loss function value is minimized, thereby obtaining a trained retrieval-based dialogue model; while maintaining the small size and high precision of the dialogue model, the model calibration effect can be greatly improved, and the accuracy of the dialogue model can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following introduction is made to the drawings of the embodiments of the present application or the related technical solutions in the prior art. It should be understood that the drawings introduced below are only for the convenience of clearly describing some embodiments of the technical solutions of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0042] Figure 1 It is a schematic diagram of the principle of the retrieval dialogue model;
[0043] Figure 2is a flow chart of the dialogue model training method provided in an embodiment of the present application;
[0044] Figure 3 is a flowchart of step S300 provided in an embodiment of the present application;
[0045] Figure 4 is a flowchart of step S320 provided in an embodiment of the present application;
[0046] Figure 5 is a flowchart of step S321 provided in an embodiment of the present application;
[0047] Figure 6 is a flowchart of step S400 provided in an embodiment of the present application;
[0048] Figure 7 is a flow chart of a method for generating a dialogue provided by an embodiment of the present application;
[0049] Figure 8 is a structural diagram of a dialogue model training device provided in an embodiment of the present application;
[0050] Fig. 9 It is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0052] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0053] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0054] First, some nouns involved in this application are analyzed:
[0055] Artificial Intelligence (AI): It is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science. It attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making. Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level technology and software-level technology. The basic technologies of artificial intelligence generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, and mechatronics. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0056] Natural language processing (NLP) is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can achieve effective communication between people and computers using natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics. The natural language involved in this field is the language used by people in daily life, so it is also closely related to the study of linguistics. Natural language processing technology usually includes text processing, semantic understanding, machine translation, robot question answering, knowledge graph and other technologies.
[0057] Machine Learning (ML) is a multi-disciplinary subject involving probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning (deep learning) usually includes artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and self-learning.
[0058] Conversational AI (CoAI) refers to intelligent behaviors that are manifested through dialogue and interaction. Usually, intelligent systems interact with users or the environment and learn and model in the interaction. It mainly includes but is not limited to the following research areas: general question-answering systems, including automatic question-answering, reading comprehension, etc.; task- or goal-oriented dialogue systems; open-domain chat systems. Among them, general question-answering systems aim to find accurate information from structured (such as knowledge bases, tables) and unstructured (such as documents) to answer user questions; task- or goal-oriented dialogue systems need to achieve a specific task or goal through interaction, such as various intelligent assistants, ticket booking, and meal ordering systems; open-domain chat systems focus on chatting with users, emotional communication, and companionship, which are important foundations and prerequisites for social robots to enter thousands of households. These interactive systems not only use natural language as a carrier, but also comprehensively apply multimedia information such as images and voices to enable machines to understand their own environment and show intelligent behaviors that are in line with the situation.
[0059] In recent years, with the rapid development of artificial intelligence technology, various types of machine learning models have achieved relatively good application results in the fields of image classification, face recognition, and autonomous driving. In the field of human-computer interaction, artificial intelligence technology can be used to build a retrieval dialogue model to achieve relevant information collection and task processing based on human-computer dialogue. This technology is called interactive artificial intelligence (Conversational AI, CoAI).
[0060] In the related art, when human-computer interaction is realized based on interactive artificial intelligence, the constructed retrieval-based dialogue model performs well in processing single-round dialogues. For example, a general question-answering system that searches for accurate information from structured (such as knowledge bases, tables) and unstructured (such as documents) information to answer user questions can easily identify the content required by users from massive amounts of information. However, in multi-round dialogues, the dialogue model is required to have high prediction accuracy and good calibration effect. In the dialogue model, model calibration refers to the accuracy of the score provided by the model reflecting its prediction uncertainty. Uncertainty calibration is performed on the dialogue model to avoid the dialogue model forcibly giving an unreasonable answer to questions that may be answered incorrectly. An unreasonable answer is a wrong decision, and a wrong decision often consumes more resources than not making a decision or returning it to an expert for decision-making. However, the method of using uncertainty to calibrate the model has the problem of simple operation but long reasoning time, or the problem of large model size, complex operation, and high memory demand.
[0061] In order to solve the problems in the related art, an object of an embodiment of the present application is to provide a dialogue model training method, a generation method, a training device, an equipment and a medium, which obtains dialogue information and multiple candidate answers, and inputs the dialogue information and the multiple candidate answers into a retrieval dialogue model, wherein the dialogue information is a dialogue composed of multiple sentences; performs feature extraction on the dialogue information to obtain semantic features; for each candidate answer, classifies the candidate answer according to the semantic features to obtain first probability information, and the first probability information includes a probability value of the candidate answer being a correct answer to the sentence, and a probability value of the candidate answer being an incorrect answer to the sentence; calculates an empirical calibration error of the retrieval dialogue model according to the first probability information, and calculates a target loss function value according to the empirical calibration error; adjusts the parameters of the retrieval dialogue model according to the target loss value, iteratively trains the retrieval dialogue model until the target loss function value is minimized, and obtains a trained retrieval dialogue model; while maintaining the small size and high precision of the dialogue model, it can greatly improve the model calibration effect and improve the accuracy of the dialogue model.
[0062] The implementation environment of a dialogue model training method provided in an embodiment of the present application is as follows. The hardware and software main body of the implementation environment mainly includes an operation terminal and a server, and the operation terminal is connected to the server in communication. Among them, the training method of the retrieval dialogue model can be configured to be executed separately on the operation terminal, or it can be configured to be executed separately on the server, or it can be executed based on the interaction between the operation terminal and the server. It can be appropriately selected according to the actual application situation, and this embodiment does not make specific restrictions on this. In addition, the operation terminal and the server can be nodes in the blockchain, and this embodiment does not make specific restrictions on this.
[0063] Specifically, the operation terminal in the present application may include but is not limited to any one or more of a smart watch, a smart phone, a computer, a personal digital assistant (PDA), an intelligent voice interaction device, a smart home appliance or a vehicle-mounted terminal. The server may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The operation terminal 101 and the server 102 can establish a communication connection through a wireless network or a wired network, which uses standard communication technology and / or protocols. The network can be set to the Internet or any other network, such as but not limited to a local area network (LAN), a metropolitan area network (MAN), a wide area network (WAN), a mobile, wired or wireless network, a private network or a virtual private network.
[0064] In addition, the present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0065] Reference Figure 2 , Figure 2 The embodiment of the present application provides a method for training a dialogue model, which includes but is not limited to the following steps:
[0066] Step S100, obtaining dialogue information and a plurality of candidate answers, and inputting the dialogue information and the plurality of candidate answers into a search-based dialogue model, wherein the dialogue information is a dialogue composed of a plurality of sentences;
[0067] Step S200, extracting features from the dialogue information to obtain semantic features;
[0068] Step S300, for each candidate answer, classify the candidate answer according to the semantic feature to obtain first probability information, the first probability information including the probability value of the candidate answer being a correct answer to the sentence, and the probability value of the candidate answer being an incorrect answer to the sentence;
[0069] Step S400, calculating an empirical calibration error of the retrieval-based dialogue model according to the first probability information, and calculating a target loss function value according to the empirical calibration error;
[0070] Step S500, adjusting the parameters of the retrieval-based dialogue model according to the target loss value, iteratively training the retrieval-based dialogue model until the target loss function value is minimized, and obtaining a trained retrieval-based dialogue model.
[0071] For step S100, when training the search-based dialogue model, training data is obtained. The training data includes dialogue information and multiple candidate answers. The training data is input into the search-based dialogue model to train the search-based dialogue model.
[0072] For example, U i ={u1,u2,…,u t} is a conversation message consisting of t sentences, R i ={t1,r2,…,r n} is n candidate answers, then concatenate the dialogue information and the candidate answers, and separate them by [SEP] between the dialogue information and the candidate answers, and add the start mark character [CLS] to the entire sentence, then the input form is x i ={[CLS],u1,u2,...,u t ,[SEP],r i}. In addition, there is a category label y i ∈{1,2,…,K}, in this embodiment, specifically, y i ∈{1,2}, there are two category labels, the correct answer label corresponding to 1 and the wrong answer label corresponding to 2. Then the input form of the model is
[0073] It is understandable that there is no limitation on the source channel for obtaining the dialogue information and multiple candidate answers. For example, in some embodiments, the first input information can be downloaded from a related resource server, transmitted through a hardware port, or obtained from the environment through a voice collection and recognition device.
[0074] Among them, refer to Figure 1 , Figure 1 This is a schematic diagram of the principle of the retrieval dialogue model. The principle of the retrieval dialogue model is as follows: the retrieval dialogue model is a comprehensive entity involving multiple technologies such as understanding, generation, and interaction. Understanding means that you need to understand the content output by the other party, only in this way can you give a correct response. Generation means giving appropriate results based on the understood content. Interaction means that in multiple rounds of dialogue, you need to record and track the content involved in the entire dialogue process.
[0075] The search-based dialogue model includes a central control sub-model and a plurality of different sub-interaction models. For example, the search-based dialogue model includes three sub-interaction models, namely, sub-interaction model A, sub-interaction model B and sub-interaction model C. In the actual search-based dialogue model, the number of sub-interaction models can be any integer greater than or equal to 2. In the search-based dialogue model, each sub-interaction model is used to interactively predict the input information to obtain the interaction information corresponding to each sub-interaction model. Generally speaking, the interaction process is mainly completed in the form of sentence dialogue, that is, the input information may include multiple sentences, and for each input sentence, each sub-interaction model can give a corresponding interaction sentence. The input information includes sentence S1, sentence S2 and sentence S3 in order of interaction, and the sub-interaction model A, the sub-interaction model B and the sub-interaction model C respectively give corresponding interaction contents for these input sentences, wherein the interaction content of the sub-interaction model A for sentence S1 is sentence A1, the interaction content for sentence S2 is sentence A2, and the interaction content for sentence S3 is sentence A3. The sub-interaction model B is similar to the sub-interaction model C and will not be repeated here. The central control sub-model is used to select appropriate sentences from the interactive contents given by each sub-interaction model A, sub-interaction model B and sub-interaction model C according to the sentences in the input information as the interactive output of the search-based dialogue model for the input information. For example, for sentence S1 in the input information, the central control sub-model selects sentence B1 output by sub-interaction model B, for sentence S2 in the input information, the central control sub-model selects sentence C2 output by sub-interaction model C, and for sentence S3 in the input information, the central control sub-model selects sentence A3 output by sub-interaction model A as the interactive content, thereby forming a multi-round continuous dialogue of "sentence S1-sentence B1-sentence S2-sentence C2-sentence S3-sentence A3".
[0076] The above is a brief description of the composition structure and application principle of the retrieval-based dialogue model in this application. In this retrieval-based dialogue model, the central control sub-model and each sub-interaction model can be built based on the machine learning algorithm in the field of artificial intelligence. This application does not limit the machine learning model structure selected for the central control sub-model and each sub-interaction model.
[0077] It should be noted that in order to simulate the normal interaction process well, the central control sub-model in this application can determine the output statement based on the previous interaction content when selecting the output statement of the sub-interaction model corresponding to the input statement. For the input statement S2, the central control sub-model can simultaneously consider the dialogue "statement S1-statement B1" before statement S2, and then combine the content of statement S2 to determine the output statement. Of course, in order to reduce the pressure of data processing, the central control sub-model can be set to determine the output statement based on the current input statement and the interaction content of several previous rounds. The specific rounds can be flexibly set as needed.
[0078] It should be noted that the various components in the retrieval-based dialogue model in the embodiment of the present application can be integrated in one place or in a distributed layout. For example, the sub-interaction model in the retrieval-based dialogue model can be a node in the blockchain, and this embodiment does not specifically limit this.
[0079] For step S200, feature extraction is performed on the dialogue information to obtain semantic features, which can be achieved through a semantic feature extraction model.
[0080] In some embodiments, the conversation information is feature extracted using a BERT (Bidirectional Encoder Representations from Transformer) model to obtain semantic features.
[0081] The BERT model is a language representation model based on the Transformer bidirectional encoder. The bidirectional Transformers are pre-trained using the MLM (masked language model) to generate deep bidirectional language representations. The goal of the BERT model is to use large-scale unlabeled corpus training to obtain semantic features of texts that contain rich semantic information.
[0082] The main model structure of the BERT model is a stack of Transformers. Transformers are the core modules of the BERT model, and the attention mechanism is the most critical part of Transformers.
[0083] The main function of the attention mechanism is to allow the neural network to focus on a part of the input, that is, to distinguish the impact of different parts of the input on the output. In order to use the context word information to enhance the semantic representation of the target word in a differentiated way, the BERT model uses the attention mechanism.
[0084] In the BERT model, the target word is used as the query, and each word in its context is used as the key. The similarity between the query and each key is used as the weight, and the value of each word in the context is integrated into the original value of the target word. The attention mechanism takes the semantic vector representation of the target word and each word in the context as input. First, the query vector representation of the target word, the key vector representation of each word in the context, and the original value representation of the target word and each word in the context are obtained through multiple linear transformations to enhance the expression ability of the model. Then, the similarity between the query vector and each key vector is calculated as the weight, and the value vector of the target word and the value vector of each word in the context are weighted and fused, that is, the enhanced semantic vector representation of the target word. In addition, different Self-Attention modules are used to obtain the enhanced semantic vector of each word in the text in different semantic spaces, and multiple enhanced semantic vectors of each word are linearly combined to obtain a final enhanced semantic vector with the same length as the original word vector. The input of the module is added to the enhanced semantic vector to realize residual connection, and it is used as the final output of the attention module. The final output is exactly the same as the input in form. That is, if the input is a one-dimensional vector, the output is also a one-dimensional vector. Words with similar semantics will be closer in the feature vector space, so that the text vector converted from the word vector can also contain more accurate semantic information. Therefore, the main input of the BERT model is the original word vector of each word in the dialogue information, which can be randomly initialized or pre-trained using algorithms such as Word2Vector as the initial value; the output is the vector representation of each word in the text after integrating the semantic information of the entire text.
[0085] Before inputting into the BERT model, the dialogue information can be first segmented by the tokenizer. The input part of the BERT model is a linear sequence. Two sentences are separated by a separator symbol, and two identifiers are added at the front and the back to indicate the beginning and the end. Each word has three position information. This is because the word order is a very important feature in natural language processing, and the position information needs to be encoded here. The three position information are common subword unit position information, word position information, and sentence position information. Common subword position information is the vector representation of the word itself. Dividing the word into a limited set of common subword units can achieve a compromise between the effectiveness of the word and the flexibility of the character. Word position information encodes the position information of the word into a feature vector. Sentence position information is used to distinguish the vector representations of two sentences. The input of the BERT model is the sum of these three different position information.
[0086] The final output of the BERT model consists of four parts: the hidden state of the last layer output of the model, the hidden state of the last layer of the first common subword unit of the sequence, the hidden state of each layer of the model, and the output of the attention module.
[0087] That is, the conversation information is input into the BERT model, and the BERT model outputs semantic features with the same dimension as the conversation information.
[0088] Reference Figure 3 , Figure 3 is a flow chart of step S300. For step S300, the candidate answers are processed for K classification problem through an evidential neural network (ENN).
[0089] Classifying the candidate answers according to the semantic features to obtain first probability information includes but is not limited to the following steps:
[0090] Step S310, extracting evidence based on semantic features to obtain evidence information that the candidate answer is classified into each category, where the category includes a correct answer and an incorrect answer; the evidence information includes evidence that the candidate answer is classified as a correct answer, and evidence that the candidate answer is classified as an incorrect answer;
[0091] Step S320: obtaining first probability information according to the evidence information.
[0092] Reference Figure 4 , Figure 4 is a flow chart of step S320. For step S320, obtaining first probability information according to the evidence information includes but is not limited to the following steps:
[0093] Step S321, calculating the Dirichlet strength and the probability parameter of each category according to the evidence information;
[0094] Step S322: Obtain first probability information according to the probability parameter and the Dirichlet intensity.
[0095] Reference Figure 5 , Figure 5 is a flow chart of step S321. For step S321, the Dirichlet strength and the probability parameter of each category are calculated according to the evidence information, including:
[0096] Step S3211, mapping the evidence information of each category through an activation function to obtain an evidence mapping value of each category, where the evidence mapping value is a non-negative number;
[0097] Step S3212, calculating the probability parameter of each category according to the sum of the evidence mapping value and the preset value;
[0098] Step S3213, calculating the Dirichlet intensity according to the sum of probability parameters of all categories.
[0099] For multi-classification problems, there are K labels. In this application, K is 2, that is, there are two labels, the correct answer label and the wrong answer label. For the candidate answers, the predicted output probability P = [p1, p2]. A belief quality is assigned to the probability of each label, and the belief quality is expressed as B = {b1, b2}; at the same time, an overall uncertainty quality u is provided to consider a framework of k mutually exclusive singletons (such as category labels), and the belief quality and uncertainty satisfy . and b k and u are both non-negative.
[0100] Evidence is introduced through the evidence neural network, and evidence is defined as a measure of the amount of support collected from the data to support the classification of samples into a certain category. In step S310, evidence is extracted based on semantic features to obtain evidence information that the candidate answer is classified into each category. The evidence information includes evidence that the candidate answer is classified as a correct answer and evidence that the candidate answer is classified as an incorrect answer. That is, in step S310, the amount of support that supports the classification of the candidate answer as a correct answer and another amount of support that supports the classification of the candidate answer as an incorrect answer are extracted from the semantic features.
[0101] For step S320, the evidence information of each category is mapped by an activation function to obtain the evidence mapping value of each category. Specifically, the activation function adopts a softmax function to normalize the evidence information to the interval [0, 1].
[0102] The evidence mapping value is expressed as E = {e i1 ,e i2},e ik It is represented as the evidence map value derived from the k-th category label for the i-th candidate answer. The distribution of belief quality conforms to α ik =e ik +1 Dirichlet distribution, α ik It can represent the probability parameter of each category, and 1 is the preset value.
[0103] The output of a standard neural network classifier is a probability assignment to the possible classes for each sample. However, the evidence-parameterized Dirichlet distribution represents the density of each such probability assignment; thus, it models second-order probabilities and uncertainties. K The density function of the Dirichlet distribution of ] is expressed as: Where S K is a unit cone of K dimensions; B(α) is the K-dimensional beta function.
[0104] in S i represents the Dirichlet intensity of the i-th candidate answer. The uncertainty quality is inversely proportional to the Dirichlet intensity, so and
[0105] The predicted probability of the kth category is the mean of the corresponding Dirichlet distribution, so the first probability information is expressed as
[0106] Reference Figure 6 , Figure 6 is a flowchart of step S400. For step S400, this step is to calculate the overall target loss function value of the search-based dialogue model. The target loss function value includes the empirical calibration error loss function value and the cross entropy loss function value, and the target loss function value is the sum of the two.
[0107] Then, the empirical calibration error of the retrieval-based dialogue model is calculated according to the first probability information, and the target loss function value is calculated according to the empirical calibration error, including but not limited to the following steps:
[0108] Step S410, calculating an empirical calibration error of the retrieval-type dialogue model according to the first probability information, and calculating an empirical calibration error loss function value according to the empirical calibration error;
[0109] Step S420, calculating a cross entropy loss function value of the search-based dialogue model according to the first probability information;
[0110] Step S430: taking the sum of the empirical calibration error loss function value and the cross entropy loss function value as the target loss function value.
[0111] For step S410, Empirical Calibration Error (ECE) is a commonly used indicator for measuring calibration. It calculates the weighted average of the absolute difference between the average prediction confidence and the average accuracy between samples. The probability value of the sample prediction is usually regarded as the confidence of the sample for the prediction. The Empirical Calibration Error divides the [0,1] interval into M small intervals, and the number of samples in each interval is B. i , the total number of samples is N, then the empirical calibration error can be expressed as
[0112] For a candidate answer sample x i The predicted probability value obtained on the kth category is p ik , and maps it into an M-dimensional vector v = [v1, v2, …, v M ] and make it satisfy the condition Let ρ jrepresents the midpoint value of each interval, and T is the temperature parameter. The predicted probability value p ik Mapped to a vector. In order to ensure that the value is between [0,1], the softmax activation function is used to map it.
[0113] Then the empirical calibration error loss function value is expressed by the following formula: i∈[1,n] and i is an integer, j∈[1,M] and j is an integer; where L ECE represents the empirical calibration error loss function value, T represents the temperature parameter, n represents the number of sentences, M represents the number of intervals mapped by the first probability information, and A j represents the accuracy in the jth interval, p ik represents the probability value of the candidate answer being classified as the kth category for the i-th sentence, ρ j is the midpoint value of the jth interval, and T represents the temperature parameter.
[0114] For step S420, the evidence neural network is deep evidence learning (EDL) based on evidence theory. When modeling uncertainty, there is no need for complex posterior probability estimation and multiple Monte Carlo sampling, so the computational efficiency is extremely high. The basic assumption of EDL is that the classification probability output by the model obeys the Dirichlet distribution prior. By maximizing the probability likelihood of the observed data, the posterior distribution of the output classification probability can be obtained using the deep learning model. According to probability statistics, the likelihood function of the classification probability obeys the multinomial distribution, and in the Bayesian framework, the Dirichlet prior belongs to the conjugate prior of the multinomial distribution, that is, the posterior distribution still obeys the Dirichlet distribution. Therefore, the evidence neural network directly learns the distribution parameters of the Dirichlet posterior distribution, and the classification probability of the class is regarded as sampling from the distribution. In this way, the evidence neural network can directly learn the uncertainty of the classification probability.
[0115] Combining the Dempster-Shafer evidence theory and subjective logic, the classification recognition model based on the Dirichlet hypothesis is essentially a classification system based on evidence. In order to maximize the likelihood of the observed data, the cross entropy loss function value is calculated and minimized during the training process. Minimizing this cross entropy loss function value is equivalent to maximizing the collection of evidence to support the correct classification. Specifically, the cross entropy loss function value is expressed as:
[0116] For step S430, the empirical calibration error loss function value and the cross entropy loss function value are added to obtain the target loss function value, and the target loss function value is expressed as: L = LEDL +L ECE .
[0117] For step S500, the parameters of the search-based dialogue model are adjusted according to the target loss value. The search-based dialogue model is iteratively trained, and the parameters of the search-based dialogue model are continuously adjusted. The search-based dialogue model is trained until the target loss function value of the search-based dialogue model is minimized, at which point the parameters of the search-based dialogue model are optimal, and a trained search-based dialogue model is obtained.
[0118] Reference Figure 7 , Figure 7 To achieve the above purpose, an embodiment of the present application provides a method for generating a dialogue, including but not limited to the following steps:
[0119] Step S610, inputting the current dialogue information into a search-based dialogue model, where the search-based dialogue model is trained according to the above-mentioned dialogue model training method;
[0120] Step S620, the search-based dialogue model obtains a second probability value based on the current dialogue information, where the second probability value is a probability value that all preset candidate answers are correct answers to the current dialogue information;
[0121] Step S630: the search-based dialogue model sorts all candidate answers according to the second probability value, and outputs the candidate answer with the largest second probability value as the target answer.
[0122] In step S610, the user inputs the current dialogue information through an input device, which may be a keyboard, a virtual keyboard, a touch screen, a microphone, etc. Then, the current dialogue information is input into the trained retrieval dialogue model.
[0123] For step S620, a plurality of candidate answers are pre-stored. The candidate answers may be stored in the search-based dialogue model, or the candidate answers may be read from an external memory by the search-based dialogue model.
[0124] Referring to the above process, the search-based dialogue model uses the BERT model to extract semantic features from the current dialogue information to obtain semantic features. Then the search-based dialogue model uses the evidence neural network to classify candidate answers according to the semantic features to obtain multiple second probability values, each of which corresponds to the probability value of each candidate answer being the correct answer for the current dialogue information.
[0125] For step S630, all candidate answers are sorted according to the second probability value, which can be sorted from large to small according to the numerical value of the second probability value, or from small to large according to the numerical value of the second probability value; and the candidate answer with the largest second probability value is selected. The search-based dialogue model outputs the candidate answer corresponding to the largest second probability value as the target answer through the output layer.
[0126] In this embodiment, the dialogue generation method can quickly obtain accurate target answers through a retrieval-based dialogue model and has strong robustness.
[0127] Reference Figure 8 , Figure 8 7 is a structural diagram of a dialogue model training device. To achieve the above purpose, an embodiment of the present application further provides a dialogue model training device. The dialogue model training device includes an input module 710, a semantic feature extraction module 720, a classification module 730, a loss function calculation module 740 and an iterative training module 750.
[0128] Among them, the input module 710 is used to input dialogue information and multiple candidate answers into the retrieval dialogue model, and the dialogue information is a dialogue composed of multiple sentences; the semantic feature extraction module 720 is used to extract features from the dialogue information to obtain semantic features; the classification module is used to classify each candidate answer according to the semantic features to obtain first probability information, and the first probability information includes the probability value of the candidate answer being the correct answer to the sentence, and the probability value of the candidate answer being the wrong answer to the sentence; the loss function calculation module 730 is used to calculate the empirical calibration error of the retrieval dialogue model according to the first probability information, and calculate the target loss function value according to the empirical calibration error; the parameter adjustment module 740 is used to adjust the parameters of the retrieval dialogue model according to the target loss function value; the iterative training module 750 is used to iteratively train the retrieval dialogue model until the target loss function value is minimized, so as to obtain a trained retrieval dialogue model.
[0129] It can be understood that the contents in the embodiment of the training method of the retrieval-type dialogue model are applicable to the embodiment of the training device of the retrieval-type dialogue model. The functions specifically implemented by the embodiment of the training device of the retrieval-type dialogue model are the same as those in the embodiment of the training method of the retrieval-type dialogue model, and the beneficial effects achieved are also the same as those achieved by the embodiment of the training method of the retrieval-type dialogue model.
[0130] Reference Fig. 9 , Fig. 98 is a structural diagram of an electronic device. To achieve the above purpose, an embodiment of the present application further provides an electronic device, the electronic device comprising a memory 820, a processor 810, a program stored in the memory 820 and executable on the processor 810, and a data bus 830 for realizing connection and communication between the processor 810 and the memory 820, and when the program is executed by the processor 810, the above-mentioned dialogue model training method or dialogue generation method is realized.
[0131] The memory 820, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer executable programs, such as the dialogue model training method or dialogue generation method in the above-mentioned embodiment of the present invention. The processor 810 implements the dialogue model training method or dialogue generation method in the above-mentioned embodiment of the present invention by running the non-transitory software programs and programs stored in the memory 820.
[0132] The memory 820 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data required for executing the dialogue model training method in the above-mentioned embodiment of the present invention, or the dialogue generation method, etc. In addition, the memory 820 may include a high-speed random access memory 820, and may also include a non-volatile memory 820, such as at least one disk memory 820, a flash memory device, or other non-volatile solid-state memory 820. In some embodiments, the memory 820 may optionally include a memory 820 remotely arranged relative to the processor 810, and these remote memories 820 may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0133] To achieve the above-mentioned purpose, an embodiment of the present application also provides a computer-readable storage medium, which stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the above-mentioned dialogue model training method or dialogue generation method.
[0134] It will be appreciated by those skilled in the art that all or some of the steps and systems in the disclosed method above may be implemented as software, firmware, hardware and appropriate combinations thereof. Some physical components or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, disk storage or other magnetic storage devices, or any other medium that may be used to store desired information and may be accessed by a computer. In addition, it is well known to those of ordinary skill in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium. In the above description of this specification, the description of reference terms "one embodiment / example", "another embodiment / example" or "certain embodiments / examples" and the like means that the specific features, structures, materials or characteristics described in conjunction with the embodiments or examples are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0135] Although the embodiments of the present application have been shown and described, those skilled in the art will appreciate that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present application, and that the scope of the present application is defined by the claims and their equivalents.
[0136] The above is a specific description of the preferred implementation of the present application, but the present application is not limited to the embodiments. Technical personnel familiar with the field can make various equivalent modifications or substitutions without violating the spirit of the present application. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present application.
[0137] In the description of this specification, the description with reference to the terms "one embodiment", "another embodiment" or "certain embodiments" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiments or examples are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
Claims
1. A dialogue model training method, It is characterized in that include: Acquire dialogue information and a plurality of candidate answers, and input the dialogue information and the plurality of candidate answers into a search-based dialogue model, wherein the dialogue information is a dialogue consisting of a plurality of sentences; Extracting features from the conversation information to obtain semantic features; For each candidate answer, classify the candidate answer according to the semantic feature to obtain first probability information, wherein the first probability information includes a probability value that the candidate answer is a correct answer to the sentence, and a probability value that the candidate answer is an incorrect answer to the sentence; Calculating an empirical calibration error of the retrieval-based dialogue model according to the first probability information, and calculating a target loss function value according to the empirical calibration error; Adjusting the parameters of the retrieval-based dialogue model according to the target loss function value, iteratively training the retrieval-based dialogue model until the target loss function value is minimized, thereby obtaining a trained retrieval-based dialogue model; The empirical calibration error loss function value is expressed by the following formula: i∈[1,n] and i is an integer, j∈[1,M] and j is an integer; where L ECE represents the empirical calibration error loss function value, T represents the temperature parameter, n represents the number of sentences, M represents the number of intervals mapped by the first probability information, and A j represents the accuracy in the jth interval, p ik represents the probability value of the candidate answer being classified as the kth category for the i-th sentence, ρ j is the midpoint value of the jth interval, and T represents the temperature parameter.
2. The dialogue model training method according to claim 1, It is characterized in that The step of classifying the candidate answers according to the semantic features to obtain first probability information includes: Extracting evidence according to the semantic features to obtain evidence information that the candidate answer is classified into each category, the category including a correct answer and an incorrect answer; the evidence information includes evidence that the candidate answer is classified as the correct answer, and evidence that the candidate answer is classified as the incorrect answer; The first probability information is obtained according to the evidence information.
3. The dialogue model training method according to claim 2, It is characterized in that The obtaining the first probability information according to the evidence information includes: Calculating the Dirichlet intensity and the probability parameter of each category according to the evidence information; The first probability information is obtained according to the probability parameter and the Dirichlet intensity.
4. The method for training a dialogue model according to claim 3, It is characterized in that The calculating the Dirichlet intensity and the probability parameter of each category according to the evidence information includes: Mapping the evidence information of each category through an activation function to obtain an evidence mapping value of each category, wherein the evidence mapping value is a non-negative number; Calculating a probability parameter for each category according to the sum of the evidence mapping value and a preset value; The Dirichlet intensity is calculated based on the sum of the probability parameters for all classes.
5. The method for training a dialogue model according to claim 1, It is characterized in that The step of calculating the empirical calibration error of the retrieval-based dialogue model according to the first probability information, and calculating the target loss function value according to the empirical calibration error, includes: Calculate the empirical calibration error of the retrieval-based dialogue model according to the first probability information, and calculate the empirical calibration error loss function value according to the empirical calibration error; Calculating a cross entropy loss function value of the search-based dialogue model according to the first probability information; The sum of the empirical calibration error loss function value and the cross entropy loss function value is taken as the target loss function value.
6. A method for generating a dialogue, It is characterized in that include: Acquire current dialogue information, and input the current dialogue information into a search-based dialogue model, wherein the search-based dialogue model is trained according to the dialogue model training method according to any one of claims 1 to 5; The search-based dialogue model obtains a second probability value according to the current dialogue information, where the second probability value is a probability value of all preset candidate answers being correct answers to the current dialogue information; The search-based dialogue model sorts all the candidate answers according to the second probability value, and outputs the candidate answer with the largest second probability value as the target answer.
7. A dialogue model training device, It is characterized in that include: An input module, used to input dialogue information and multiple candidate answers into the search-based dialogue model, wherein the dialogue information is a dialogue composed of multiple sentences; A semantic feature extraction module, used for extracting features from the dialogue information to obtain semantic features; A classification module, configured to classify each candidate answer according to the semantic feature to obtain first probability information, wherein the first probability information includes a probability value of the candidate answer being a correct answer to the sentence and a probability value of the candidate answer being an incorrect answer to the sentence; A loss function calculation module, used to calculate the empirical calibration error of the retrieval-based dialogue model according to the first probability information, and calculate the target loss function value according to the empirical calibration error; A parameter adjustment module, used for adjusting the parameters of the retrieval dialogue model according to the target loss function value; An iterative training module, used for iteratively training the retrieval-based dialogue model until the target loss function value is minimized, thereby obtaining a trained retrieval-based dialogue model; The empirical calibration error loss function value is expressed by the following formula: i∈[1,n] and i is an integer, j∈[1,M] and j is an integer; where L ECE represents the empirical calibration error loss function value, T represents the temperature parameter, n represents the number of sentences, M represents the number of intervals mapped by the first probability information, and A j represents the accuracy in the jth interval, p ik represents the probability value of the candidate answer being classified as the kth category for the i-th sentence, ρ j is the midpoint value of the jth interval, and T represents the temperature parameter.
8. An electronic device, It is characterized in that The electronic device includes a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory. When the program is executed by the processor, the dialogue model training method according to any one of claims 1 to 5 or the dialogue generation method according to claim 6 is realized.
9. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the dialogue model training method as described in any one of claims 1 to 5, or the dialogue generation method as described in claim 6.
