Intention recognition method, device, computer equipment and storage medium
By obtaining sample data from the database, constructing an initial semantic representation model and combining clustering and the Hungarian algorithm to identify unknown intentions, it solves the problem of low accuracy of unknown intention recognition in traditional intent recognition methods and improves the recognition effect.
Patent Information
- Application Number
- CN202210044795.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-14
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2042-01-14
AI Technical Summary
Due to the complexity and diversity of intentions in practical application scenarios, traditional intention recognition methods have low effectiveness and insufficient accuracy in identifying unknown intentions.
By obtaining sample label data and unlabeled data from a preset database, a pre-trained model is used to build an initial semantic representation model, and the clustering method and the Hungarian algorithm are combined to identify unknown intentions in the text to be recognized and improve the recognition accuracy.
By constructing the semantic space of the semantic representation model and using unsupervised learning to identify unknown intentions, the recognition accuracy of unknown intentions is significantly improved.
Smart Images

Figure CN114528844B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an intention recognition method, device, computer equipment and storage medium. Background Art
[0002] With the informatization of society, applications based on intent recognition technology such as intelligent customer service based on natural language processing, chatbots, and search engines have begun to be widely used.
[0003] Traditional intent recognition methods generally build intent recognition models. During the construction process, a large amount of corpus needs to be annotated, and based on the already classified intent labels, the intent task is converted into a classification task. A machine learning or deep learning-based model is used to classify the input intent labels to achieve the purpose of intent recognition. This method usually requires a large amount of annotated data, and in actual application scenarios, due to the complexity and diversity of actual intents, some intents will be identified as unknown intents, resulting in low accuracy of intent recognition in application scenarios. Summary of the invention
[0004] The present invention provides an intention recognition method, device, computer equipment and storage medium to improve the recognition accuracy of unknown intentions.
[0005] An intent recognition method, comprising:
[0006] Obtaining sample labeled data and sample unlabeled data from a preset database, and classifying the sample labeled data according to a preset positive and negative classification method to obtain at least one input text pair;
[0007] Inputting the input text pair into a preset pre-training model for training to obtain an initial semantic representation model;
[0008] Inputting the sample label data into the initial semantic representation model to obtain a sample label vector, Inputting the sample unlabeled data into the initial semantic representation model to obtain a sample unlabeled vector;
[0009] According to a preset clustering method, clustering the sample label vector and the sample unlabeled vector to obtain a clustering index and clustering intention label data, wherein the clustering intention label data includes clustering text and clustering intention label data;
[0010] Based on the clustering index, the initial semantic representation model is trained by the clustering intent label data to obtain a trained semantic representation model;
[0011] Acquire text data to be recognized input by the user from the user terminal, input the text data to be recognized into the trained semantic representation model to obtain a predicted semantic vector, and input the sample label data into the trained semantic representation model to obtain a verified semantic vector;
[0012] The similarity result between the predicted semantic vector and the verified semantic vector is calculated by using the clustering index according to the Hungarian algorithm, and the unknown intent in the text data to be identified is identified according to the similarity result.
[0013] An intention recognition device, comprising:
[0014] A data acquisition module, used to acquire sample label data and sample unlabeled data from a preset database, and classify the sample label data according to a preset positive and negative classification method to obtain at least one input text pair;
[0015] An initial model training module, used for inputting the input text pair into a preset pre-training model for training to obtain an initial semantic representation model;
[0016] A sample vector generation module, used for inputting the sample label data into the initial semantic representation model to obtain a sample label vector, and inputting the sample unlabeled data into the initial semantic representation model to obtain a sample unlabeled vector;
[0017] A clustering module, used for clustering the sample label vector and the sample unlabeled vector according to a preset clustering method to obtain a clustering index and clustering intention label data, wherein the clustering intention label data includes clustering text and clustering intention label data;
[0018] A representation model training module, used to train the initial semantic representation model based on the clustering index and the clustering intention label data to obtain a trained semantic representation model;
[0019] A vector representation module is used to obtain text data to be recognized input by a user from a user terminal, input the text data to be recognized into the trained semantic representation model to obtain a predicted semantic vector, and input the sample label data into the trained semantic representation model to obtain a verified semantic vector;
[0020] The intent recognition module is used to calculate the similarity result between the predicted semantic vector and the verified semantic vector according to the Hungarian algorithm through the clustering index, and recognize the unknown intent in the text data to be recognized according to the similarity result.
[0021] A computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned intention recognition method when executing the computer program.
[0022] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned intention recognition method are implemented.
[0023] The intent recognition method, device, computer equipment and storage medium provided by the present invention obtain sample label data and sample unlabeled data, classify the sample label data according to a preset positive and negative classification method, and obtain an input text pair; input the input text pair into a preset pre-training model for training to obtain an initial semantic representation model; input the sample label data and the sample unlabeled data into the initial semantic representation model to obtain a sample label vector and a sample unlabeled vector; cluster the sample label vector and the sample unlabeled vector to obtain a clustering index and clustering intent label data, and obtain a semantic representation model through training with the clustering index and the clustering intent label data; input the text data to be recognized into the semantic representation model to obtain a predicted semantic vector, and input the sample label data into the semantic representation model to obtain a verified semantic vector; calculate the similarity result between the predicted semantic vector and the verified semantic vector according to the clustering index and the Hungarian algorithm, and recognize the unknown intent in the text data to be recognized based on the similarity result. By performing positive and negative classification on sample label data, the semantic space of the initial semantic representation model is constructed. By using known intention labels, unknown intentions are identified through unsupervised learning, thereby improving the accuracy of identifying unknown intentions. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0025] Figure 1 is a schematic diagram of an application environment of an intention recognition method in one embodiment of the present invention;
[0026] Figure 2 is a flow chart of an intention recognition method in one embodiment of the present invention;
[0027] Figure 3 is a schematic diagram of the structure of an intention recognition device in one embodiment of the present invention;
[0028] Figure 4 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0029] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0030] The embodiments of the present invention can acquire and process relevant data based on artificial intelligence technology. Artificial Intelligence (AI) 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.
[0031] The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. Artificial intelligence software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0032] The intention recognition method provided by the embodiment of the present invention can be applied in Figure 1 In an application environment, a terminal device communicates with a server through a network. The terminal device may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices. The server may be implemented as an independent server or a server cluster consisting of multiple servers.
[0033] The system framework 100 may include a terminal device, a network and a server. The network is used to provide a medium for a communication link between the terminal device and the server. The network may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0034] Users can use terminal devices to interact with the server through the network to receive or send messages, etc.
[0035] Terminal devices 101, 102, 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Eperts Group Audio Layer III), MP4 (Moving Picture Eperts Group Audio Layer IV) players, laptop computers, desktop computers, etc.
[0036] Server 105 can be a server that provides various services, such as a background server that provides support for pages displayed on terminal devices 101, 102, and 103. It can be an independent server 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, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0037] It should be noted that the intention recognition method provided in the embodiment of the present invention is executed by a server, and accordingly, the intention recognition device is arranged in the server.
[0038] It should be understood that Figure 1 The numbers of terminal devices, networks and servers are merely illustrative. Any number of terminal devices, networks and servers may be provided according to implementation requirements. The terminal devices in the embodiments of the present invention may specifically correspond to application systems in actual production.
[0039] In one embodiment, if Figure 2 As shown, a method for intention recognition is provided, and the method is applied in Figure 1 The server in the example is used as an example to illustrate the process, including the following steps:
[0040] S10, obtaining sample label data and sample unlabeled data from a preset database, classifying the sample label data according to a preset positive and negative classification method, and obtaining at least one input text pair.
[0041] Specifically, sample labeled data and sample unlabeled data are obtained from a preset database, and the sample labeled data are reconstructed according to the similarity with the target text as the credential for positive and negative classification to obtain the input text pair.
[0042] The preset database may be a server or storage medium storing sample label data. The sample label data includes multiple text data, each of which carries its corresponding intent label. For example, one of the text data is represented as S1={Can I buy e-life insurance if I am 37 years old and have hepatitis B, insurance coverage}, where "Can I buy e-life insurance if I am 37 years old and have hepatitis B" represents the text data of text data S1, and "insurance coverage" represents the intent label of text data S1.
[0043] The sample unlabeled data consists of multiple text data, where the intent corresponding to each text data is unknown.
[0044] The input text pair consists of target text data, positive text that is similar to the target text data, and negative text that is not similar to the target text. For example, input text pair = {sentence 1, positive text, negative text}, where sentence 1 is the target text data, sentence 1 is similar to the intent label of the positive text, and sentence 1 is not similar to the intent label of the negative text. According to the number of text data contained in the sample label data, there will be multiple input text pairs for the same target text data.
[0045] The method for determining whether the intentions of text data are similar includes but is not limited to calculating the similarity between text data, and determining whether the text data other than the target text data is positive text or negative text based on the difference between the similarity and a preset threshold. Therefore, the positive and negative classification method of the sample label statement includes but is not limited to calculating the object similarity between the target text data and other text data.
[0046] S20, inputting the input text pair into a preset pre-training model for training to obtain an initial semantic representation model.
[0047] Specifically, a preset deep learning / machine learning algorithm is selected to build a pre-trained model, and the pre-trained model is trained by inputting text pairs to obtain a model with initial semantic representation.
[0048] In this embodiment, the pre-training model is constructed based on the BERT model. The BERT (Bidirectional Encoder Representations from Transformer) model is used to obtain rich semantic information of the text and represent the semantic information of the text in a specific NLP (Nature Language Processing) task.
[0049] The input text pair is represented as a word vector, a text vector and a position vector. The BERT model uses the sum of the word vector, the text vector and the position vector as the input of the BERT model.
[0050] The BERT model is built on the basis of the Transformer model, and the Transformer module is constructed through the attention mechanism. The Attention mechanism mainly involves three concepts: Query, Key, and Value. In the application scenario of enhancing the semantic representation of a word, the target word and its context words have their own original Value. The Attention mechanism uses the target word as the Query and each word in its context as the Key. It uses the similarity between the Query and each Key as the weight, and integrates the Value of each word in the context into the original Value of the target word. The Attention mechanism uses 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 linear transformation. 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 integrated as the output of Attention, that is, the enhanced semantic vector representation of the target word.
[0051] Based on the positive and negative features of the input text pairs, when training the pre-trained model, a loss function is set so that in the semantic space of the pre-trained model, the text representations between positive texts are as close as possible, and the text representations between negative texts are as far as possible.
[0052] S30, inputting the sample label data into the initial semantic representation model to obtain a sample label vector, and inputting the sample unlabeled data into the initial semantic representation model to obtain a sample unlabeled vector.
[0053] Specifically, the text data in the sample labeled data and the text data in the sample unlabeled data are respectively input into the initial semantic representation model, and the sample label vector of the sample labeled data and the sample unlabeled vector of the sample unlabeled data are obtained from the initial semantic representation model.
[0054] For example, the initial semantic representation model is g', and the sample label data is S k , then the sample label vector is feat k =g'(S k ); the number of samples without labels is S unk , then the sample unlabeled vector is feat unk =g' (S unk ).
[0055] S40, clustering the sample label vectors and the sample unlabeled vectors according to a preset clustering method to obtain clustering indexes and clustering intention label data, wherein the clustering intention label data includes clustering text and clustering intention label data.
[0056] Specifically, before clustering, the number of clusters needs to be set in advance. In this embodiment, the number of clusters is set to a multiple of the number of intent labels in the sample label data, that is, cluster_n = λ*n, usually λ = 1.25, and this coefficient can be modified according to the actual business scenario.
[0057] According to the set number of clusters, the sample label vectors and sample unlabeled vectors are clustered, and the sample label vectors and / or sample unlabeled vectors with similar intent labels are formed into clusters. The clustering results include the number of clusters and the clustering intent labels formed by each cluster, forming clustering intent label data.
[0058] As an optional method, by calculating the clustering evaluation index of each cluster, the clusters obtained by clustering are screened out, and the clustering intent labels of the retained clusters are used as clustering intent label data.
[0059] Among them, the clustering evaluation index SC can be calculated according to the following formula:
[0060]
[0061] Among them, a is the average distance between the target sample data and other sample data in the cluster, b is the average distance between the target sample data and samples in other clusters, di represents the i-th target sample data, and N refers to the number of sample data.
[0062] Furthermore, as an implementation method, the clusters obtained by clustering are accumulated according to the number of sample data in the clusters, and the clusters are sorted according to the accumulated number. When the number of sample data in the sorting exceeds t% of the total number of sample data, the subsequent clusters are regarded as invalid clusters, and the number of clusters obtained is updated cluster_n as the clustering index.
[0063] S50, based on the clustering index, train the initial semantic representation model by clustering the intent label data to obtain a trained semantic representation model.
[0064] Specifically, according to the clustering index, the clustering intention label data obtained by clustering is used to train the initial semantic representation model. When the clustering evaluation index does not improve after K consecutive iterations or the number of iterations exceeds the maximum number of iterations m, the iteration is terminated to obtain the semantic representation model.
[0065] Among them, the K rounds and the maximum number of iterations m can be set according to actual needs and are not specifically limited here.
[0066] S60, obtaining text data to be recognized input by the user from the user terminal, inputting the text data to be recognized into the trained semantic representation model to obtain a predicted semantic vector, and inputting the sample label data into the trained semantic representation model to obtain a verified semantic vector.
[0067] Specifically, the text data to be recognized input by the user is obtained from the user end, the text data to be recognized is input into the semantic representation model to obtain a predicted semantic vector, and the sample label data is input into the semantic representation model to obtain a verified semantic vector.
[0068] S70, calculating the similarity result between the predicted semantic vector and the verified semantic vector according to the Hungarian algorithm through the clustering index, and identifying the unknown intent in the text data to be identified according to the similarity result.
[0069] Specifically, the predicted semantic vectors are clustered by clustering indexes to obtain predicted clustering results, wherein the predicted clustering results include predicted intent labels and the cluster center of each cluster.
[0070] According to actual needs, the number of clusters of the verification semantic vector is set. As a preferred method, the clustering index should be greater than the number of clusters of the verification semantic vector.
[0071] The verification semantic vectors are clustered to obtain verification clustering results, wherein the verification clustering results include the verification labels of the samples and the cluster center of each cluster.
[0072] The Hungarian algorithm is used to calculate the distance between the cluster center of the predicted semantic vector and the cluster center of the verified semantic vector, and obtain the mapping between the cluster center of the predicted semantic vector and the cluster center of the verified semantic vector. Because the clustering index is greater than the number of clusters of the verified semantic vector, some cluster centers of the predicted semantic vector are not matched, and the intent labels corresponding to the unmatched cluster centers are identified as unknown intents.
[0073] Specifically, the Hungarian algorithm is an algorithm for finding the maximum matching in graph data.
[0074] The intent recognition method provided by the embodiment of the present invention obtains sample label data and sample unlabeled data, classifies the sample label data according to a preset positive and negative classification method, and obtains an input text pair; inputs the input text pair into a preset pre-training model for training to obtain an initial semantic representation model; inputs the sample label data and the sample unlabeled data into the initial semantic representation model to obtain a sample label vector and a sample unlabeled vector; clusters the sample label vector and the sample unlabeled vector to obtain a clustering index and clustering intent label data, and obtains a semantic representation model through training with the clustering index and the clustering intent label data; inputs the text data to be recognized into the semantic representation model to obtain a predicted semantic vector, and inputs the sample label data into the semantic representation model to obtain a verified semantic vector; calculates the similarity result between the predicted semantic vector and the verified semantic vector through the clustering index and the Hungarian algorithm, and identifies the unknown intent in the text data to be recognized based on the similarity result. By performing positive and negative classification on sample label data, the semantic space of the initial semantic representation model is constructed. By using known intention labels, unknown intentions are identified through unsupervised learning, thereby improving the accuracy of identifying unknown intentions.
[0075] In this embodiment, as an optional implementation, in S10, sample label data and sample unlabeled data are obtained from a preset database, and the sample label data are classified according to a preset positive and negative classification method to obtain at least one input text pair including:
[0076] S101, determining a target text in the sample label data, and calculating a target text vector of the target text and a text vector of other text data of the sample label data by means of vector conversion.
[0077] S102, calculating the similarity results between the target text vector and the text vectors of other text quantities, taking the text data whose similarity results are greater than a first preset threshold as positive text, and taking the text data whose similarity results are less than a second preset threshold as negative text.
[0078] S103, combining the target text, the positive text and the negative text to form an input text pair.
[0079] Specifically, determine the target text in the sample label data, convert the target text and other text data in the sample label data into vectors, obtain the similarity results between the vectors, and use the text data with a similarity result greater than a first preset threshold as positive text, and use the text data with a similarity result less than a second preset threshold as negative text.
[0080] Among them, the first preset threshold and the second preset threshold are set according to actual conditions. Generally, the first preset threshold can be set to 90% to 95%, etc., and the second preset threshold can be set to 5% to 10%, etc., that is, the first preset threshold is used to measure the similarity between the target text and the category of other text data, and the second preset threshold is used to measure the dissimilarity between the target text and the category of other text data.
[0081] In this embodiment, by calculating the vector similarity results between text data, the positive text and negative text of the target text are obtained, which are then used to construct input text pairs. The similarity between the text data is directly calculated, which means that the original intention of the text is retained. When constructing input text pairs, the positive and negative semantic spaces can be intuitively represented, which is convenient for improving the effect of subsequent clustering.
[0082] In this embodiment, as an optional implementation, in S10, sample label data and sample unlabeled data are obtained from a preset database, and the sample label data are classified according to a preset positive and negative classification method to obtain at least one input text pair including:
[0083] S111, determining the target text and the corresponding intention label of the sample label data, and taking the intention label of the target text as the target intention label.
[0084] S112, by means of text matching, calculate the similarity results between the target intent label and the intent label in the sample label data, and the text data corresponding to the intent label whose similarity results are greater than the first preset threshold is used as positive text, and the text data corresponding to the intent label whose similarity results are less than the second preset threshold is used as negative text.
[0085] S113, combining the target text, the positive text and the negative text to obtain an input text pair.
[0086] Specifically, by determining the intent label of the target text and the intent labels of other text data in the sample label data, through text matching, the text data with the intent label of the target text in the same category is used as positive text, and the text data with different categories is used as negative text.
[0087] Among them, it is determined whether the intention labels of the two are of the same category based on the similarity results. Specifically, the text data with a similarity result greater than a first preset threshold is used as positive text, and the text data with a similarity result less than a second preset threshold is used as negative text. Specifically, the first preset threshold and the second preset threshold are set according to actual needs.
[0088] In this embodiment, based on the intent labels of the text data, the positive text and negative text of the target text are determined, and the input text pairs are constructed according to the categories of the intent labels. When the intent label categories are known, it is beneficial to improve the positive and negative representation of the semantic space and facilitate improving the effect of subsequent clustering.
[0089] In this embodiment, as an optional implementation, in S20, the input text pair is input into a preset pre-trained model for training, and the initial semantic representation model is obtained, including:
[0090] S201, build a pre-training model based on the attention mechanism, and construct positive loss function and negative loss function.
[0091] S202, adjusting the parameters of the pre-trained model through a positive loss function and a negative loss function to obtain an initial semantic representation model.
[0092] Specifically, the loss function of the pre-trained model is expressed according to the following formula:
[0093] L(s, s′) = loss pos +loss neg
[0094] loss pos =max(0,δ pos -cos(g(s),g(s′)))
[0095] loss neg =max(0,cos(g(s),g(t))-δ neg )
[0096] Among them, loss pos Represents the forward loss function, loss neg represents the negative loss function, g is the initial semantic representation model, s is the target text, s' is the positive text, t is the negative text, δpos refers to the coefficient of the positive loss function, and δneg refers to the coefficient of the negative loss function. g(s) represents the semantic vector obtained by inputting the target text into the initial semantic representation model, g(s') represents the semantic vector obtained by inputting the positive text into the initial semantic representation model, and g(t) represents the semantic vector obtained by inputting the negative text into the initial semantic representation model.
[0097] Among them, the positive loss function and the negative loss function are used to construct the semantic space representation of the pre-training model to obtain the initial semantic representation model.
[0098] In this embodiment, the pre-trained model is trained by using positive loss functions and negative loss functions so that text data with the same intent label can be as close as possible in the semantic space, and the distance between text data with different intent labels in the semantic space can be as far as possible. When clustering is performed according to the semantic vector output by the initial semantic representation model, the final clustering effect is guaranteed, so that the distance between samples in the clustering clusters is closer, thereby determining the intent label corresponding to each clustering cluster.
[0099] In this embodiment, as an optional implementation, in S40, according to a preset clustering method, the sample label vector and the sample unlabeled vector are clustered to obtain the clustering index and clustering intention label data including:
[0100] S401 , clustering sample label vectors and sample unlabeled vectors by k-means clustering according to a preset number of clusters to obtain at least one cluster label cluster.
[0101] S402, according to a preset screening method, select a target clustering label cluster from the clustering label clusters as clustering intention label data, and calculate a clustering index according to the target clustering label cluster.
[0102] Specifically, the sample label vector and the sample unlabeled vector are clustered, and the known intent labels in the sample label vector are clustered to classify the intent labels for the sample unlabeled data, thereby obtaining new intent labels.
[0103] In this embodiment, unsupervised clustering is implemented through k-means, and the sample unlabeled vectors and sample label vectors are clustered to obtain new intent labels generated based on clustering, which are used to train the initial semantic representation model to obtain a semantic representation model, thereby further improving the possibility and accuracy of identifying unknown intents.
[0104] In this embodiment, as an optional implementation, in S70, by using the clustering index, according to the Hungarian algorithm, calculating the similarity result between the predicted semantic vector and the verified semantic vector, and identifying the unknown intent in the text data to be identified according to the similarity result includes:
[0105] S701, clustering the prediction semantic vectors according to the clustering index to obtain prediction clustering results, clustering the verification semantic vectors to obtain verification clustering results, wherein the prediction clustering results include prediction clustering clusters, and the verification clustering results include verification clustering clusters.
[0106] S702, based on the Hungarian algorithm, calculate the distance matrix between the predicted clustering results and the verified clustering results, and based on the maximum matching algorithm, identify the unknown intent in the predicted clustering results.
[0107] Specifically, the prediction semantic vector and the verification semantic vector are clustered respectively to obtain the prediction clustering result and the verification clustering result, wherein both the prediction semantic vector and the verification semantic vector are represented by vectors through the semantic representation model, and then the matching results of the prediction clustering result and the verification clustering result are calculated by the Hungarian algorithm to identify the unknown intentions in the text data to be identified.
[0108] In this embodiment, the initial semantic representation model is trained by the clustering intention labels obtained through the first clustering to obtain a semantic representation model, which is used to shorten the distance between similar semantics and increase the distance between dissimilar semantics, thereby facilitating the clustering effect of the output semantic vector and thereby increasing the possibility of identifying unknown intents. On this basis, the accuracy of identifying unknown intents is effectively improved.
[0109] It should be understood that the order of execution of the steps in the above embodiments does not imply a precedence of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0110] In one embodiment, an intention recognition device is provided, and the intention recognition device corresponds one-to-one with the intention recognition method in the above embodiment. Figure 3 As shown, the intention recognition device includes a data acquisition module 31, an initial model training module 32, a sample vector generation module 33, a clustering module 34, a representation model training module 35, a vector representation module 36 and an intention recognition module 37. The functional modules are described in detail as follows:
[0111] The data acquisition module 31 is used to acquire sample label data and sample unlabeled data from a preset database, and classify the sample label data according to a preset positive and negative classification method to obtain at least one input text pair.
[0112] The initial model training module 32 is used to input the input text pair into a preset pre-training model for training to obtain an initial semantic representation model.
[0113] The sample vector generation module 33 is used to input the sample label data into the initial semantic representation model to obtain the sample label vector, and input the sample unlabeled data into the initial semantic representation model to obtain the sample unlabeled vector.
[0114] The clustering module 34 is used to cluster the sample label vectors and the sample unlabeled vectors according to a preset clustering method to obtain clustering indexes and clustering intention label data, wherein the clustering intention label data includes clustering text and clustering intention label data.
[0115] The representation model training module 35 is used to train the initial semantic representation model based on the clustering index and the clustering intention label data to obtain a trained semantic representation model.
[0116] The vector representation module 36 is used to obtain the text data to be recognized input by the user from the user end, input the text data to be recognized into the trained semantic representation model to obtain the predicted semantic vector, and input the sample label data into the trained semantic representation model to obtain the verified semantic vector.
[0117] The intention recognition module 37 is used to calculate the similarity result between the predicted semantic vector and the verified semantic vector according to the Hungarian algorithm through the clustering index, and recognize the unknown intention in the text data to be recognized according to the similarity result.
[0118] Furthermore, the data acquisition module 31 includes:
[0119] The vector conversion unit is used to determine the target text in the sample label data, and calculate the target text vector of the target text and the text vector of other text data of the sample label data by means of vector conversion.
[0120] The positive and negative classification unit is used to calculate the similarity results between the target text vector and the text vectors of the other text quantity, and the text data with similarity results greater than a first preset threshold is used as positive text, and the text data with similarity results less than a second preset threshold is used as negative text.
[0121] The text pair generating unit is used to combine the target text, the positive text and the negative text to form an input text pair.
[0122] Furthermore, the data acquisition module 31 includes:
[0123] The intention determination unit is used to determine the target text of the sample label data and the corresponding intention label, and use the intention label of the target text as the target intention label.
[0124] The intent matching unit is used to calculate the similarity results between the target intent label and the intent label in the sample label data by text matching. The text data corresponding to the intent label whose similarity result is greater than the first preset threshold is used as positive text, and the text data corresponding to the intent label whose similarity result is less than the second preset threshold is used as negative text.
[0125] The text composition unit is used to combine the target text, the positive text and the negative text to obtain an input text pair.
[0126] Furthermore, the initial model training module 32 includes:
[0127] The loss function construction unit is used to build a pre-trained model based on the attention mechanism and to construct positive and negative loss functions.
[0128] The model building unit is used to adjust the parameters of the pre-trained model through positive loss functions and negative loss functions to obtain an initial semantic representation model.
[0129] Furthermore, the clustering module 34 includes:
[0130] The clustering unit is used to cluster the sample label vector and the sample unlabeled vector according to the preset number of cluster clusters by k-means clustering method to obtain at least one cluster label cluster.
[0131] The clustering index generating unit is used to select a target clustering label cluster from the clustering label clusters according to a preset screening method as clustering intention label data, and calculate the clustering index according to the target clustering label cluster.
[0132] Furthermore, the intention recognition module 37 includes:
[0133] The clustering result unit is used to cluster the prediction semantic vectors according to the clustering index to obtain the prediction clustering result, and cluster the verification semantic vectors to obtain the verification clustering result, wherein the prediction clustering result includes the prediction clustering clusters, and the verification clustering result includes the verification clustering clusters.
[0134] The intent recognition unit is used to calculate the distance matrix between the predicted clustering results and the verified clustering results based on the Hungarian algorithm, and to identify the unknown intent in the predicted clustering results based on the maximum matching algorithm.
[0135] The meaning of "first" and "second" in the above modules / units is only to distinguish different modules / units, and is not used to define which module / unit has a higher priority or other limiting meanings. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or modules is not necessarily limited to those steps or modules clearly listed, but may include other steps or modules that are not clearly listed or inherent to these processes, methods, products or devices. The division of modules in this application is only a logical division, and there may be other division methods when implemented in actual applications.
[0136] For the specific definition of the intention recognition device, please refer to the definition of the intention recognition method above, which will not be repeated here. Each module in the above-mentioned intention recognition device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0137] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 4 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data involved in the intention recognition method. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, an intention recognition method is implemented.
[0138] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the method for identifying intent in the above embodiment are implemented, such as Figure 2 Steps S10 to S70 shown in the figure and other extensions of the method and extensions of related steps. Alternatively, when the processor executes the computer program, the functions of each module / unit of the intention recognition device in the above embodiment are realized, for example Figure 3 The functions of modules 31 to 37 are shown in FIG. 3 and will not be described in detail here to avoid repetition.
[0139] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the computer device, and various interfaces and lines are used to connect various parts of the entire computer device.
[0140] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the computer device by running or executing the computer program and / or module stored in the memory and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, video data, etc.), etc.
[0141] The memory may be integrated into the processor or may be arranged separately from the processor.
[0142] In one embodiment, a computer-readable storage medium is provided on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for identifying intent in the above embodiment are implemented. For example, Figure 2 Alternatively, when the computer program is executed by a processor, the functions of each module / unit of the intention recognition device in the above embodiment are realized, for example, Figure 3 The functions of modules 31 to 37 are shown in Figure 3. To avoid repetition, they will not be described here.
[0143] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0144] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0145] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit them. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A method for intention recognition, characterized in that: include: Obtaining sample labeled data and sample unlabeled data from a preset database, and classifying the sample labeled data according to a preset positive and negative classification method to obtain at least one input text pair; Inputting the input text pair into a preset pre-training model for training to obtain an initial semantic representation model; Inputting the sample label data into the initial semantic representation model to obtain a sample label vector, and inputting the sample unlabeled data into the initial semantic representation model to obtain a sample unlabeled vector; Setting the multiple of the number of intent labels in the sample label data as the number of clustering clusters; Based on the set number of clusters, cluster the sample label vectors and the sample unlabeled vectors, and form clusters of the sample label vectors and / or the sample unlabeled vectors with similar intent labels, wherein the clustering result includes the number of clusters and the clustering intent label formed by each cluster; Calculate the clustering evaluation index of each cluster, screen out the clusters obtained by clustering according to the clustering evaluation index, and use the clustering intention labels of the remaining clusters as clustering intention label data; wherein the clustering evaluation index a is the average distance between the target sample data and other sample data in the cluster, b is the average distance between the target sample data and samples in other clusters, d is the average distance between the target sample data and samples in other clusters, i represents the i-th target sample data, and N refers to the number of sample data; wherein the clustering intention label data includes clustering text and clustering intention label data; The clusters are accumulated according to the number of sample data in the clusters, and the clusters are sorted according to the accumulated number. When the number of sample data in the sorting exceeds t% of the number of all sample data, the clusters are regarded as invalid clusters, the number of clusters is updated, and the number of clusters is used as the clustering index; Based on the clustering index, the initial semantic representation model is trained by the clustering intention label data. When the clustering evaluation index is not improved after K consecutive iterations or the number of iterations exceeds the maximum number of iterations m, the iteration is terminated to obtain a trained semantic representation model; Acquire text data to be recognized input by the user from the user terminal, input the text data to be recognized into the trained semantic representation model to obtain a predicted semantic vector, and input the sample label data into the trained semantic representation model to obtain a verified semantic vector; Clustering the prediction semantic vectors according to the clustering index to obtain prediction clustering results, and clustering the verification semantic vectors to obtain verification clustering results, wherein the prediction clustering results include prediction clustering clusters, and the verification clustering results include verification clustering clusters; Based on the Hungarian algorithm, a distance matrix between the predicted clustering result and the verified clustering result is calculated, and based on the maximum matching algorithm, an unknown intent in the predicted clustering result is identified.
2. The method for intention recognition according to claim 1, characterized in that: The step of obtaining sample label data and sample unlabeled data from a preset database, and classifying the sample label data according to a preset positive and negative classification method to obtain at least one input text pair includes: Determine the target text in the sample label data, and calculate the target text vector of the target text and the text vector of other text data of the sample label data by vector conversion; Calculate the similarity result between the target text vector and the text vectors of the other text quantity, take the text data whose similarity result is greater than a first preset threshold as positive text, and take the text data whose similarity result is less than a second preset threshold as negative text; The target text, the positive text and the negative text are combined to form an input text pair.
3. The method for identifying intention according to claim 1, characterized in that: The step of obtaining sample label data and sample unlabeled data from a preset database, and classifying the sample label data according to a preset positive and negative classification method to obtain at least one input text pair includes: Determine a target text and a corresponding intent label of the sample label data, and use the intent label of the target text as a target intent label; By means of text matching, the similarity result between the target intent label and the intent label in the sample label data is calculated, and the text data corresponding to the intent label whose similarity result is greater than a first preset threshold is used as positive text, and the text data corresponding to the intent label whose similarity result is less than a second preset threshold is used as negative text; The target text, the positive text and the negative text are combined to obtain an input text pair.
4. The method for identifying intention according to claim 1, characterized in that: The step of inputting the input text pair into a preset pre-training model for training to obtain an initial semantic representation model comprises: Build a pre-training model based on the attention mechanism, and construct positive loss function and negative loss function; The parameters of the pre-trained model are adjusted through the positive loss function and the negative loss function to obtain an initial semantic representation model.
5. An intention recognition device, characterized in that: Includes the following modules: A data acquisition module, used to acquire sample label data and sample unlabeled data from a preset database, and classify the sample label data according to a preset positive and negative classification method to obtain at least one input text pair; An initial model training module, used for inputting the input text pair into a preset pre-training model for training to obtain an initial semantic representation model; A sample vector generation module, used for inputting the sample label data into the initial semantic representation model to obtain a sample label vector, and inputting the sample unlabeled data into the initial semantic representation model to obtain a sample unlabeled vector; A clustering module, used for setting the multiple of the number of intent labels in the sample label data as the number of clustering clusters; Based on the set number of clusters, cluster the sample label vectors and the sample unlabeled vectors, and form clusters of the sample label vectors and / or the sample unlabeled vectors with similar intent labels, wherein the clustering result includes the number of clusters and the clustering intent label formed by each cluster; Calculate the clustering evaluation index of each cluster, screen out the clusters obtained by clustering according to the clustering evaluation index, and use the clustering intention labels of the remaining clusters as clustering intention label data; wherein the clustering evaluation index a is the average distance between the target sample data and other sample data in the cluster, b is the average distance between the target sample data and samples in other clusters, d is the average distance between the target sample data and samples in other clusters, i represents the i-th target sample data, and N refers to the number of sample data; wherein the clustering intention label data includes clustering text and clustering intention label data; The clusters are accumulated according to the number of sample data in the clusters, and the clusters are sorted according to the accumulated number. When the number of sample data in the sorting exceeds t% of the number of all sample data, the clusters are regarded as invalid clusters, the number of clusters is updated, and the number of clusters is used as the clustering index; A representation model training module is used to train the initial semantic representation model based on the clustering index and the clustering intention label data. When the clustering evaluation index does not improve after K consecutive iterations or the number of iterations exceeds the maximum number of iterations m, the iteration is terminated to obtain a trained semantic representation model; A vector representation module is used to obtain text data to be recognized input by a user from a user terminal, input the text data to be recognized into the trained semantic representation model to obtain a predicted semantic vector, and input the sample label data into the trained semantic representation model to obtain a verified semantic vector; An intention recognition module, used for clustering the predicted semantic vectors according to the clustering index to obtain a predicted clustering result, and clustering the verification semantic vectors to obtain a verified clustering result, wherein the predicted clustering result includes a predicted clustering cluster, and the verified clustering result includes a verified clustering cluster; Based on the Hungarian algorithm, a distance matrix between the predicted clustering result and the verified clustering result is calculated, and based on the maximum matching algorithm, an unknown intent in the predicted clustering result is identified.
6. The intention recognition device according to claim 5, characterized in that: The data acquisition module comprises: A vector conversion unit, used to determine the target text in the sample label data, and calculate the target text vector of the target text and the text vectors of other text data of the sample label data by means of vector conversion; A positive and negative classification unit, used to calculate the similarity result between the target text vector and the text vectors of the other text quantity, and to take the text data whose similarity result is greater than a first preset threshold as positive text, and to take the text data whose similarity result is less than a second preset threshold as negative text; The text pair generating unit is used to combine the target text, the positive text and the negative text to form an input text pair.
7. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the intention recognition method according to any one of claims 1 to 4 are implemented.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the intention recognition method according to any one of claims 1 to 4 are implemented.
