Intent recognition method, device, electronic device and computer-readable storage medium
By using sample library retrieval and expanded statement sample combinations in intent recognition, the problem of lack of global information in the sample matching method is solved and the accuracy of intent recognition is improved.
Patent Information
- Application Number
- CN202010969999.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-14
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2040-09-14
AI Technical Summary
Existing intent recognition methods based on sample matching lack global information, resulting in low recognition accuracy.
By obtaining the sentence to be recognized, the matching candidate sentence samples are retrieved in the intent sample library, and the matching sentence samples are selected from the sample library as extended sentence samples, combined into a sentence sample group, and spliced to form a rewritten sentence. Use the intent recognition model to determine the intent recognition results.
It improves the accuracy of intent recognition, avoids false positives and false negatives, and enhances the model's ability to capture global information on statement samples.
Smart Images

Figure CN112256845B
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of natural language processing, and in particular to an intent recognition method, device, electronic device and computer-readable storage medium. Background Art
[0002] In recent years, with the advancement of related technologies, products with dialogue systems as the core, such as smart speakers and smart customer service, have gradually entered the public's field of vision. The technical modules of a typical dialogue system are as follows: Figure 1 As shown in the figure, it includes multiple modules such as speech recognition, intent recognition, dialogue management, natural language generation, and speech synthesis. Among them, the most common method for intent recognition is text classification, but text classification usually requires a large amount of training data. When the training data is insufficient, another intent recognition method is usually used, that is, the method based on sample matching.
[0003] However, the inventors have discovered that a significant problem with existing intent recognition methods based on sample matching is the lack of global information, resulting in low recognition accuracy. Summary of the invention
[0004] In view of the above problems, the present application is proposed to provide an intention recognition method, device, electronic device and computer-readable storage medium that overcome the above problems or at least partially solve the above problems.
[0005] According to a first aspect of the present application, there is provided an intention recognition method, comprising:
[0006] Acquire a sentence to be recognized and search in an intent sample library according to the sentence to be recognized to obtain a candidate sentence sample matching the sentence to be recognized;
[0007] Selecting sentence samples matching the candidate sentence samples from the intention sample library as extended sentence samples, and determining a sentence sample group corresponding to the sentence to be recognized based on the candidate sentence samples and the extended sentence samples;
[0008] The sentence to be recognized is concatenated with the sentence sample group to obtain a rewritten sentence, and an intent recognition result of the sentence to be recognized is determined according to an intent recognition model and the rewritten sentence.
[0009] Optionally, the acquiring of the sentence to be recognized and searching in the intent sample library according to the sentence to be recognized to obtain a candidate sentence sample matching the sentence to be recognized comprises:
[0010] Determining the text similarity between the sentence to be recognized and each sentence sample in the intent sample library;
[0011] At least one candidate sentence sample matching the sentence to be recognized is determined according to the text similarity.
[0012] Optionally, the intent sample library stores a correspondence between sentence samples and intent labels, and the step of selecting a sentence sample matching the candidate sentence sample from the intent sample library as an extended sentence sample, and determining a sentence sample group corresponding to the sentence to be recognized based on the candidate sentence sample and the extended sentence sample comprises:
[0013] Grouping the candidate sentence samples according to the intention labels of the candidate sentence samples to obtain at least one candidate sentence sample group;
[0014] Sample expansion is performed on each candidate sentence sample group according to the number of candidate sentence samples in each candidate sentence sample group, and the expanded candidate sentence sample group is used as the sentence sample group corresponding to the sentence to be recognized.
[0015] Optionally, the sample expansion of each candidate sentence sample group according to the number of candidate sentence samples in each candidate sentence sample group, and using the expanded candidate sentence sample group as the sentence sample group corresponding to the sentence to be recognized includes:
[0016] Comparing the number of candidate examples in each candidate sentence example group with a first preset threshold;
[0017] When the number of candidate samples in the candidate sentence sample group is less than a first preset threshold, an extended sentence sample that matches the intent label of the candidate sentence sample group and whose text similarity with the sentence to be recognized is lower than a second preset threshold is retrieved from the intent sample library, and a sentence sample group corresponding to the sentence to be recognized is obtained based on the candidate sentence sample group and the extended sentence samples.
[0018] Optionally, the method further comprises:
[0019] When the number of candidate sentence samples in the candidate sentence sample group is greater than the first preset threshold, the candidate sentence samples in the candidate sentence sample group whose text similarity with the sentence to be recognized is greater than a third preset threshold are determined as retained candidate sentence samples, and a sentence sample group corresponding to the sentence to be recognized is obtained based on the retained candidate sentence samples.
[0020] Optionally, the step of concatenating the sentence to be recognized with the sentence sample group to obtain a rewritten sentence, and determining the intent recognition result of the sentence to be recognized according to the intent recognition model and the rewritten sentence includes:
[0021] Using a first preset separator, each sentence sample in each sentence sample group is spliced within the group to obtain a first splicing result;
[0022] Using a second preset separator, the sentence to be recognized is concatenated with each sentence sample group to obtain a second concatenation result;
[0023] The first concatenation result and the second concatenation result are combined and input into the intention recognition model for recognition to obtain the intention recognition result of the sentence to be recognized.
[0024] Optionally, determining the intention recognition result of the sentence to be recognized according to the intention recognition model and the rewritten sentence includes:
[0025] Determine, by using the intent recognition model, the probability that the intent of the sentence to be recognized is the same as the intent label of each sentence sample group;
[0026] The intention recognition result of the sentence to be recognized is determined according to the probability.
[0027] Optionally, the intent recognition model is trained by the following method:
[0028] Acquire a sentence to be trained and search the intent sample library according to the sentence to be trained to obtain a candidate sentence sample that matches the sentence to be trained;
[0029] Selecting sentence samples matching the candidate sentence samples from the intention sample library as extended sentence samples, and determining a sentence sample group corresponding to the sentence to be trained based on the candidate sentence samples and the extended sentence samples;
[0030] The sentence to be trained is concatenated with each sentence sample group and then input into the intention recognition model for training to obtain the training loss value corresponding to each sentence sample group, and the parameters of the intention recognition model are updated according to the training loss value corresponding to each sentence sample group.
[0031] According to a second aspect of the present application, there is provided an intention recognition device, the device comprising:
[0032] An acquisition unit, used for acquiring a sentence to be recognized and searching in an intention sample library according to the sentence to be recognized to obtain a candidate sentence sample matching the sentence to be recognized;
[0033] An expansion unit, configured to select a sentence sample matching the candidate sentence sample from the intention sample library as an expanded sentence sample, and determine a sentence sample group corresponding to the sentence to be recognized based on the candidate sentence sample and the expanded sentence sample;
[0034] The recognition unit is used to concatenate the sentence to be recognized with the sentence sample group to obtain a rewritten sentence, and determine the intention recognition result of the sentence to be recognized according to the intention recognition model and the rewritten sentence.
[0035] Optionally, the acquiring unit is further used for:
[0036] Determining the text similarity between the sentence to be recognized and each sentence sample in the intent sample library;
[0037] At least one candidate sentence sample matching the sentence to be recognized is determined according to the text similarity.
[0038] Optionally, the intent sample library stores a correspondence between sentence samples and intent labels, and the expansion unit is further used to:
[0039] Grouping the candidate sentence samples according to the intention labels of the candidate sentence samples to obtain at least one candidate sentence sample group;
[0040] Sample expansion is performed on each candidate sentence sample group according to the number of candidate sentence samples in each candidate sentence sample group, and the expanded candidate sentence sample group is used as the sentence sample group corresponding to the sentence to be recognized.
[0041] Optionally, the extension unit is further used for:
[0042] Comparing the number of candidate examples in each candidate sentence example group with a first preset threshold;
[0043] When the number of candidate samples in the candidate sentence sample group is less than a first preset threshold, an extended sentence sample that matches the intent label of the candidate sentence sample group and whose text similarity with the sentence to be recognized is lower than a second preset threshold is retrieved from the intent sample library, and a sentence sample group corresponding to the sentence to be recognized is obtained based on the candidate sentence sample group and the extended sentence samples.
[0044] Optionally, the device further comprises:
[0045] A determination unit is used to determine, when the number of candidate sentence samples in the candidate sentence sample group is greater than the first preset threshold, the candidate sentence samples in the candidate sentence sample group whose text similarity with the sentence to be recognized is greater than a third preset threshold as retained candidate sentence samples, and obtain a sentence sample group corresponding to the sentence to be recognized based on the retained candidate sentence samples.
[0046] Optionally, the identification unit is further used for:
[0047] Using a first preset separator, each sentence sample in each sentence sample group is spliced within the group to obtain a first splicing result;
[0048] Using a second preset separator, the sentence to be recognized is concatenated with each sentence sample group to obtain a second concatenation result;
[0049] The first concatenation result and the second concatenation result are combined and input into the intention recognition model for recognition to obtain the intention recognition result of the sentence to be recognized.
[0050] Optionally, the identification unit is further used for:
[0051] Determine, by using the intent recognition model, the probability that the intent of the sentence to be recognized is the same as the intent label of each sentence sample group;
[0052] The intention recognition result of the sentence to be recognized is determined according to the probability.
[0053] Optionally, the intent recognition model is trained by the following method:
[0054] Acquire a sentence to be trained and search the intent sample library according to the sentence to be trained to obtain a candidate sentence sample that matches the sentence to be trained;
[0055] Selecting sentence samples matching the candidate sentence samples from the intention sample library as extended sentence samples, and determining a sentence sample group corresponding to the sentence to be trained based on the candidate sentence samples and the extended sentence samples;
[0056] The sentence to be trained is concatenated with each sentence sample group and then input into the intention recognition model for training to obtain the training loss value corresponding to each sentence sample group, and the parameters of the intention recognition model are updated according to the training loss value corresponding to each sentence sample group.
[0057] According to a third aspect of the present application, there is provided an electronic device comprising: a processor; and a memory arranged to store computer executable instructions, wherein when the executable instructions are executed, the processor executes any of the above-described intent recognition methods.
[0058] According to the fourth aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores one or more programs, and when the one or more programs are executed by a processor, they implement any of the intent recognition methods described above.
[0059] From the above, it can be seen that the technical solution of the present application obtains a sentence to be recognized and searches the intent sample library according to the sentence to be recognized to obtain a candidate sentence sample that matches the sentence to be recognized; selects a sentence sample that matches the candidate sentence sample from the intent sample library as an extended sentence sample, and determines a sentence sample group corresponding to the sentence to be recognized based on the candidate sentence sample and the extended sentence sample; concatenates the sentence to be recognized with the sentence sample group to obtain a rewritten sentence, and determines the intent recognition result of the sentence to be recognized based on the intent recognition model and the rewritten sentence. The present application expands the samples so that the intent recognition model can pay attention to more information when matching, including sentence sample information of other intents and other sentence sample information of the same intent, etc., so that intent recognition can be more accurate.
[0060] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0062] Figure 1 A structural block diagram of a dialogue system in an embodiment of the prior art is shown;
[0063] Figure 2 A flowchart of an intention recognition method according to an embodiment of the prior art is shown;
[0064] Figure 3 A schematic diagram of a process of an intention recognition method according to an embodiment of the present application is shown;
[0065] Figure 4 A schematic diagram of the training process of an intent recognition model according to an embodiment of the present application is shown;
[0066] Figure 5 A schematic diagram of the structure of an intention recognition device according to an embodiment of the present application is shown;
[0067] Figure 6 A schematic diagram of the structure of an electronic device according to an embodiment of the present application is shown;
[0068] Figure 7A schematic diagram of the structure of a computer-readable storage medium according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0069] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.
[0070] like Figure 2 As shown, a method for intent recognition based on sample matching in the prior art is provided. In order to realize intent recognition, the method needs to collect a small number of samples for each intent in advance. When a user makes a request, the user expression is first retrieved from the collected sample set to obtain relevant candidate samples, and then the candidate samples and the user expression are sorted by similarity according to the sorting model. Finally, the intent corresponding to the sample that is most similar to the user expression and greater than a certain threshold is selected as the recognized intent.
[0071] However, a significant problem with the above-mentioned intent recognition method based on sample matching is the lack of capturing and learning global information. This is specifically reflected in two aspects. On the one hand, when matching the user expression with a candidate sample, other candidate sample information is not considered and utilized, which makes it impossible for the model to obtain other sample information that is different from the candidate sample intention, which may lead to the situation of false positive candidate samples; on the other hand, when the user expression is matched with a candidate sample, other sample information with the same intention as the candidate sample is not utilized, which makes it impossible for the model to obtain extended semantic information, which may lead to the situation of missing candidate samples. The above two situations make it impossible for the intent recognition method based on sample matching in the prior art to obtain more accurate intent recognition results.
[0072] Based on this, the embodiment of the present application provides an intent recognition method. Intent can be understood as a relatively clear awareness of the need for the goal and method to be achieved. The intent recognition of the embodiment of the present application can be understood as enabling search engines, question-answering systems, and recommendation systems to identify the most relevant information to the query input by the user. The query information can be the user's voice information or directly input text information.
[0073] A typical application scenario is the application of chatbots or intelligent customer service robots. Intention recognition in this scenario means that when a user communicates with a chatbot, the robot can quickly determine the user's true intention based on the direct or indirect information provided by the user. For example, some chatbots can identify the user's travel consumption intention from the user's questions, such as booking air tickets and hotels. For enterprises, accurately identifying consumption-related intentions has huge commercial value. For users, this also saves the user's search clicks to a certain extent, shortens the search time, and greatly improves the user experience.
[0074] Intents reflect user needs to a certain extent. For example, the above-mentioned "booking air tickets and booking hotels" intent indicates the user's travel consumption needs. For these intents, the business side or domain experts can determine the intent name and classify them, that is, summarize the user needs. A sentence entered by the user may correspond to multiple intents. For example, if the user enters "airport", it may mean that the user wants to book a flight, or it may mean that the user wants to go to the airport or learn about the situation around the airport. In this example, "booking a flight", "going to the airport" and "learning about the situation around the airport" are three types of intent related to the search keyword "airport". Similarly, an intent may also correspond to multiple different sentences. Here, different sentence samples corresponding to each intent can be pre-set to form an intent sample library as the basis for subsequent intent recognition. The more the intent matches the user's real needs, the faster the user's search purpose can be achieved, improving search efficiency.
[0075] like Figure 3 As shown, the intention recognition method of the embodiment of the present application includes the following steps S310 to S330:
[0076] Step S310, obtaining a sentence to be recognized and searching in an intent sample library according to the sentence to be recognized to obtain a candidate sentence sample matching the sentence to be recognized.
[0077] When performing intent recognition, the embodiment of the present application may first obtain a sentence to be recognized, where the sentence to be recognized may be text information directly input by the user, or may be a speech recognition result obtained after recognizing the user's voice information. The sentence to be recognized is then searched and matched in a pre-built intent sample library, which may store a certain number of sentence samples and corresponding intent labels, as well as information such as the text similarity between the sentence sample and the sentence to be recognized.
[0078] By searching and matching the above-mentioned sentence to be recognized in the intent sample library, a candidate sentence sample matching the sentence to be recognized can be obtained. The matching here can be a matching of text similarity, that is, the degree of text similarity between the sentence to be recognized and the sentence samples in the intent sample library. The sentence with a higher degree of similarity can be used as a candidate sentence sample for the sentence to be recognized.
[0079] Step S320, selecting a sentence sample that matches the candidate sentence sample from the intention sample library as an extended sentence sample, and determining a sentence sample group corresponding to the sentence to be recognized based on the candidate sentence sample and the extended sentence sample.
[0080] As mentioned above, since the intent recognition method based on sample matching in the prior art does not take into account the global information of the sample, in order to improve the accuracy of the intent recognition results, the embodiment of the present application, after obtaining the candidate sentence samples of the sentence to be recognized, performs sample expansion on the above-mentioned candidate sentence samples. The sample expansion here can be understood as further supplementing the candidate samples so that the model can capture and learn the global information of the sentence samples.
[0081] In specific implementation, a sentence sample that matches the candidate sentence sample can be selected from the intention sample library as an extended sentence sample, and then the candidate sentence sample and the extended sentence sample are combined into a sentence sample group. Multiple sentence sample groups constitute a sentence sample set corresponding to the sentence to be identified.
[0082] Step S330, concatenating the sentence to be recognized with the sentence sample group to obtain a rewritten sentence, and determining the intent recognition result of the sentence to be recognized based on the intent recognition model and the rewritten sentence.
[0083] After obtaining each sentence sample group, each sentence sample group is spliced or combined with the sentence to be recognized to obtain the spliced or combined rewritten sentence as the input of the intent recognition model. The intent recognition model here can adopt the infrastructure of the BERT model (Bidirectional Encoder Representations from Transformer), which is a language representation model developed by the Google team and has been widely used in the field of natural language processing. The BERT model is designed to pre-train deep bidirectional representations based on the left and right contexts of all layers. Therefore, the pre-trained BERT representation can be fine-tuned with only one additional output layer to create the current optimal model for many tasks (such as question answering and language reasoning) without making a lot of modifications to the task-specific architecture. Of course, those skilled in the art can also choose other types of recognition models according to actual conditions, which are not specifically limited here. Finally, according to the intent recognition model, the intent corresponding to the sentence to be recognized can be output.
[0084] The embodiments of the present application expand samples so that the intent recognition model can focus on more sample information during matching, avoiding false positives and false negatives, thereby making intent recognition more accurate.
[0085] In one embodiment of the present application, the step of obtaining a sentence to be recognized and searching in an intent sample library based on the sentence to be recognized to obtain a candidate sentence sample that matches the sentence to be recognized includes: determining a text similarity between the sentence to be recognized and each sentence sample in the intent sample library; and determining at least one candidate sentence sample that matches the sentence to be recognized based on the text similarity.
[0086] When determining the candidate sentence samples corresponding to the sentence to be recognized, the embodiments of the present application can be determined based on text similarity. Text similarity can be understood as the degree of similarity between texts in dimensions such as hyponymy and synonymy. The higher the similarity between two texts, the closer the semantics of the two texts are. Usually, the steps for calculating the similarity between two texts are: 1) Through Chinese word segmentation, the complete sentence is divided into independent word sets according to the word segmentation algorithm; 2) Calculate the union of the two word sets (word bag); 3) Calculate the word frequency of each word set and vectorize the word frequency; 4) Bring it into the vector calculation model to calculate the text similarity. Of course, the method of calculating text similarity is not limited to this, and will not be listed here one by one.
[0087] After obtaining the text similarity between the sentence to be recognized and each sentence sample in the intent sample library, candidate sentence samples can be selected according to certain rules. For example, sentence samples in the intent sample library whose text similarity with the sentence to be recognized exceeds a preset threshold can be used as candidate sentence samples. Alternatively, the text similarities can be sorted in descending order, and the top N sentence samples can be used as candidate sentence samples.
[0088] In one embodiment of the present application, the intent sample library stores a correspondence between sentence samples and intent labels, and the selecting a sentence sample that matches the candidate sentence sample from the intent sample library as an extended sentence sample, and determining a sentence sample group corresponding to the sentence to be recognized based on the candidate sentence sample and the extended sentence sample includes: grouping the candidate sentence samples according to the intent labels of the candidate sentence samples to obtain at least one candidate sentence sample group; performing sample expansion on each candidate sentence sample group according to the number of candidate sentence samples in each candidate sentence sample group, and using the expanded candidate sentence sample group as the sentence sample group corresponding to the sentence to be recognized.
[0089] The intent sample library of the embodiment of the present application may store the correspondence between sentence samples and intent labels in advance. Taking leisure and entertainment applications as an example, a sentence sample may be "what are the fun things to do around Beijing", and the corresponding intent label may be "search for attractions".
[0090] When performing sample expansion, the sample expansion of the embodiment of the present application may include two dimensions, one is the expansion of different dimensions of intent, and the other is the expansion of the same intent but different dimensions of text. Specifically, the candidate sentence samples can be grouped based on the correspondence between the sentence samples and the intent labels stored in the above-mentioned intent sample library, that is, the candidate sentence samples with the same intent labels are grouped together, and then multiple candidate sentence sample groups are obtained. This process can be regarded as an expansion of different dimensions of intent. Afterwards, the sample expansion of each candidate sentence sample group can be performed according to the number of candidate sentence samples in each candidate sentence sample group. This process can be regarded as an expansion of the same intent but different dimensions of text. Finally, the expansion of the two dimensions is combined together as the final sentence sample group corresponding to the sentence to be identified.
[0091] For the sample expansion of the first dimension, when the sentence to be recognized matches a candidate sample, the information of other candidate samples can be further used, so that the model can obtain information about other samples with different intentions from the candidate sample, thereby avoiding the situation of false positives of candidate samples. For the sample expansion of the second dimension, when the sentence to be recognized matches a candidate sample, the information of other samples with the same intention as the candidate sample can be used at the same time, so that the model can obtain extended semantic information and avoid the situation of missing candidate samples.
[0092] In one embodiment of the present application, the sample expansion of each candidate sentence sample group according to the number of candidate sentence samples in each candidate sentence sample group, and using the expanded candidate sentence sample group as the sentence sample group corresponding to the sentence to be recognized includes: comparing the number of candidate samples in each candidate sentence sample group with a first preset threshold; when the number of candidate samples in the candidate sentence sample group is less than the first preset threshold, retrieving in the intention sample library an extended sentence sample that matches the intention label of the candidate sentence sample group and has a text similarity with the sentence to be recognized lower than a second preset threshold, and obtaining the sentence sample group corresponding to the sentence to be recognized based on the candidate sentence sample group and the extended sentence sample.
[0093] When the embodiment of the present application performs sample expansion on each candidate sentence sample group according to the number of candidate sentence samples in each candidate sentence sample group, the number of candidate samples in each group can be determined first, and it can be judged whether the number reaches the preset requirement. For example, it is pre-set that the number of candidate sentence samples in each candidate sentence sample group should be no less than 5, and the number of samples in the candidate sentence sample group G1 is 3, the number of samples in the candidate sentence sample group G2 is 2, and the number of samples in the candidate sentence sample group G3 is 1, which are all less than the preset requirement. Then, the samples of these three groups of candidate sentence sample groups can be expanded to meet the preset requirement. The size of the preset threshold can be flexibly set and adjusted according to the actual situation, and is not specifically limited here.
[0094] If it is determined that the candidate sentence sample group needs to be expanded, a search can be performed in the intent sample library to determine the expanded sentence sample. The selection condition of the expanded sentence sample can be a sentence sample with the same intent label as the candidate sentence sample group but different from the text of the sentence to be recognized or with a low similarity. Finally, the expanded sentence sample is added to the candidate sentence sample group to obtain the sentence sample group corresponding to the sentence to be recognized. The sentence sample group obtained after expansion captures the global information of the sentence sample, making the subsequent intent recognition result more accurate.
[0095] In one embodiment of the present application, the method also includes: when the number of candidate sentence samples in the candidate sentence sample group is greater than the first preset threshold, the candidate sentence samples in the candidate sentence sample group whose text similarity with the sentence to be recognized is greater than a third preset threshold are determined as retained candidate sentence samples, and a sentence sample group corresponding to the sentence to be recognized is obtained based on the retained candidate sentence samples.
[0096] In addition to the above-mentioned situation where the number of candidate samples is less than the preset threshold, there may also be a situation where the number of candidate samples is greater than or equal to the preset threshold. For example, it is pre-set that the number of candidate sentence samples in each candidate sentence sample group should be no less than 5, and the number of samples in the current candidate sentence sample group G1 is 6, the number of samples in the candidate sentence sample group G2 is 5, and the number of samples in the candidate sentence sample group G3 is 1. At this time, the sample expansion method of the above-mentioned embodiment can be used for candidate sentence sample group G3. For candidate sentence sample group G1, if its number of samples exceeds the preset threshold, it can be selected from it to meet the preset requirements. The selection standard can be to determine the text similarity between each candidate sentence sample in the candidate sentence sample group and the sentence to be identified, and the candidate sentence samples with a similarity greater than the preset threshold or the top N with the highest similarity are retained as candidate sentence samples. For the case where the number of samples is the same as the preset threshold, such as candidate sentence sample group G2, all these candidate sentence samples can be directly retained.
[0097] In one embodiment of the present application, the sentence to be recognized is spliced with the sentence sample group to obtain a rewritten sentence, and the intention recognition result of the sentence to be recognized is determined according to the intention recognition model and the rewritten sentence, including: using a first preset delimiter to perform intra-group splicing on each sentence sample in each sentence sample group to obtain a first splicing result; using a second preset delimiter to splice the sentence to be recognized with each sentence sample group to obtain a second splicing result; combining the first splicing result and the second splicing result and inputting them into the intention recognition model for recognition to obtain the intention recognition result of the sentence to be recognized.
[0098] When the embodiment of the present application obtains the rewritten sentence that can be input into the intent recognition model, the sentence to be recognized can be spliced with each sentence sample group in a certain order. The splicing process includes two levels, one level is to splice each sentence sample in each sentence sample group within the group, and the other level is to splice the sentence to be recognized with each sentence sample group. For the first level of splicing, the [SEP] (short for Separation, translated as separation) separator commonly used in the BERT model can be used for splicing, and for the second level of splicing, the [CLS] (short for Classification, translated as separation) separator in the BERT model can be used for splicing. The final rewritten sentence can be in the following form: [CLS] sentence to be recognized [CLS] candidate sentence sample 1 [SEP] candidate sentence sample 3 [SEP] extended sentence sample a [CLS] candidate sentence sample 2 [SEP] candidate sentence sample 4 [SEP] extended sentence sample b [CLS].
[0099] It should be noted that the above separators are only different in separation levels, namely, sample level and sample group level. Those skilled in the art can flexibly select the type of separator to be used according to actual conditions, and no specific limitation is made here.
[0100] In one embodiment of the present application, determining the intention recognition result of the sentence to be recognized based on the intention recognition model and the rewritten sentence includes: using the intention recognition model to determine the probability that the intention of the sentence to be recognized is the same as the intention label of each sentence sample group; determining the intention recognition result of the sentence to be recognized based on the probability.
[0101] The result output by the user recognition model of the embodiment of the present application can be the probability that the intention of the sentence to be recognized is the same as the intention label of each sentence sample group. For example, there are three candidate sentence sample groups G1, G2 and G3, and the final recognition model output result is P1=0.7, P2=0.5, P3=0.2, that is, the probability that the intention of the sentence to be recognized is the same as the intention label of the candidate sentence sample group G1 is 0.7, the probability that it is the same as the intention label of G2 is 0.5, and the probability that it is the same as the intention label of G3 is 0.2. Among the above three prediction probabilities, P1 is the largest, and the final output is that the intention of the sentence to be recognized is the recognition result corresponding to the intention of the candidate sentence sample group G1.
[0102] In one embodiment of the present application, the intent recognition model is trained by the following method: obtaining a sentence to be trained and searching in an intent sample library based on the sentence to be trained to obtain a candidate sentence sample that matches the sentence to be trained; selecting a sentence sample that matches the candidate sentence sample from the intent sample library as an extended sentence sample, and determining a sentence sample group corresponding to the sentence to be trained based on the candidate sentence samples and the extended sentence samples; concatenating the sentence to be trained with each sentence sample group and inputting the concatenated sentence sample into the intent recognition model for training to obtain a training loss value corresponding to each sentence sample group, and updating the parameters of the intent recognition model according to the training loss value corresponding to each sentence sample group.
[0103] like Figure 4 As shown in the figure, a training process diagram of an intent recognition model is provided. First, the labeled sentences to be trained are obtained, and the sentences to be trained are searched in the intent sample library to obtain multiple candidate sentence samples matching the sentences to be trained. Then, the candidate sentence samples are expanded according to the intent labels of the candidate sentence samples to obtain expanded sentence samples. The candidate sentence samples and the expanded sentence samples are combined as the sentence sample group corresponding to the sentence to be trained. The sentence to be trained is concatenated with each sentence sample group and input into the intent recognition model such as the BERT model for training. During the training process, the hidden state of the output layer corresponding to each sentence sample group can be processed by Softmax. The Softmax function normalizes multiple values obtained by the neural network so that the obtained values are between [0,1], making the results interpretable, that is, the results can be regarded as probabilities. The greater the probability of a certain category, the higher the possibility of classifying the sample into that category. Finally, the probability that the intent labels of each group are the same as the intent labels of the sentences to be trained is output.
[0104] The intent recognition of the embodiment of the present application can be regarded as a classification problem, that is, predicting which category or categories of intent the sentence to be recognized belongs to. One of the loss functions commonly used in classification problems is the cross-entropy loss function. Cross-entropy (CrossEntropy) is mainly used to measure the difference information between two probability distributions. p represents the distribution of the true label, and q is the distribution of the predicted label of the trained model. The cross-entropy loss function can measure the similarity between p and q. Therefore, the embodiment of the present application can use the cross-entropy loss function to measure the difference between the above-mentioned groups of prediction results and the true labels. The final training loss value Loss can be the sum of the training loss values of each group (assuming there are M groups), that is, L = Loss1 + Loss2 + ... + LossM. Finally, the parameters of the intent recognition model are iteratively updated according to the total training loss value L until the termination condition is reached.
[0105] The present application embodiment provides an intention recognition device 500, such as Figure 5 As shown, the device 500 includes: an acquisition unit 510, an expansion unit 520 and an identification unit 530.
[0106] The acquisition unit 510 of the embodiment of the present application is used to acquire a sentence to be recognized and search in an intent sample library according to the sentence to be recognized to obtain a candidate sentence sample matching the sentence to be recognized.
[0107] When performing intent recognition, the embodiment of the present application may first obtain a sentence to be recognized, where the sentence to be recognized may be text information directly input by the user, or may be a speech recognition result obtained after recognizing the user's voice information. The sentence to be recognized is then searched and matched in a pre-built intent sample library, which may store a certain number of sentence samples and corresponding intent labels, as well as information such as the text similarity between the sentence sample and the sentence to be recognized.
[0108] By searching and matching the above-mentioned sentence to be recognized in the intent sample library, a candidate sentence sample matching the sentence to be recognized can be obtained. The matching here can be a matching of text similarity, that is, the degree of text similarity between the sentence to be recognized and the sentence samples in the intent sample library. The sentence with a higher degree of similarity can be used as a candidate sentence sample for the sentence to be recognized.
[0109] The expansion unit 520 of the embodiment of the present application is used to select sentence samples matching the candidate sentence samples from the intention sample library as expanded sentence samples, and determine a sentence sample group corresponding to the sentence to be recognized based on the candidate sentence samples and the expanded sentence samples.
[0110] As mentioned above, since the intent recognition method based on sample matching in the prior art does not take into account the global information of the sample, in order to improve the accuracy of the intent recognition results, the embodiment of the present application, after obtaining the candidate sentence samples of the sentence to be recognized, performs sample expansion on the above-mentioned candidate sentence samples. The sample expansion here can be understood as further supplementing the candidate samples so that the model can capture and learn the global information of the sentence samples.
[0111] In specific implementation, a sentence sample that matches the candidate sentence sample can be selected from the intention sample library as an extended sentence sample, and then the candidate sentence sample and the extended sentence sample are combined into a sentence sample group. Multiple sentence sample groups constitute a sentence sample set corresponding to the sentence to be identified.
[0112] The recognition unit 530 of the embodiment of the present application is used to concatenate the sentence to be recognized with the sentence sample group to obtain a rewritten sentence, and determine the intent recognition result of the sentence to be recognized based on the intent recognition model and the rewritten sentence.
[0113] After obtaining each sentence sample group, each sentence sample group is spliced or combined with the sentence to be recognized to obtain the spliced or combined rewritten sentence as the input of the intent recognition model. The intent recognition model here can adopt the infrastructure of the BERT model (Bidirectional Encoder Representations from Transformer), which is a language representation model developed by the Google team and has been widely used in the field of natural language processing. The BERT model is designed to pre-train deep bidirectional representations based on the left and right contexts of all layers. Therefore, the pre-trained BERT representation can be fine-tuned with only one additional output layer to create the current optimal model for many tasks (such as question answering and language reasoning) without making a lot of modifications to the task-specific architecture. Of course, those skilled in the art can also choose other types of recognition models according to actual conditions, which are not specifically limited here. Finally, according to the intent recognition model, the intent corresponding to the sentence to be recognized can be output.
[0114] The embodiments of the present application expand samples so that the intent recognition model can focus on more sample information during matching, avoiding false positives and false negatives, thereby making intent recognition more accurate.
[0115] In one embodiment of the present application, the acquisition unit 510 is further used to: determine the text similarity between the sentence to be recognized and each sentence sample in the intention sample library; and determine at least one candidate sentence sample that matches the sentence to be recognized based on the text similarity.
[0116] In one embodiment of the present application, the intent sample library stores the correspondence between sentence samples and intent labels, and the expansion unit 520 is further used to: group the candidate sentence samples according to the intent labels of the candidate sentence samples to obtain at least one candidate sentence sample group; expand the samples of each candidate sentence sample group according to the number of candidate sentence samples in each candidate sentence sample group, and use the expanded candidate sentence sample group as the sentence sample group corresponding to the sentence to be identified.
[0117] In one embodiment of the present application, the expansion unit 520 is also used to: compare the number of candidate samples in each candidate sentence sample group with a first preset threshold; when the number of candidate samples in the candidate sentence sample group is less than the first preset threshold, retrieve the extended sentence samples in the intention sample library that match the intention label of the candidate sentence sample group and have a text similarity with the sentence to be recognized that is lower than a second preset threshold, and obtain the sentence sample group corresponding to the sentence to be recognized based on the candidate sentence sample group and the extended sentence sample.
[0118] In one embodiment of the present application, the device also includes: a determination unit, which is used to determine the candidate sentence samples in the candidate sentence sample group whose text similarity with the sentence to be recognized is greater than a third preset threshold as retained candidate sentence samples when the number of candidate sentence samples in the candidate sentence sample group is greater than the first preset threshold, and obtain the sentence sample group corresponding to the sentence to be recognized based on the retained candidate sentence samples.
[0119] In one embodiment of the present application, the recognition unit 530 is also used to: use a first preset delimiter to splice each statement sample in each statement sample group within the group to obtain a first splicing result; use a second preset delimiter to splice the statement to be recognized with each statement sample group to obtain a second splicing result; combine the first splicing result and the second splicing result and input them into the intention recognition model for recognition to obtain the intention recognition result of the statement to be recognized.
[0120] In one embodiment of the present application, the recognition unit 530 is also used to: use the intention recognition model to determine the probability that the intention of the sentence to be recognized is the same as the intention label of each sentence sample group; and determine the intention recognition result of the sentence to be recognized based on the probability.
[0121] In one embodiment of the present application, the intent recognition model is trained by the following method: obtaining a sentence to be trained and searching in an intent sample library based on the sentence to be trained to obtain a candidate sentence sample that matches the sentence to be trained; selecting a sentence sample that matches the candidate sentence sample from the intent sample library as an extended sentence sample, and determining a sentence sample group corresponding to the sentence to be trained based on the candidate sentence samples and the extended sentence samples; concatenating the sentence to be trained with each sentence sample group and inputting the concatenated sentence sample into the intent recognition model for training to obtain a training loss value corresponding to each sentence sample group, and updating the parameters of the intent recognition model according to the training loss value corresponding to each sentence sample group.
[0122] It should be noted that the specific implementation of the above-mentioned device embodiments can be carried out with reference to the specific implementation of the above-mentioned corresponding method embodiments, which will not be repeated here.
[0123] In summary, the technical solution of the present application obtains a sentence to be recognized and searches the intent sample library according to the sentence to be recognized to obtain a candidate sentence sample that matches the sentence to be recognized; selects a sentence sample that matches the candidate sentence sample from the intent sample library as an extended sentence sample, and determines a sentence sample group corresponding to the sentence to be recognized based on the candidate sentence sample and the extended sentence sample; concatenates the sentence to be recognized with the sentence sample group to obtain a rewritten sentence, and determines the intent recognition result of the sentence to be recognized based on the intent recognition model and the rewritten sentence. The present application expands the samples so that the intent recognition model can pay attention to more information when matching, including sentence sample information of other intents and other sentence sample information of the same intent, etc., so that intent recognition can be more accurate.
[0124] It should be noted that:
[0125] The algorithm and display provided herein are not inherently related to any particular computer, virtual device or other equipment. Various general purpose devices can also be used together with the teachings based on this. According to the above description, it is obvious to construct the structure required for this type of device. In addition, the application is not directed to any specific programming language either. It should be understood that various programming languages can be utilized to realize the content of the application described herein, and the description of the specific language above is for the purpose of disclosing the best mode of the application.
[0126] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present application can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0127] Similarly, it should be understood that in order to streamline the present application and help understand one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present application, the various features of the present application are sometimes grouped together into a single embodiment, figure, or description thereof. However, the disclosed method should not be interpreted as reflecting the following intention: the claimed application requires more features than the features clearly stated in each claim. More specifically, as reflected in the claims below, the inventive aspects are less than all the features of the single embodiment disclosed above. Therefore, the claims following the specific embodiment are hereby expressly incorporated into the specific embodiment, wherein each claim itself serves as a separate embodiment of the present application.
[0128] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0129] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present application and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0130] The various component embodiments of the present application can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) can be used in practice to implement some or all functions of some or all components in the intention recognition device according to the embodiment of the present application. The application can also be implemented as a device or device program (e.g., computer program and computer program product) for executing part or all of the methods described herein. Such a program implementing the present application can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0131] For example, Figure 6 A schematic diagram of the structure of an electronic device according to an embodiment of the present application is shown. The electronic device 600 includes a processor 610 and a memory 620 arranged to store computer executable instructions (computer readable program code). The memory 620 can be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk or a ROM. The memory 620 has a storage space 630 for storing a computer readable program code 631 for executing any method step in the above method. For example, the storage space 630 for storing computer readable program code may include individual computer readable program codes 631 for implementing various steps in the above method respectively. The computer readable program code 631 can be read from or written to one or more computer program products. These computer program products include program code carriers such as a hard disk, a compact disk (CD), a memory card or a floppy disk. Such a computer program product is typically, for example Figure 7 The computer-readable storage medium shown. Figure 7 A schematic diagram of the structure of a computer-readable storage medium according to an embodiment of the present application is shown. The computer-readable storage medium 700 stores a computer-readable program code 631 for executing the method steps according to the present application, which can be read by the processor 610 of the electronic device 600. When the computer-readable program code 631 is executed by the electronic device 600, the electronic device 600 executes each step in the method described above. Specifically, the computer-readable program code 631 stored in the computer-readable storage medium can execute the method shown in any of the above embodiments. The computer-readable program code 631 can be compressed in an appropriate form.
[0132] It should be noted that the above embodiments illustrate the present application rather than limit the present application, and that those skilled in the art may design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets should not be constructed as a limitation to the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of multiple such elements. The present application may be implemented by means of hardware including several different elements and by means of a suitably programmed computer. In a unit claim that lists several devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc. does not indicate any order. These words may be interpreted as names.
Claims
1. A method for intention recognition, characterized in that: include: Acquire a sentence to be recognized and search in an intent sample library according to the sentence to be recognized to obtain a candidate sentence sample matching the sentence to be recognized; Selecting sentence samples matching the candidate sentence samples from the intention sample library as extended sentence samples, and determining a sentence sample group corresponding to the sentence to be recognized based on the candidate sentence samples and the extended sentence samples; splicing the sentence to be recognized and the sentence sample group to obtain a rewritten sentence, and determining an intent recognition result of the sentence to be recognized based on an intent recognition model and the rewritten sentence; The intent sample library stores the correspondence between sentence samples and intent labels, and the sentence samples matching the candidate sentence samples are selected from the intent sample library as extended sentence samples, and the sentence sample group corresponding to the sentence to be recognized is determined according to the candidate sentence samples and the extended sentence samples, including: Grouping the candidate sentence samples according to the intention labels of the candidate sentence samples to obtain at least one candidate sentence sample group; Expanding each candidate sentence sample group according to the number of candidate sentence samples in each candidate sentence sample group, and using the expanded candidate sentence sample group as the sentence sample group corresponding to the sentence to be recognized; The step of expanding each candidate sentence sample group according to the number of candidate sentence samples in each candidate sentence sample group and using the expanded candidate sentence sample group as the sentence sample group corresponding to the sentence to be recognized includes: Comparing the number of candidate examples in each candidate sentence example group with a first preset threshold; When the number of candidate samples in the candidate sentence sample group is less than a first preset threshold, an extended sentence sample that matches the intent label of the candidate sentence sample group and whose text similarity with the sentence to be recognized is lower than a second preset threshold is retrieved from the intent sample library, and a sentence sample group corresponding to the sentence to be recognized is obtained based on the candidate sentence sample group and the extended sentence samples.
2. The method for intention recognition according to claim 1, characterized in that: The step of obtaining a sentence to be recognized and searching in an intention sample library according to the sentence to be recognized to obtain a candidate sentence sample matching the sentence to be recognized includes: Determining the text similarity between the sentence to be recognized and each sentence sample in the intent sample library; At least one candidate sentence sample matching the sentence to be recognized is determined according to the text similarity.
3. The method for identifying intention according to claim 1, characterized in that: The method further comprises: When the number of candidate sentence samples in the candidate sentence sample group is greater than the first preset threshold, the candidate sentence samples in the candidate sentence sample group whose text similarity with the sentence to be recognized is greater than a third preset threshold are determined as retained candidate sentence samples, and a sentence sample group corresponding to the sentence to be recognized is obtained based on the retained candidate sentence samples.
4. The method for identifying intention according to claim 1, characterized in that: The step of concatenating the sentence to be recognized with the sentence sample group to obtain a rewritten sentence, and determining the intention recognition result of the sentence to be recognized according to the intention recognition model and the rewritten sentence includes: Using a first preset separator, each sentence sample in each sentence sample group is spliced within the group to obtain a first splicing result; Using a second preset separator, the sentence to be recognized is concatenated with each sentence sample group to obtain a second concatenation result; The first concatenation result and the second concatenation result are combined and input into the intention recognition model for recognition to obtain the intention recognition result of the sentence to be recognized.
5. The method for intention recognition according to claim 1, characterized in that: The step of determining the intention recognition result of the sentence to be recognized according to the intention recognition model and the rewritten sentence includes: Determine, by using the intent recognition model, the probability that the intent of the sentence to be recognized is the same as the intent label of each sentence sample group; The intention recognition result of the sentence to be recognized is determined according to the probability.
6. The intention recognition method according to any one of claims 1 to 5, characterized in that: The intent recognition model is trained by the following method: Acquire a sentence to be trained and search the intent sample library according to the sentence to be trained to obtain a candidate sentence sample matching the sentence to be trained; Selecting sentence samples matching the candidate sentence samples from the intention sample library as extended sentence samples, and determining a sentence sample group corresponding to the sentence to be trained based on the candidate sentence samples and the extended sentence samples; The sentence to be trained is concatenated with each sentence sample group and then input into the intention recognition model for training to obtain the training loss value corresponding to each sentence sample group, and the parameters of the intention recognition model are updated according to the training loss value corresponding to each sentence sample group.
7. An intention recognition device, characterized in that: include: An acquisition unit, used for acquiring a sentence to be recognized and searching in an intention sample library according to the sentence to be recognized to obtain a candidate sentence sample matching the sentence to be recognized; An expansion unit, configured to select a sentence sample matching the candidate sentence sample from the intention sample library as an expanded sentence sample, and determine a sentence sample group corresponding to the sentence to be recognized based on the candidate sentence sample and the expanded sentence sample; An identification unit, configured to concatenate the sentence to be identified with the sentence sample group to obtain a rewritten sentence, and determine an intent identification result of the sentence to be identified based on an intent identification model and the rewritten sentence; The intent sample library stores the correspondence between sentence samples and intent labels, and the sentence samples matching the candidate sentence samples are selected from the intent sample library as extended sentence samples, and the sentence sample group corresponding to the sentence to be identified is determined according to the candidate sentence samples and the extended sentence samples, including: Grouping the candidate sentence samples according to the intention labels of the candidate sentence samples to obtain at least one candidate sentence sample group; Expanding each candidate sentence sample group according to the number of candidate sentence samples in each candidate sentence sample group, and using the expanded candidate sentence sample group as the sentence sample group corresponding to the sentence to be recognized; The step of expanding each candidate sentence sample group according to the number of candidate sentence samples in each candidate sentence sample group and using the expanded candidate sentence sample group as the sentence sample group corresponding to the sentence to be recognized includes: Comparing the number of candidate examples in each candidate sentence example group with a first preset threshold; When the number of candidate samples in the candidate sentence sample group is less than a first preset threshold, an extended sentence sample that matches the intent label of the candidate sentence sample group and whose text similarity with the sentence to be recognized is lower than a second preset threshold is retrieved from the intent sample library, and a sentence sample group corresponding to the sentence to be recognized is obtained based on the candidate sentence sample group and the extended sentence samples.
8. An electronic device, wherein: The electronic device comprises: a processor; and a memory arranged to store computer executable instructions, wherein when the executable instructions are executed, the processor executes the intention recognition method according to any one of claims 1 to 6.
9. A computer-readable storage medium, wherein: The computer-readable storage medium stores one or more programs, which, when executed by a processor, implement the intention recognition method according to any one of claims 1 to 6.
