Intention recognition method and electronic equipment
By identifying and replacing word segmentation semantic types in the text and using the intent comparison table to calculate similarity, it solves the problem of low efficiency of intent recognition in small samples and low computing power environments, achieves efficient and accurate intent recognition, and improves user experience.
Patent Information
- Application Number
- CN202310318751.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-28
- Publication Date
- 2024-10-01
AI Technical Summary
In a small sample and low computing power environment, electronic devices use deep learning models to complete intent recognition inefficiently and the recognition results are inaccurate.
By obtaining the text input by the user, identifying the semantic type of the word segmentation and replacing it with the preset semantic type label, using the intention comparison table to calculate the text similarity to determine the target intention, reducing the number of second texts in the intention comparison table, and improving the accuracy of intention recognition. Efficiency and accuracy.
It achieves efficient and accurate intent recognition in a small sample and low computing power environment, shortens the inference time, improves user experience, and is real-time and interpretable.
Smart Images

Figure CN118734862A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of intent recognition, and in particular to an intent recognition method and electronic device. Background Art
[0002] Intent recognition refers to identifying the intention of an action. For example, in a question-and-answer conversation, each sentence of the questioner carries a certain intention, and the respondent will answer according to the other party's intention. Intent recognition is widely used in search engines, chatbots and other scenarios. Therefore, when answering a user's question, the electronic device needs to first understand what the user wants to ask based on the text entered by the user, that is, the user's intention, and then give a corresponding answer based on the user's intention.
[0003] At present, deep learning is usually used to achieve intent recognition, that is, the electronic device converts the text input by the user into a feature vector, and uses the feature vector as the input feature vector of the deep learning model. After being processed by the deep learning model, the user's target intent is obtained. However, deep learning models usually require a large number of samples and a long training time to achieve good intent recognition results, and when new intents that do not belong to the samples appear, additional new samples are required to retrain the deep learning model in order to better identify the new intent. This leads to the problem that when the number of samples is small, the quality is low, and the computing power of the electronic device is insufficient, the efficiency of electronic devices in completing intent recognition through deep learning models is poor and the intent recognition results are inaccurate. Summary of the invention
[0004] The present application provides an intent recognition method and electronic device to solve the problem of low efficiency and inaccurate recognition results when electronic devices use deep learning models to complete intent recognition in a small sample and low computing power environment.
[0005] In a first aspect, the present application provides an intent recognition method, the method comprising:
[0006] Get the first text entered by the user;
[0007] For any one of the at least one segmentation included in the first text, identifying the semantic type of the segmentation, and replacing the segmentation with a label of the corresponding semantic type when the semantic type of the segmentation is a preset semantic type;
[0008] If there is a target second text in the intention comparison table whose similarity with the replaced first text meets the conditions, the target intention of the first text is determined according to the intention corresponding to the target second text, wherein the intention comparison table records the correspondence between multiple second texts and multiple intentions.
[0009] Furthermore, before identifying the semantic type of any one of the at least one segmentation contained in the first text, the method further includes:
[0010] Perform data cleaning on the first text.
[0011] Furthermore, before identifying the semantic type of any one of the at least one segmentation contained in the first text, the method further includes:
[0012] According to a preset synonym file, a first word in the first text is replaced with a second word, wherein the synonym file contains multiple words determined according to multiple second texts in the intention comparison table, and the second word is a synonym of the first word in the synonym file.
[0013] Further, determining that there is a target second text in the intention comparison table whose similarity with the replaced first text satisfies a condition includes:
[0014] If there is a second text in the intention comparison table that successfully matches the replaced first file, the successfully matched second text is determined as the target second text.
[0015] Further, determining that there is a target second text in the intention comparison table whose similarity with the replaced first text satisfies a condition includes:
[0016] Calculating the text similarity between the replaced first text and any second text in the intention comparison table;
[0017] If there is at least one second text whose text similarity with the replaced first text is greater than a first threshold, a target second text is determined in the at least one second text.
[0018] Further, determining the target second text in the at least one second text includes:
[0019] Determine the second text with the greatest similarity to the replaced first text as the target second text; or determine the semantic similarity between the at least one second text and the replaced first text based on a semantic similarity model, and determine the second text with the greatest similarity output by the semantic similarity model as the target second text; or search for at least one second input text corresponding to the at least one second text based on the correspondence between the saved second text and the second input text, determine the semantic similarity between any second input text among the at least one second input text and the first text based on the semantic similarity model, and determine the second text corresponding to the second input text with the greatest similarity output by the semantic similarity model as the target second text.
[0020] Furthermore, the method further comprises:
[0021] The replaced first text is added to the intention comparison table, and a corresponding relationship between the replaced first text and the target intention is established.
[0022] Further, the calculating of the text similarity between the replaced first text and the second text in the intention comparison table includes:
[0023]
[0024] Wherein, Score(Q,d) is the text similarity between the replaced first text Q and the second text d in the intent comparison table, N is the number of second texts in the intent comparison table, t is the i-th word in the replaced first text, df i is the number of the second text containing the i-th word segment, k1 is a preset positive parameter, tf td It represents the frequency of the i-th word in the first text after replacement in the second text.
[0025] Furthermore, the method further comprises:
[0026] If there is no target second text in the intention comparison table whose similarity with the replaced first text meets the condition, the intention recognition failure information is output.
[0027] In a second aspect, the present application provides an intention recognition device, the device comprising:
[0028] An acquisition module, used for acquiring a first text input by a user;
[0029] a processing module, configured to identify the semantic type of any one of the at least one segmentation contained in the first text, and replace the segmentation with a label of the corresponding semantic type when the semantic type of the segmentation is a preset semantic type;
[0030] The processing module is also used to determine the target intent of the first text according to the intent corresponding to the target second text if there is a target second text in the intent comparison table whose similarity with the replaced first text meets the conditions, wherein the intent comparison table records the correspondence between multiple second texts and multiple intents.
[0031] Furthermore, before identifying the semantic type of any one of the at least one segmentation included in the first text, the processing module is further configured to:
[0032] Perform data cleaning on the first text.
[0033] Furthermore, before identifying the semantic type of any one of the at least one segmentation included in the first text, the processing module is further configured to:
[0034] According to a preset synonym file, a first word in the first text is replaced with a second word, wherein the synonym file contains multiple words determined according to multiple second texts in the intention comparison table, and the second word is a synonym of the first word in the synonym file.
[0035] Furthermore, when the processing module determines that there is a target second text in the intention comparison table whose similarity with the replaced first text meets the condition, it is specifically used to:
[0036] If there is a second text in the intention comparison table that successfully matches the replaced first file, the successfully matched second text is determined as the target second text.
[0037] Furthermore, when the processing module determines that there is a target second text in the intention comparison table whose similarity with the replaced first text meets the condition, it is specifically used to:
[0038] Calculating the text similarity between the replaced first text and any second text in the intention comparison table;
[0039] If there is at least one second text whose text similarity with the replaced first text is greater than a first threshold, a target second text is determined in the at least one second text.
[0040] Furthermore, when the processing module determines the target second text in the at least one second text, it is specifically configured to:
[0041] Determine the second text with the greatest similarity to the replaced first text as the target second text; or determine the semantic similarity between the at least one second text and the replaced first text based on a semantic similarity model, and determine the second text with the greatest similarity output by the semantic similarity model as the target second text; or search for at least one second input text corresponding to the at least one second text based on the correspondence between the saved second text and the second input text, determine the semantic similarity between any second input text among the at least one second input text and the first text based on the semantic similarity model, and determine the second text corresponding to the second input text with the greatest similarity output by the semantic similarity model as the target second text.
[0042] Furthermore, the processing module is also used for:
[0043] The replaced first text is added to the intention comparison table, and a corresponding relationship between the replaced first text and the target intention is established.
[0044] Further, when the processing module calculates the text similarity between the replaced first text and the second text in the intention comparison table, it is specifically used to:
[0045]
[0046] Wherein, Score(Q,d) is the text similarity between the replaced first text Q and the second text d in the intent comparison table, N is the number of second texts in the intent comparison table, t is the i-th word in the replaced first text, df i is the number of the second text containing the i-th word segment, k1 is a preset positive parameter, tf td It represents the frequency of the i-th word in the first text after replacement in the second text.
[0047] Furthermore, the processing module is also used for:
[0048] If there is no target second text in the intention comparison table whose similarity with the replaced first text meets the condition, the intention recognition failure information is output.
[0049] In a third aspect, the present application provides an electronic device, which includes at least a processor and a memory, and when the processor executes a computer program or instruction stored in the memory, the method of the first aspect is implemented.
[0050] In a fourth aspect, the present application provides a computer-readable storage medium storing a computer program or instructions, which, when executed by a processor, implements the method of the first aspect.
[0051] The present application identifies the semantic type of any one of at least one participle contained in a first text input by a user, and replaces the participle with a label of the corresponding semantic type when the semantic type of the participle is a preset semantic type, thereby reducing the number of second texts in the intent comparison table, and being able to efficiently find a target second text whose similarity with the replaced first text meets the conditions from the intent comparison table, and then determine the target intent of the first text according to the intent corresponding to the target second text, thereby improving the efficiency and accuracy of intent recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0053] Figure 1 A schematic diagram of the process of intent recognition by an existing NLU module provided in this application.
[0054] Figure 2 The present invention provides a flowchart of an intent recognition method.
[0055] Figure 3 This is an example diagram of an intent comparison table provided in this application.
[0056] Figure 4 This is an example diagram of a synonym file provided in this application.
[0057] Figure 5 A flowchart of another possible intent recognition method provided in this application.
[0058] Figure 6 This is a schematic diagram of the structure of an intent recognition device provided in this application.
[0059] Figure 7 This is a schematic diagram of the structure of an electronic device provided in this application. DETAILED DESCRIPTION
[0060] In order to make the purpose and implementation method of the present application clearer, the exemplary implementation method of the present application will be clearly and completely described below in conjunction with the drawings in the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only part of the embodiments of the present application, rather than all the embodiments.
[0061] It should be noted that the brief description of terms in this application is only for the convenience of understanding the embodiments described below, and is not intended to limit the embodiments of this application. Unless otherwise specified, these terms should be understood according to their common and usual meanings.
[0062] The terms "first", "second", "third", etc. in the specification and claims of this application and the above drawings are used to distinguish similar or similar objects or text entities, and do not necessarily mean to limit a specific order or sequence, unless otherwise noted. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances.
[0063] The terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover but not exclude inclusion, for example, a product or device comprising a list of components is not necessarily limited to all the components expressly listed but may include other components not expressly listed or inherent to such product or device.
[0064] The term "module" refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic, or combination of hardware and / or software code that is capable of performing the functions associated with that element.
[0065] Intent recognition refers to identifying the intention of an action. For example, in a question-and-answer conversation, each sentence of the questioner carries a certain intention, and the respondent will answer according to the other party's intention. Intent recognition is widely used in search engines, chatbots and other scenarios. For example, the user inputs: "What is the weather in Shenzhen today?", "What is the weather tomorrow?", "What is the weather in Shenzhen tomorrow?", the intention is: check the weather. Similarly, "Check the flight tickets from Beijing to Shanghai tomorrow", "The flight from Beijing to Shanghai tomorrow", the intention is: check the flight tickets.
[0066] When answering a user's question, the electronic device needs to analyze the user's intention based on the text input by the user. After understanding what the user wants to ask, that is, completing the intention recognition, it will feedback the corresponding answer to the customer. Because people may use many different ways of expressing the same intention in natural language, the current processing method for intent recognition in the industry mostly uses deep learning models for processing, such as the Natural Language Understanding (NLU) module.
[0067] Figure 1 The following is a schematic diagram of the process of intent recognition by an existing NLU module. Figure 1 As shown, the electronic device inputs the text input by the user into the NLU module, and the NLU module directly gives the intent recognition result. Among them, the existing NLU module can include functional parts such as word segmentation, feature extraction, entity extraction, and intent recognition. The word segmentation function of the NLU module is mainly used to segment the text input by the user; the feature extraction function of the NLU module is mainly used to encode the output of the word segmentation function into a digital vector that can be processed by the electronic device, such as sparse vector encoding in the form of one-hot or dense vector encoding obtained by word2vec; the entity extraction function is used to extract keywords in the text; the intent recognition function is used to obtain the digital vector processed by the feature extraction function, and output the intent recognition result based on the digital vector.
[0068] Through the above example of the process of intent recognition of the existing NLU module, it is easy to understand that the deep learning model can determine the target intent that is closest to the meaning of the text input by the user through closed and unpredictable processing and analysis of the text input by the user. It is not easy for engineers to understand and interfere with the processing process of the deep learning model for intent recognition of the text. In addition, if the deep learning model is to achieve a more accurate intent recognition effect, a large number of high-quality intent recognition samples are required to pre-train the deep learning model. However, a large number of high-quality intent recognition samples are difficult to obtain. The cost of manually annotating the initial data to obtain intent recognition samples is high, the annotation cycle is long, and the intent recognition samples are deviated from the actual application scenario. In other words, the intent recognition samples used to train the deep learning model greatly affect the processing effect of the deep learning model for intent recognition. In addition, when in an unused semantic environment or when a new intent appears, additional samples are needed to retrain the deep learning model so that the deep learning model can have a better intent recognition effect in the new semantic environment and new intent category. This results in the problem that the use of deep learning models to process intent recognition on electronic devices with a small number of intent recognition samples, low quality, and low computing power takes a long time and is inaccurate, affecting the user experience. Based on this, the present application provides an intent recognition method and device to efficiently and accurately recognize the user's intent and improve the user experience.
[0069] Figure 2 A flowchart of an intention recognition method provided in an embodiment of the present application, which can be applied to an electronic device, includes:
[0070] S201: Acquire the first text input by the user.
[0071] The electronic device obtains the first text input by the user for intent recognition, wherein the electronic device can be an electronic device with certain computing capabilities such as a server and a computer. In addition, the first text input by the user can be text obtained by converting the user's voice, or can be text directly input by the user into the electronic device.
[0072] S202: For any word among at least one word included in the first text, identify the semantic type of the word, and when the semantic type of the word is a preset semantic type, replace the word with a label of the corresponding semantic type.
[0073] The electronic device can use the Jieba word segmentation algorithm, the maximum matching word segmentation algorithm, the shortest path word segmentation algorithm, etc. to segment the first text. For example, the first text is "How is the weather today?". After being processed by the word segmentation algorithm, each word in the first text is "today", "weather", and "how is it."
[0074] After the electronic device completes the word segmentation processing of the first text, the electronic device can also perform named entity recognition (NER) processing, that is, entity extraction, on each word segment in the first text to identify the semantic type to which each word segment in the first text belongs, and for each word segment in the first text, when the semantic type of the word segment is a preset semantic type, replace the word segment with a label of the corresponding semantic type. Among them, the preset semantic type may include time, place, quantity, name, organization name, currency, percentage, etc. In an embodiment of the present application, replacing the word segment of the preset semantic type with a label of the corresponding semantic type may not affect the intended expression of the first text. It can be understood that the preset semantic type can be set according to the actual business situation, such as different language environments, different usage habits, etc.
[0075] For example, the preset semantic types can be semantic types such as quantity, time, and place. The first text is "How is the weather today", "How is the weather tomorrow", "How is the weather in Shanghai tomorrow", and "How is the weather in Shanghai today", and the intention is: query the weather. Replace the participles "today" and "tomorrow" with the semantic type of time with the label "date", and replace the participle "Shanghai" with the semantic type of place with the label "area". After replacement, the first text is "How is the weather on date", "How is the weather on date", "How is the weather on date area", and "How is the weather on date area" respectively, and the intention is still: query the weather.
[0076] S203: If there is a target second text in the intention comparison table whose similarity with the replaced first text meets the conditions, the target intention of the first text is determined according to the intention corresponding to the target second text, wherein the intention comparison table records the correspondence between multiple second texts and multiple intentions.
[0077] The target second text whose similarity with the replaced first text meets the condition is the second text that successfully matches the replaced first text, or the second text whose semantic similarity with the replaced first text is greater than a preset threshold.
[0078] Specifically, taking the example that the similarity between the target second text and the replaced first text satisfies the condition that the target second text and the replaced first text are successfully matched, a method is provided for an electronic device to determine whether there is a target second text in the intent comparison table whose similarity with the replaced first text satisfies the condition. After the electronic device replaces the word segmentation in the first text with a label of the corresponding language type, it can retrieve the second text that matches the replaced first text in the intent comparison table through text matching methods such as regular expressions. If there is a second text that successfully matches the replaced first text in the intent comparison table, the second text that successfully matches the replaced first text is used as the target second text, and the intent corresponding to the target second text is used as the target intent of the first text. In addition, it has been experimentally confirmed that existing reasoning schemes based on deep learning models, such as Figure 1 The average inference time of the NLU module in the example is between 75ms and 150ms. The method of searching for a second text matching the replaced first text as the target second text according to the intent comparison table in the embodiment of the present application can significantly shorten the inference time and control the inference time within 30ms.
[0079] In addition, the intent comparison table records the correspondence between multiple second texts and multiple intents, each intent corresponds to at least one second text, and for each second text, the word segmentations belonging to the preset semantic type in the second text are also replaced by labels of the corresponding semantic type.
[0080] Taking the intent of querying the weather as an example, this paper explains how to efficiently determine the target intent of the first text based on the intent comparison table. Figure 3 This is an example diagram of an intention comparison table provided in an embodiment of the present application. Figure 3 As shown, the intent may include: querying the weather, etc. When the intent is to query the weather, the corresponding second text includes: "How is the weather on date", "How is the weather in area", "How is the weather on area date", "How is the weather on date area", "How many degrees is the date area", etc. When the first text input by the user is "How is the weather in Shanghai tomorrow", "How is the weather in Shenzhen the day after tomorrow", "How is the weather in Beijing on March 1st", the electronic device replaces the word segmentations of the preset semantic type in the first text with labels of the corresponding semantic type. The replaced first texts are all "How is the weather in date area". Therefore, only a small amount of second texts can be recorded in the intent comparison table to enable the electronic device to retrieve the target second text whose similarity with the replaced first text meets the conditions, and use the intent corresponding to the target second text recorded in the intent comparison table as the target intent of the first text, so as to improve the efficiency of intent recognition.
[0081] In addition, if there are no word segments belonging to the preset semantic types in the first text input by the user, the electronic device can determine the target intent of the first text through existing intent recognition methods.
[0082] Optionally, the second text in the intent comparison table can be pre-loaded into the cache to further improve the efficiency of intent recognition. And the intent comparison table can be periodically updated according to the actual business processing results to further improve the accuracy of intent recognition and the ability of intent recognition.
[0083] In the embodiment of the present application, for each word segment in the first text input by the user, the semantic type of the word segment is recognized, and when the semantic type of the word segment is the preset semantic type, the word segment is replaced with a label corresponding to the semantic type, reducing the number of second texts in the intent comparison table, and enabling the target second text whose similarity to the replaced first text meets the condition to be efficiently found from the intent comparison table, and then the target intent of the first text is determined according to the intent corresponding to the target second text, improving the efficiency and accuracy of intent recognition. The intent recognition method protected by the present application has the characteristics of real-time and interpretability, meeting the trustworthy characteristics.
[0084] Further, on the basis of the above embodiment, in order to improve the efficiency of intent recognition, before recognizing the semantic type of each word segment in the first text, the method further includes:
[0085] Perform data cleaning on the first text.
[0086] Since there may be some modal particles, onomatopoeias, etc. in natural language expressions that do not affect the expression of the text intent, removing these words that do not affect the expression of the text intent from the first text can further reduce the number of second texts in the intent comparison table, and then enable the electronic device to more quickly retrieve the target second text whose similarity to the replaced first text meets the condition from the intent comparison table, thereby further improving the efficiency and accuracy of intent recognition. Specifically, according to the preset modal particle file, the modal particles, onomatopoeias, etc. that do not affect the target intent of the text and do not affect the expression of the text intent can be removed from the first text, and the preset modal particle file records the words that do not affect the expression of the text intent, such as modal particles, onomatopoeias, etc. For another example, the preset modal particle file may include words similar to "ya", "a", "he", "咱", "能不能", "给我", "哎呦", etc. that do not affect the expression of the text intent. Among them, the preset modal particle file can be set and updated according to the actual business situation. It should be noted that not all modal particles need to be removed from the first text. For example, "ma" in "Is the weather good today?" may affect the expression of the text intent, so "ma" will not be set in the modal particle file.
[0087] Furthermore, in order to improve the efficiency of intent recognition, for each word segment in the first text, before identifying the semantic type of the word segment, the electronic device can also replace the first word in the first text with a second word according to a preset synonym file, wherein the synonym file records multiple groups of words with the same meaning, and replacement between words in the same group does not change the intention expression of the first text. Specifically, the second word included in the synonym file is determined based on multiple second texts in the intent comparison table, and for each second word in the synonym file, at least one first word with the same meaning as the second word is recorded.
[0088] For example, Figure 4 This is an example diagram of a synonym file provided in an embodiment of the present application. Figure 4 As shown, the first word corresponding to the second word "rain" may include "showers", "light rain", "heavy rain", "rainstorm", etc., the first word corresponding to the second word "snow" may include "light snow", "heavy snow", "blizzard", etc., and the first word corresponding to the second word "how" may include "what", "what", "how", etc. As shown above, the synonym file may include many groups of corresponding synonyms, wherein the second words are all determined according to the second text in the intent comparison table. For example, when the first text is "what is the weather like today", "what is the weather like today", "how is the weather today", and other similar descriptions, the synonym file can be used to replace "what", "what", "how", and "how" in the first text with "how", so that the first text after the synonym replacement process can be successfully matched with the second text "how is the weather on date" in the intent comparison table, further reducing the number of second texts in the intent comparison table, thereby improving the efficiency of intent recognition. Similarly, the synonym file can also be set and updated according to actual business.
[0089] Based on the above embodiments, the electronic device may determine that there is a target second text in the intent comparison table whose similarity with the replaced first text meets the condition, which may include:
[0090] Calculating the text similarity between the replaced first text and any second text in the intention comparison table;
[0091] If there is at least one second text whose text similarity with the replaced first text is greater than a first threshold, a target second text is determined in the at least one second text.
[0092] In addition, in the embodiment of the present application, when determining whether there is a target second text whose similarity with the replaced first text meets the condition, it can also be determined based on the text similarity between the replaced first text and each second text in the intention comparison table.
[0093] In addition, in order to improve the efficiency of intent recognition, since the segmentations in the replaced first text and the second text recorded in the intent comparison table are replaced with labels of corresponding semantic types, the electronic device can quickly determine the second text that successfully matches the replaced first text in the intent comparison table by text matching, and then use the second text that successfully matches the replaced first text as the target second text. Therefore, the electronic device can first use a text matching method such as a regular expression to search in the intent comparison table whether there is a second text that successfully matches the replaced first text. If there is a second text that successfully matches the replaced first text in the intent comparison table, the second text that successfully matches the replaced first text is directly used as the target second text, in order to determine the target second text more quickly, and then complete the intent recognition according to the target second text; if there is no second text that successfully matches the replaced first text in the intent comparison table, the electronic device can determine the target second text by calculating the text similarity between the replaced first text and each second text in the intent comparison table, so that the electronic device can better complete the intent recognition task. Moreover, since the intent comparison table can be updated with the continuous iteration of the business, the method of retrieving the target second text that successfully matches the replaced first text according to the intent comparison table and then completing the intent recognition can complete 80% or even more intent recognition results. Only a small number of intent recognition results need to determine the target second text by calculating the similarity, thereby controlling the inference time of intent recognition to between 25ms-75ms. Therefore, the inference time of intent recognition in the embodiment of the present application has a smaller delay, which improves the efficiency of intent recognition.
[0094] Specifically, the electronic device may first use a text similarity algorithm to roughly calculate the text similarity between the replaced first text and each second text in the intent comparison table. If there is at least one second text whose text similarity to the replaced first text is greater than a first threshold, then in the at least one second text whose text similarity to the replaced first text is greater than the first threshold, the target second text is determined according to the text similarity between the at least one second text and the replaced first text. For example, any one of the several second texts with greater similarity in the at least one second text may be selected as the target second text.
[0095] Optionally, if after calculation by the text similarity algorithm there is no second text whose text similarity with the replaced first text is greater than a first threshold, the electronic device directly outputs intention recognition failure information, such as the intention of the text has not been included yet, so that the electronic device can quickly give a conclusion on intention recognition.
[0096] The text similarity algorithm may be a term frequency-inverse document frequency (TD-IDF) algorithm, a 25th generation best matching (BM25) algorithm, etc. The semantic similarity model may be trained by similar text samples and used to calculate the similarity between the first text input into the semantic similarity model and each second text.
[0097] Taking the BM25 algorithm as an example, the present application embodiment provides a possible calculation formula for the text similarity algorithm, which is as follows:
[0098]
[0099] Where Q is the query representing the first text after replacement, d represents the second text, Score(Q,d) is the similarity between the first text after replacement and the second text, W i is the weight of the i-th word in the first text after replacement, q i represents the i-th word of the first text after replacement, R(q i ,d) represents the relevance score between the i-th word in the first text and the second text after replacement, R(q i , Q) represents the relevance score of the i-th word segment in the replaced first text with the replaced first text, and n is the total number of word segments in the replaced first text.
[0100] Optionally, the word segmentation weight W i The calculation formula is as follows:
[0101]
[0102] Among them, IDF(q i ) is W i , N is the number of second texts in the intent comparison table, df i is the number of second texts containing the i-th word segment.
[0103] Optionally, the calculation formula of the relevance score R(qi,d) between the i-th word in the replaced first text and the second text is as follows:
[0104]
[0105]
[0106] Among them, R(q i,d) is the correlation score between the i-th word in the first text after replacement and the second text, k1 is a preset positive parameter, for example, k1 takes a value between 1.2 and 2, tf td represents the frequency of the i-th word in the first text after word t is replaced in the second text, L d is the length of the second text, L ave is the average length of all second texts, b is another adjustable positive parameter ranging from 0 to 1, and b is 0 in this application.
[0107] Optionally, the relevance score R(q i ,Q) is calculated as follows:
[0108]
[0109] Among them, R(q i , Q) is the correlation score between the i-th word in the first text after replacement and the first text after replacement, k3 is another preset positive parameter, tf tq Represents the word frequency of word t, i.e., the i-th participle in the first text after replacement.
[0110] Since the replaced first text and the second text in the embodiment of the present application have been processed by data cleaning, that is, removing modal particles, onomatopoeia, etc., and undergoing synonym replacement processing, and replacing the segmentation words belonging to the preset semantic type with the labels of the corresponding semantic type, the lengths of the replaced first text and the second text have changed, b in formula (4) is set to 0, and S(q i , Q) is set to 1, and then formula (2), formula (3), formula (4), and formula (5) are substituted into formula (1). Finally, the BM25 algorithm formula applicable to this solution is obtained as follows:
[0111]
[0112] Further, based on the above embodiments, determining the target second text in the at least one second text includes:
[0113] Determine a second text having the greatest similarity to the replaced first text as a target second text;
[0114] or determining the semantic similarity between the at least one second text and the replaced first text according to a semantic similarity model, and determining the second text with the greatest similarity output by the semantic similarity model as the target second text;
[0115] Or according to the correspondence between the saved second text and the second input text, search for at least one second input text corresponding to the at least one second text, determine the semantic similarity between any second input text of the at least one second input text and the first text according to the semantic similarity model, and determine the second text corresponding to the second input text with the greatest similarity output by the semantic similarity model as the target second text.
[0116] Specifically, the electronic device can calculate the text similarity between the replaced first text and each second text according to formula (6), and use the second text with the greatest text similarity to the replaced first text as the target second text, and then determine the target intent of the first text according to the intent corresponding to the target second text.
[0117] In order to further improve the semantic accuracy between the determined target second text and the replaced first text, and ensure the processing effect of intent recognition. In an embodiment of the present application, the electronic device can determine the second text with the greatest semantic similarity to the replaced first text according to the semantic similarity model, and use the second text with the greatest semantic similarity to the replaced first text as the target second text, so that the determined target second text is closer to the semantics of the replaced first text, and the intention corresponding to the target second text can more accurately express the target intention of the first text. Specifically, after the electronic device determines at least one second text whose text similarity to the replaced first text is greater than the first threshold through a text similarity algorithm, the electronic device calculates the semantic similarity of each second text in the at least one second text with the replaced first text according to the semantic similarity model, and uses the second text with the greatest semantic similarity to the replaced first text as the target second text.
[0118] Optionally, in addition to determining the second text with the greatest semantic similarity to the replaced first text as the target second text according to the semantic similarity model, the electronic device can also determine the semantic similarity between the first text input by the user and each second input text according to the semantic similarity model, and determine the second text corresponding to the second input text with the greatest semantic similarity to the first text input by the user as the target second text. Since the replaced first text has been processed by data cleaning, synonym replacement, and replacement of word segmentation of a preset semantic type with a label of a corresponding semantic type, the replaced first text may lack some text information compared to the first text input by the user, affecting the determination of the target second text by the semantic similarity model, while the text input by the user does not lose any information, and the second input text that is closer to the semantics of the first text input by the user can be better determined according to the semantic similarity model, and then the target second text that is closer to the semantics of the first text input by the user is determined according to the correspondence between the second input text and the second text.
[0119] Specifically, the electronic device may store the correspondence between the second text and the second input text. According to the correspondence between the second text and the second input text, each second input text corresponding to at least one second text having a text similarity greater than a first threshold value with the replaced first text may be found. The electronic device then determines the semantic similarity between each of the above second input texts and the first text input by the user according to the semantic similarity model, and determines the second text corresponding to the second input text having the greatest semantic similarity with the first text input by the user as the target second text. Each second text corresponds to at least one second input text, each second input text uniquely corresponds to one second text, and each second input text becomes the second text corresponding to the second input text after data cleaning, synonym replacement, and replacement of word segmentation of a preset semantic type with a label of a corresponding semantic type.
[0120] Among them, the electronic device needs to be pre-trained before determining the second text with the greatest similarity to the replaced first text according to the semantic similarity model. Taking the example of an electronic device training a semantic similarity model through a set number of similar text samples, the electronic device can input the third text sample and the fourth text sample in the similar text samples into the two input layers of the semantic similarity model, and there is usually an initialization process before the third text sample and the fourth text sample are input into the semantic similarity model for the first time, that is, the configuration parameters of each layer of the neural network corresponding to the semantic similarity model, such as random configuration parameters, etc., after obtaining the semantic similarity between the third text sample and the fourth text sample output by the semantic similarity model, the difference between the semantic similarity between the third text sample and the fourth text sample output by the semantic similarity model and its preset target semantic similarity can be calculated through the loss function. The higher the output value (loss) of the loss function, the greater the difference, so the training process of the semantic similarity model becomes a process of minimizing this loss as much as possible.
[0121] Specifically, the parameters of each neural network layer of the semantic similarity model are updated according to the output value of the loss function. For example, the parameters of each neural network layer of the semantic similarity model are updated using a gradient descent learning algorithm. The parameters are continuously adjusted until the semantic similarity between the third text sample and the fourth text sample output by the semantic similarity model matches its preset target semantic similarity, thereby completing the training of the semantic similarity model.
[0122] In addition, the semantic similarity model can refer to the structure of the Bidirectional Encoder Representation from Transformers (BERT) model for text feature extraction. The third text sample and the fourth text sample used to train the semantic similarity model may not be processed by data cleaning, synonym replacement, or replacing the word segmentation of the preset semantic type with the label of the corresponding semantic type.
[0123] Furthermore, the method further comprises:
[0124] The replaced first text is added to the intention comparison table, and a corresponding relationship between the replaced first text and the target intention is established.
[0125] After the electronic device determines the target second text according to the semantic similarity model or the text similarity algorithm, the electronic device can directly add the replaced first text to the intent comparison table and establish a correspondence between the replaced first text and the target intent, or save the replaced first text and the correspondence between the replaced first text and the target intent, and after a period of time or a certain number of replaced first texts have been saved, update the saved replaced first text and the correspondence between the replaced first text and the target intent to the intent comparison table. By continuously updating the intent comparison table, the electronic device can complete more intent recognition services by only retrieving the target second text that successfully matches the replaced first text according to the intent comparison table, further improving the efficiency and capability of intent recognition.
[0126] Figure 5 Another possible intent recognition method flow chart is provided for this application. Figure 5 As shown:
[0127] S501: Acquire the first text input by the user.
[0128] The electronic device obtains the first text input by the user, or obtains the voice recorded by the user and converts it into the corresponding first text.
[0129] S502: Data cleaning.
[0130] The electronic device removes the words that do not affect the expression of the text intention, such as the modal particles, onomatopoeia, auxiliary words, and stop words, from the first text according to the preset modal particle file. The electronic device then replaces the first word in the first text with the second word according to the preset synonym file, wherein the second word is a synonym of the first word, and the second word can be determined by the second text in the intention comparison table.
[0131] S503: Entity extraction.
[0132] After the electronic device uses the Jieba word segmentation algorithm to process the first text, it identifies the semantic type of each word segmentation, and when a word segmentation belongs to a preset semantic type, it replaces the word segmentation with a label of the corresponding semantic type to complete the entity extraction process of the first text. The word segmentations of the preset semantic type in each second text in the intent comparison table are also replaced with labels of the corresponding semantic type, which further reduces the number of second texts recorded in the intent comparison table, thereby improving the efficiency of intent recognition.
[0133] S504: Rule matching.
[0134] The electronic device can retrieve the target second text that successfully matches the replaced first text in the intent comparison table through text matching methods such as regular expressions, and determine the target intent of the first text based on the intent corresponding to the target second text.
[0135] If there is no target second text in the intent comparison table that successfully matches the replaced first text, then proceed to S505. The content in the intent comparison table can be preloaded into the cache of the electronic device to further improve the efficiency of intent recognition.
[0136] S505: Calculate text similarity according to the BM25 algorithm.
[0137] When there is no target second text that successfully matches the replaced first text in the intention comparison table, the electronic device calculates the text similarity between the replaced first text and each second text according to the BM25 algorithm.
[0138] When there is at least one second text whose text similarity with the replaced first text is greater than the first threshold, step S506 is performed.
[0139] When there is no second text having a text similarity with the replaced first text greater than the first threshold, proceed to S507.
[0140] S506: Determine the target second text according to the semantic similarity model, and determine the target intent of the first text according to the intent corresponding to the target second text.
[0141] When determining the target intent, for each second text in at least one second text whose text similarity with the replaced first text is greater than a first threshold, the electronic device can calculate the semantic similarity of each second text with the replaced first text based on a semantic similarity model, and use the second text with the greatest semantic similarity with the replaced first text as the target second text, and then determine the target intent of the first text based on the intent corresponding to the target second text.
[0142] When determining the target intent, the electronic device can also search for each second input text corresponding to at least one second text whose text similarity with the replaced first text is greater than a first threshold based on the correspondence between the saved second text and the second input text, and determine the semantic similarity between each second input text and the first text input by the user based on a semantic similarity model, and take the second text corresponding to the second input text with the greatest semantic similarity to the first text input by the user as the target second text, and then determine the target intent of the first text based on the intent corresponding to the target second text.
[0143] In addition, after the electronic device determines the target intent of the first text based on the intent corresponding to the target second text, it can save the replaced first text and the correspondence between the first text and the target intent, and update the saved replaced first text and the correspondence between the first text and the target intent into the intent comparison table.
[0144] S507: Output the information that the intention recognition failed.
[0145] The electronic device directly outputs information about the failure of intent recognition, such as "The intent of this text has not been recorded yet", "The intent of this text has not been collected yet", "×× cannot understand this sentence for the time being, please try to input it again", etc. Similarly, the electronic device can still save the first text input by the user and the information record of the failure of outputting intent recognition for updating the intent comparison table, synonym file, modal particle file, etc., so that as the business processing volume accumulates, the ability of the electronic device to perform intent recognition through rule matching is further improved.
[0146] Finally, it has been confirmed through experiments that the average intention recognition reasoning time of the reasoning scheme based on the deep learning model, such as intent recognition through the NLU module, is between 75ms and 150ms. The intention recognition reasoning time based on rule matching is only within 30ms. Furthermore, since the intention comparison table in this application can be continuously iterated and updated as the business is processed, more than 80% or even more of the intention recognition results come from the rule matching method, and the intention recognition business that cannot be completed by rule matching can be completed by calculating the semantic similarity through the semantic similarity model, and the content of the intention comparison table is further improved according to the intention recognition results of the semantic similarity. Therefore, in this scheme, intent recognition is performed mainly by rule matching and supplemented by the semantic similarity model, which has a smaller delay. At the same time, the intention recognition method based on rule matching is more transparent and has stronger interpretability than the intention recognition method of the deep learning model, and it is easier to locate and correct errors when encountering related errors.
[0147] Based on the above intention recognition method, the embodiment of the present application provides an intention recognition device, Figure 6A schematic diagram of the structure of an intention recognition device provided in an embodiment of the present application, the device comprising:
[0148] An acquisition module 601 is used to acquire a first text input by a user;
[0149] A processing module 602 is used to identify the semantic type of any one of the at least one segmentation contained in the first text, and replace the segmentation with a label of the corresponding semantic type when the semantic type of the segmentation is a preset semantic type;
[0150] The processing module 602 is also used to determine the target intent of the first text according to the intent corresponding to the target second text if there is a target second text in the intent comparison table whose similarity with the replaced first text meets the conditions, wherein the intent comparison table records the correspondence between multiple second texts and multiple intents.
[0151] Furthermore, before identifying the semantic type of any of the at least one segmentation included in the first text, the processing module 602 is further configured to:
[0152] Perform data cleaning on the first text.
[0153] Furthermore, before identifying the semantic type of any of the at least one segmentation included in the first text, the processing module 602 is further configured to:
[0154] According to a preset synonym file, a first word in the first text is replaced with a second word, wherein the synonym file contains multiple words determined according to multiple second texts in the intention comparison table, and the second word is a synonym of the first word in the synonym file.
[0155] Furthermore, when the processing module 602 determines that there is a target second text in the intention comparison table whose similarity with the replaced first text meets the condition, it is specifically used to:
[0156] If there is a second text in the intention comparison table that successfully matches the replaced first file, the successfully matched second text is determined as the target second text.
[0157] Furthermore, when the processing module 602 determines that there is a target second text in the intention comparison table whose similarity with the replaced first text meets the condition, it is specifically used to:
[0158] Calculating the text similarity between the replaced first text and any second text in the intention comparison table;
[0159] If there is at least one second text whose text similarity with the replaced first text is greater than a first threshold, a target second text is determined based on the similarity between the at least one second text and the replaced first text.
[0160] Further, when the processing module 602 determines the target second text in the at least one second text, it is specifically configured to:
[0161] Determine the second text with the greatest similarity to the replaced first text as the target second text; or determine the semantic similarity between the at least one second text and the replaced first text according to a semantic similarity model, and determine the second text with the greatest similarity output by the semantic similarity model as the target second text; or search for at least one second input text corresponding to the at least one second text according to the correspondence between the saved second text and the second input text, determine the semantic similarity between any second input text of the at least one second input text and the first text according to the semantic similarity model, and determine the second text corresponding to the second input text with the greatest similarity output by the semantic similarity model as the target second text.
[0162] Furthermore, the processing module 602 is also used for:
[0163] The replaced first text is added to the intention comparison table, and a corresponding relationship between the replaced first text and the target intention is established.
[0164] Furthermore, when the processing module 602 calculates the text similarity between the replaced first text and the second text in the intention comparison table, it is specifically used to:
[0165]
[0166] Wherein, Score(Q,d) is the text similarity between the replaced first text Q and the second text d in the intent comparison table, N is the number of second texts in the intent comparison table, t is the i-th word in the replaced first text, df i is the number of the second text containing the i-th word segment, k1 is a preset positive parameter, tf td It represents the frequency of the i-th word in the first text after replacement in the second text.
[0167] Furthermore, the processing module 602 is also used for:
[0168] If there is no target second text in the intention comparison table whose similarity with the replaced first text meets the condition, the intention recognition failure information is output.
[0169] Figure 7Figure 1 is a schematic diagram of the structure of an electronic device. Figure 7 As shown, the electronic device includes: a processor 701 , a communication interface 702 , a memory 703 and a communication bus 704 , wherein the processor 701 , the communication interface 702 , and the memory 703 communicate with each other via the communication bus 704 .
[0170] The memory 703 stores a computer program, and when the program is executed by the processor 701, the processor 701 implements the steps of any one of the above-mentioned intention recognition methods.
[0171] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0172] The communication interface 702 is used for communication between the electronic device and other devices.
[0173] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0174] The above-mentioned processor can be a general-purpose processor, including a central processing unit, a network processor (Network Processor, NP), etc.; it can also be a digital signal processing processor (Digital Signal Processing, DSP), an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, etc.
[0175] Based on the above embodiments, an embodiment of the present application also provides a computer-readable storage medium, which stores a computer program that can be executed by an electronic device. When the program runs on the electronic device, the electronic device implements the steps of any of the above-mentioned intent recognition methods when executed.
[0176] The above-mentioned computer-readable storage medium can be any available medium or data storage device that can be accessed by the processor in the electronic device, including but not limited to magnetic storage such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc., optical storage such as CD, DVD, BD, HVD, etc., and semiconductor storage such as ROM, EPROM, EEPROM, non-volatile memory (NANDFLASH), solid-state drive (SSD), etc.
[0177] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
[0178] For the convenience of explanation, the above description has been made in conjunction with specific embodiments. However, the above exemplary discussion is not intended to be exhaustive or limit the embodiments to the specific forms disclosed above. Based on the above teachings, various modifications and variations can be obtained. The selection and description of the above embodiments are to better explain the principles and practical applications, so that those skilled in the art can better use the embodiments and various different variations of the embodiments suitable for specific use considerations.
[0179] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0180] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0181] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0182] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0183] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0184] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A method for intention recognition, characterized in that: The method comprises: Get the first text entered by the user; For any one of the at least one segmentation included in the first text, identifying the semantic type of the segmentation, and when the semantic type of the segmentation is a preset semantic type, replacing the segmentation with a label of the corresponding semantic type; If there is a target second text in the intention comparison table whose similarity with the replaced first text meets the conditions, the target intention of the first text is determined according to the intention corresponding to the target second text, wherein the intention comparison table records the correspondence between multiple second texts and multiple intentions.
2. The method according to claim 1, characterized in that Before identifying the semantic type of any one of the at least one segmentation included in the first text, the method further includes: Perform data cleaning on the first text.
3. The method according to claim 1 or 2, characterized in that Before identifying the semantic type of any one of the at least one segmentation included in the first text, the method further includes: According to a preset synonym file, a first word in the first text is replaced with a second word, wherein the synonym file contains multiple words determined according to multiple second texts in the intention comparison table, and the second word is a synonym of the first word in the synonym file.
4. The method according to claim 1, characterized in that Determining that there is a target second text in the intent comparison table whose similarity with the replaced first text satisfies the condition includes: If there is a second text in the intention comparison table that successfully matches the replaced first file, the successfully matched second text is determined as the target second text.
5. The method according to claim 1 or 4, characterized in that Determining that there is a target second text in the intent comparison table whose similarity with the replaced first text satisfies the condition includes: Calculating the text similarity between the replaced first text and any second text in the intention comparison table; If there is at least one second text whose text similarity with the replaced first text is greater than a first threshold, a target second text is determined in the at least one second text.
6. The method according to claim 5, characterized in that Determining the target second text in the at least one second text comprises: Determine the second text having the greatest similarity to the replaced first text as the target second text; or Determine the semantic similarity between the at least one second text and the replaced first text according to a semantic similarity model, and determine the second text with the greatest similarity output by the semantic similarity model as the target second text; or According to the correspondence between the saved second text and the second input text, at least one second input text corresponding to the at least one second text is searched, and according to the semantic similarity model, the semantic similarity between any second input text of the at least one second input text and the first text is determined, and the second text corresponding to the second input text with the greatest similarity output by the semantic similarity model is determined as the target second text.
7. The method according to claim 1 or 6, characterized in that The method further comprises: The replaced first text is added to the intention comparison table, and a corresponding relationship between the replaced first text and the target intention is established.
8. The method according to claim 5, characterized in that The calculating of the text similarity between the replaced first text and the second text in the intention comparison table comprises: Wherein, Score(Q,d) is the text similarity between the replaced first text Q and the second text d in the intent comparison table, N is the number of second texts in the intent comparison table, t is the i-th word in the replaced first text, df i is the number of the second text containing the i-th word segment, k1 is a preset positive parameter, tf td It represents the frequency of the i-th word in the first text after replacement in the second text.
9. The method according to claim 1, characterized in that The method further comprises: If there is no target second text in the intention comparison table whose similarity with the replaced first text meets the condition, the intention recognition failure information is output.
10. An electronic device, characterized in that: The electronic device comprises at least a processor and a memory, and when the processor executes a computer program or instruction stored in the memory, the method as described in any one of claims 1 to 9 is implemented.
