Disclosure of Invention
In order to solve the above problems, the present application provides a method and a system for identifying a user intention.
In one aspect, the present application provides a user intention identification method, including:
constructing a directed graph according to the corpus;
segmenting the sentence to be recognized to obtain a plurality of participles to be recognized;
and searching corresponding intentions in the directed graph according to the multiple to-be-recognized participles.
Preferably, the searching for the corresponding intention in the directed graph according to the plurality of to-be-recognized participles includes:
determining corresponding question sentence participles in the directed graph according to the sequence of the participles to be recognized in the sentences to be recognized;
and determining the intention of the sentence to be recognized according to the corresponding intention of the question word.
Preferably, the determining the intention of the sentence to be recognized according to the intention corresponding to the sentence segmentation includes:
if the last word to be recognized in the sentence to be recognized has a corresponding question word in the digraph, the intention corresponding to the question word is the intention of the sentence to be recognized;
if the currently searched word to be recognized is not the last word to be recognized in the sentence to be recognized, and the currently searched word to be recognized does not have a corresponding question word in the directed graph, searching a corresponding question word in the directed graph of the next word to be recognized of the currently searched word to be recognized;
if the currently searched word to be recognized is not the last word to be recognized in the sentence to be recognized, and all the word to be recognized at the back position after the currently searched word to be recognized has no corresponding question word in the digraph, determining the intention of the sentence to be recognized according to the intention corresponding to the word to be recognized at the front position of the currently searched word to be recognized;
and if the currently searched word to be recognized is the last word to be recognized in the sentence to be recognized, which has a corresponding question word in the directed graph, and the question word is connected with a plurality of intentions through other question words, determining the intention of the sentence to be recognized according to the weight of the directed edge.
Preferably, the determining the intention of the sentence to be recognized according to the intention corresponding to the preceding word to be recognized of the currently searched word to be recognized includes:
if the intention of the corresponding question word segmentation of the preceding word to be recognized in the digraph and the number of the directed edges between the question word segmentation are less than or equal to the threshold value of the number of the edges, the intention of the question word segmentation is the intention of the sentence to be recognized;
and if the intentions of the question participles corresponding to the preceding to-be-identified participles in the directed graph and the quantity of the directed edges between the question participles are greater than the threshold value of the number of the edges, the intentions of the to-be-identified sentences cannot be identified.
Preferably, the constructing a directed graph according to the corpus includes:
marking the intentions of all question texts in the corpus;
segmenting the marked question texts to obtain a plurality of question segmentations corresponding to each question text;
and constructing a directed graph according to the intentions of all question texts and a plurality of question clauses corresponding to the intentions of the document texts.
Preferably, the constructing a directed graph according to the intentions of all question sentence texts and a plurality of question sentence participles corresponding to the intentions of the document text includes:
using directed edges to connect the question and sentence participles pairwise in sequence according to the sequence of the question and sentence participles in the sentence text;
connecting the last question word in each question text with the intention of the question text;
determining the weight of a directed edge connecting two question clauses according to the co-occurrence frequency of the two question clauses in the question text;
and deleting the directed edges with the weights smaller than the weight threshold value to obtain a directed graph comprising the question clauses, the intentions, the directed edges and the weights.
Preferably, the segmenting the sentence to be recognized to obtain a plurality of participles to be recognized includes:
performing word segmentation on a sentence to be recognized to obtain a plurality of words;
and deleting stop words in the vocabulary to obtain a plurality of segmented words to be recognized.
Preferably, before the segmenting the sentence to be recognized and obtaining a plurality of segmented words to be recognized, the method further includes:
and translating the voice to be recognized to obtain the sentence to be recognized.
Preferably, the question clauses are connected with another question clause or with the question clause itself through a directed edge.
In a second aspect, the present application provides a user intention recognition system, including:
the directed graph module is used for constructing a directed graph according to the corpus;
and the recognition module is used for segmenting the sentence to be recognized to obtain a plurality of participles to be recognized, and searching corresponding intentions in the directed graph according to the plurality of participles to be recognized.
The application has the advantages that: a directed graph is constructed through a corpus, so that the fault tolerance is strong, and the offline model does not need to be trained by spending a large amount of time and calculation power; and searching the corresponding intention in the directed graph according to the multiple to-be-recognized word segmentations, so that the efficiency is high and the fault tolerance is strong.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
According to an embodiment of the present application, a method for identifying a user intention is provided, as shown in fig. 1, including: the method comprises the following steps:
s101, constructing a directed graph according to the corpus;
s102, segmenting the sentence to be recognized to obtain a plurality of participles to be recognized;
s103, searching corresponding intentions in the directed graph according to the multiple participles to be recognized.
Searching a corresponding intention in a directed graph according to a plurality of to-be-recognized word segmentations, wherein the method comprises the following steps:
determining corresponding question and sentence participles in the directed graph according to the sequence of the participles to be recognized in the sentence to be recognized;
and determining the intention of the sentence to be recognized according to the corresponding intention of the question word.
Determining the intention of the sentence to be recognized according to the intention corresponding to the question word, which comprises the following steps:
if the last word to be recognized in the sentence to be recognized has a corresponding question word in the digraph, the intention corresponding to the question word is the intention of the sentence to be recognized;
if the currently searched word to be recognized is not the last word to be recognized in the sentence to be recognized, and the currently searched word to be recognized does not have a corresponding question word in the directed graph, searching a corresponding question word in the directed graph of the next word to be recognized of the currently searched word to be recognized;
if the currently searched word to be recognized is not the last word to be recognized in the sentence to be recognized, and all the word to be recognized at the back position after the currently searched word to be recognized has no corresponding question word in the digraph, determining the intention of the sentence to be recognized according to the intention corresponding to the word to be recognized at the front position of the currently searched word to be recognized;
and if the currently searched word to be recognized is the last word to be recognized in the sentence to be recognized, which has a corresponding question word in the directed graph, and the question word is connected with a plurality of intentions through other question words, determining the intention of the sentence to be recognized according to the weight of the directed edge.
Determining the intention of the sentence to be recognized according to the intention corresponding to the front word to be recognized of the currently searched word to be recognized, wherein the method comprises the following steps:
if the number of the directed edges between the intention of the corresponding question participle of the front to-be-identified participle in the directed graph and the question participle is less than or equal to the threshold of the number of the edges, the intention of the question participle is the intention of the to-be-identified sentence;
and if the intentions of the question participles corresponding to the preceding to-be-identified participles in the directed graph and the quantity of the directed edges between the question participles are greater than the threshold value of the number of the edges, the intentions of the to-be-identified sentences cannot be identified.
Constructing a directed graph according to the corpus, comprising:
marking the intentions of all question texts in the corpus;
segmenting the marked question texts to obtain a plurality of question segmentations corresponding to each question text;
and constructing a directed graph according to the intentions of all question texts and a plurality of question clauses corresponding to the intentions of the document texts.
Constructing a directed graph according to the intentions of all question texts and a plurality of question clauses corresponding to the intentions of the document texts, wherein the directed graph comprises the following steps:
using directed edges to connect the question and sentence participles pairwise in sequence according to the sequence of the question and sentence participles in the sentence text;
connecting the last question word in each question text with the intention of the question text;
determining the weight of a directed edge connecting two question clauses according to the co-occurrence frequency of the two question clauses in the question text;
and deleting the directed edges with the weights less than the weight threshold value to obtain a directed graph comprising the question clauses, the intentions, the directed edges and the weights.
Segmenting the sentence to be recognized to obtain a plurality of participles to be recognized, and the method comprises the following steps:
performing word segmentation on a sentence to be recognized to obtain a plurality of words;
and deleting stop words in the vocabulary to obtain a plurality of segmented words to be recognized.
Before segmenting the sentence to be recognized and obtaining a plurality of participles to be recognized, the method further comprises the following steps:
and translating the voice to be recognized to obtain the sentence to be recognized.
The question word is connected with another question word or the question word itself through the directed edge.
And the last word to be recognized is the last word to be recognized in the sentence to be recognized.
The next word to be recognized is the word to be recognized behind the currently searched word to be recognized.
The front word to be recognized is the word to be recognized which is in front of the word to be recognized and is searched currently.
Each question word corresponds to a word node in the directed graph.
Each intent corresponds to a node in the directed graph.
The directed edge in the directed graph has a direction, and the question and phrase in the directed graph are unique.
Since the corpus is also translated from the audio, the corpus also includes the words that are not translated correctly. When the intention labeling is carried out on all question texts in the corpus, the intention labeling is directly carried out on sentences comprising the wrong words in translation without correcting the wrong words in translation, so that the fault tolerance rate can be improved.
Embodiments of the present application will be further described below.
First, the history dialogue is translated to obtain history dialogue texts.
As shown in fig. 2, the history dialogue text is subjected to labeling processing. The dialog text is in the form of a question and a answer, the user sentence is a question, and the machine response is an answer. And marking the corresponding intention of each question of the user (each question in the question text).
And segmenting each question text, and removing stop words to obtain a plurality of question segments. For example, divide "i want to look up my house number" into "i", "want", "look up", "house number", and 4 words of question.
And (3) forming nodes by each question word obtained after word segmentation, and establishing directed edges according to the appearance sequence of each question word from front to back in the sentence to form a directed graph as shown in fig. 3. Whether a node corresponding to a word is generated or not in composition is not related to whether the word is translated correctly or not, and the node representing the word with the wrong translation (question word) is also included in the graph, so that correct intention recognition can be carried out on the question of the user with the wrong translation. Then, the matched intentions of each question in the question text form nodes, and the nodes are linked behind the nodes of the final question participles of the sentence (question). And according to the co-occurrence frequency of the two question clauses in the question text, giving a weight to the directed edge between the two words in the graph. As shown in fig. 4, there are directed graphs of "i want to find the account number", "i want to find the balance", and "find the account number" and "find the balance".
The directed edges connecting word nodes with intents also have weights.
The pruning can be set according to the requirement, for example, the pruning percentage is set, or the pruning weight value (the weight is lower than a certain value, the pruning is performed) is set, and the like.
Traversing all the directed edges in the graph, pruning (deleting the directed edges) the edges with the weight less than a certain threshold f (G) = a, and forming a simplified graph (directed graph), as shown in fig. 5. For the directed graph G, f (G) is the maximum edge weight with a number of occurrences that is less than 5% of the total number of edges.
f (G) = a is a threshold function, the function is f (G), and the specific value is a. This function may be self-defining. Further explanation is given by the example that this function is defined as ordering all edges in the graph, and the last 5% of directed edges are pruned. And sorting all the directed edges in the directed graph from high to low according to the weight of each directed edge, and deleting the 5 percent directed edge with the lowest weight. Assuming that there are 100 directed edges in total, 5 directed edges with the smallest weight are deleted after sorting according to the weight from high to low.
Preferably, the weight may be the number of times two question sentence clause (word node) accompanies appear.
And taking the current user question as a sentence to be recognized, performing word segmentation to obtain n vocabularies, and removing stop words in the vocabularies to obtain a plurality of words to be recognized.
And searching the intention according to the directed graph and the multiple to-be-recognized participles.
The word segmentation to be recognized sequentially comprises the following steps: "i", "want", "check" and "flow", these 4 word segments to be identified.
Starting from the 'I', looking up the 'I' in the directed graph, if the 'I' exists, looking up the 'thought', if the 'I' exists, looking up the 'flow', and if the 'I' exists, using the intention corresponding to the 'flow' as the intention of a question to be identified.
If the query is not found when the query is searched in the directed graph, the next to-be-recognized segmentation word of the query is used for searching in the directed graph, namely the traffic is searched in the sentence, and if the query is found, the intention corresponding to the traffic is used as the intention of the question to be recognized.
If there is no corresponding question clause in the directed graph, the intention of the corresponding question clause of "thought" can be used as the intention of the question to be identified. If there is no corresponding intention, but in the directed graph, when the word "want" is connected with a certain intention through several directed edges, it needs to be considered whether the number of the directed edges between the word "want" and the intention to be recognized exceeds the threshold value of the number of the edges. If the number of the edges is less than or equal to the threshold value of the number of the edges, the intention is used as the intention of the question to be recognized, and if the number of the edges is greater than the threshold value of the number of the edges, the intention of the sentence to be recognized cannot be recognized.
The edge number threshold may be set as desired.
The question word 'want' in the directed graph is connected with 'go', 'watch' and 'movie' in sequence through directed edges, and then 3 directed edges exist between the 'want' and the 'movie'. If the threshold value of the number of edges is 2, the number of the directed edges exceeds the threshold value of the number of the edges, and the intention of the sentence to be recognized cannot be recognized.
If the query has a corresponding question word in the directed graph, but the traffic has no corresponding question word in the directed graph, but the query is connected with the account number through the first directed edge and is connected with the balance through the second directed edge, the intention of the sentence to be recognized is determined according to the weight of the directed edges. That is, if the weight of the first directed edge is greater than that of the second directed edge, the intention corresponding to the "user number" is used as the intention of the question to be recognized. And if the weight of the first directed edge is equal to that of the second directed edge, the intentions corresponding to the user number and the balance are used as the intentions of the question to be recognized.
The graph search algorithm is further explained below.
Firstly, initializing i =1, and setting a total score (weight) K1= K, wherein K is not limited to a specific numerical value, and a node vi corresponding to the ith participle wi to be recognized is a node with a median wi in the directed graph. For the (i + 1) th word after the (i) th word, nodes vi1, vi2, \8230areadjacent to vi, and vim is searched for the node vi +1 with the value wi +1, and then the score Ki +1= Ki is set. After finding the corresponding node vij, let vi +1= vij, i = i +1, and repeat the previous step. If not, the score d is deducted from the score Ki +1 and vi +1 is searched for in the second level neighbor nodes vi11, vi12, \8230;, vi21, vi22, \8230;, vimt of vi, where d is not limited to a specific value here. If not, it is determined that the intention is not recognized.
If a node vijk with value wi +1 is searched, vi +1= vijk is made and the first step is repeated. If there are more than vi +1 matches possible, then the largest of the edge weights and e (vi, vij) + e (vij, vijk) is selected as vi +1. If there are a plurality of vi +1 candidates with equal edge weights, the candidates are all kept. That is, if a question word (word node L) corresponding to the last word to be recognized in the sentence to be recognized is searched in the directed graph, whether a final node (intended node) exists in the first-degree relationship (nodes connected by one directed edge) of the word node L is searched first, and the directed edge with the largest weight is selected as an intention result, and if the directed edge has the same value, the directed edge is retained (and simultaneously used as the recognized intention), and as shown in fig. 6, the direction 2 is selected. And if the first-degree relation has no intention node, searching whether the second-degree relation has a final intention node. If the node of the intentional graph is the second degree path weight, multiplying the two-step weight values of the final intention node and the question clause (the word node L) corresponding to the last clause to be recognized of the sentence to be recognized by the two-step weight values. All the two-degree path weights are compared, the largest one is selected to be the final intention path, and fig. 7 shows that fig. 1 is selected. If the values are the same, the values are reserved. If the second degree still has no final node, the search is stopped, and the intention cannot be searched.
The specific search for the several-degree relationship is related to the setting of the edge number threshold, and if the edge number threshold is set to 0, only the one-degree relationship is searched.
And continuously iterating and searching in the directed graph until finding out the node vn corresponding to the last word wn, and taking the intention corresponding to the intention node connected with the node as a final intention recognition result. The final intention recognition result may be matched to a plurality of vn, and the candidate vn with the highest score Kn is taken as the final result. If the corresponding node vn is not searched finally, the intention is identified as unrecognizable.
According to an embodiment of the present application, there is also provided a user intention recognition system, as shown in fig. 8, including:
the directed graph module 101 is configured to construct a directed graph according to the corpus;
the recognition module 102 is configured to segment a sentence to be recognized to obtain a plurality of segmented words to be recognized, and search a corresponding intention in the directed graph according to the plurality of segmented words to be recognized.
When the directed graph is updated, the wireless network performs off-line operation, and only the part needing to be added is directly added into the directed graph.
Each question word in the directed graph is a node (word node).
In the method, the directed graph is constructed through the corpus, the fault tolerance is strong, and the offline model does not need to be trained by spending a large amount of time and calculation power; and searching the corresponding intention in the directed graph according to the multiple to-be-recognized word segmentations, so that the efficiency is high and the fault tolerance is strong. And under an intelligent voice customer service dialogue scene, constructing a directed graph for identifying intentions based on the results of the question and word segmentation of the user and the corresponding intentions. And the intention recognition is carried out by utilizing the construction and the retrieval of the directed graph, and compared with a method based on a regular expression, a large amount of manual rules are not required to be configured. Compared with a method for searching a question template in a knowledge base, the method does not need to calculate sentence similarity. The calculation efficiency is improved and the calculation time is shortened while the human resources are saved. When the directed graph is constructed, nodes are constructed without difference on correct and wrong translated texts, the fault tolerance on the translation errors is enhanced, and compared with a method based on a regular expression, the accuracy of intention identification under the condition of wrong voice translation is effectively improved. The graph model can be updated online without spending much time and effort in training the offline model compared to the method of classifying the model based on the training intent. By calculating the occurrence frequency of the weight, the directed edge is pruned, so that the calculation amount reduction and the calculation time are reduced, and the calculation efficiency is high.
The above description is only for the preferred embodiment of the present application, but the scope of the present application is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present application should be covered within the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.