Small-sample intention recognition method based on multi-level attention and hierarchical category features
Through the multi-level attention mechanism and the dynamic routing idea of capsule network, the lack of mining of multi-granular semantic information and statistical features of text in small sample intent recognition is solved, and the recognition accuracy and model robustness are improved.
Patent Information
- Application Number
- CN202211452106.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2022-05-11
- Filing Date
- 2022-11-21
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2042-11-21
AI Technical Summary
Small-sample intent recognition methods are difficult to mine multi-granular semantic information and statistical features of text, and lack modeling from sample representation to category representation, making the model susceptible to noise.
A multi-level attention mechanism is used to fuse word-level, phrase-level, and semantic role-level features, and the nonlinear mapping relationship between samples and category representations is learned through the dynamic routing idea of capsule networks to generate category representations.
It effectively improves the accuracy of small sample intent recognition, reduces the impact of noise words on recognition, and improves the robustness of the model.
Smart Images

Figure CN116049349B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a small sample intention recognition method based on multi-level attention and level category features, belonging to the technical field of natural language processing and question answering system. Background Art
[0002] Intent recognition aims to identify user needs, that is, to classify user queries into intent categories. Intent recognition can be regarded as a text classification problem. Intent recognition is widely used in fields such as information retrieval, sentiment analysis, and conversational robots. The purpose of small-sample intent recognition is to learn an intent classifier on the training set, so that when faced with a new category, it can identify the intent category of the test sample and achieve good performance even with only a small number of labeled samples.
[0003] Small sample learning methods can be roughly divided into four categories: (1) Optimization-based methods, which are parameter update algorithms based on gradient descent and capture the generalization ability of optimization algorithms through a small number of iterative steps; (2) Model-based methods: quickly update parameters from the perspective of model structure design and directly establish a mapping function between input values and predicted values; (3) Metric-based methods: This type of method learns a function that measures the distance between samples and classifies the test instances by calculating the distance between the instance to be tested and the labeled data; (4) Data enhancement-based methods: The main idea of this type of method is to expand the data set by adding data or to enhance features by adding features.
[0004] Small sample learning can be divided into two meanings. The first is standard small sample learning. Assume that a base class set is given, and each category has a sufficient number of labeled samples; given another new class set, each category has only a small number of labeled samples, and the intersection of the base class set and the new class set is an empty set. Generally, the categories in the base class set are called known intent categories, and the categories in the new class set are called unknown intent categories. The classifier is trained on the base class category, and then tested on samples of the new class category. The second is generalized small sample learning, that is, when testing, not only samples in the new class category are included, but also samples in the base class category. The present invention proposes an intent recognition method for generalized small samples.
[0005] At present, the main problems of small sample intent recognition methods are as follows: (1) It is difficult to mine the multi-granular semantic information of the text and rarely introduce the statistical features of the text itself. Existing small sample intent recognition methods usually use word vectors or sentence vectors as input features. However, in the small sample scenario, due to the small number of samples, it is difficult to mine the deep semantic information of the text using only the input features of word vectors or sentence vectors. In addition, the existing intent recognition methods ignore the statistical characteristics of the text data itself. (2) Lack of modeling from sample representation to category representation. Small sample intent recognition methods based on metric learning usually use the mean of sample embedding representation to generate category representation. The lack of modeling from sample representation to category representation makes the small sample intent recognition model susceptible to noise. Summary of the invention
[0006] The purpose of this invention is to solve the problem of difficulty in mining multi-granular semantic information of text and less introduction of statistical features of the text itself in small sample intent recognition tasks, and lack of modeling from sample representation to category representation. A small sample intent recognition method based on multi-level attention and hierarchical category features is proposed.
[0007] The characteristics of the small sample intention recognition method of the present invention are: first, a three-layer attention mechanism is introduced at the word level, phrase level, and semantic role level, and a mixed feature factor is calculated by integrating four levels of category features, namely, word frequency, inverse document frequency, intra-class distribution uniformity, and inter-class distribution uniformity, to fully explore text features at different levels, different granularities, and different angles, which can effectively improve the accuracy of small sample intention recognition. Second, unlike the method of generating category representation by taking the mean of sample representation, the present invention is based on the idea of dynamic routing in capsule networks, learns the nonlinear mapping relationship between samples and category representations, and improves the ability to generalize and learn category representations from samples.
[0008] In order to achieve the above object, the present invention adopts the following technical scheme:
[0009] A small sample intention recognition method based on multi-level attention and hierarchical category features, the steps of the method include:
[0010] Step 1: Construct support set and query set;
[0011] Suppose the text x consists of words i =(x i1 ,x i2 ,x i3 ,...,x it ), x ik is a word, where i and t are natural numbers, and k = 1, 2, 3, ..., t. i The corresponding intent category label is y i , in, is the set of intent categories, N c is the number of intent categories. A set (x i ,y i ) constitutes a sample, the data set D = {(x1,y1),(x2,y2),...,(x m ,y m )}There are m samples in total;
[0012] Based on the dataset D, a small sample dataset is constructed, and then the support set and query set are constructed.
[0013] The small sample intent recognition task is usually composed of several meta-tasks. A meta-task T usually consists of two parts: support set and query set, that is, T = {S, Q}, where S represents the support set and Q represents the query set. The support set S consists of N S The support set consists of labeled samples. in For text, are the intent category labels of these texts respectively; the query set Q consists of N Q unlabeled samples, namely the query set in, It's text. is the intent category label that needs to be predicted.
[0014] Step 2: Obtain the syntactic phrase label sequences of the texts in the support set and query set constructed in step 1, and generate a phrase label embedding matrix;
[0015] First, use the syntactic analyzer to perform syntactic analysis on the sentence s in the text to obtain a phrase tag sequence;
[0016] Let sentence s=(w1,w2,...,w n ), where w1,w2,...,w n Represents words, and n is the number of words in the sentence s.
[0017] Then, construct the phrase tag dictionary PhraseDict and phrase tag table PhraseList of the support set and query set; the phrase tag dictionary PhraseDict is the set of all phrase tags, and the phrase tag table PhraseList consists of the phrase tag sequence of each sentence; for all phrase tags in the phrase tag dictionary, use Word2vec to generate the phrase tag embedding matrix Among them, n p represents the number of labels in the phrase label dictionary, and d represents the dimension of the phrase label embedding.
[0018] Step 3: Obtain the semantic role label sequences of the texts in the support set and query set constructed in step 1, and generate a semantic role label embedding matrix;
[0019] First, for sentence s, a semantic role labeling tool is used to label the text sentence s with semantic roles to obtain a semantic role label sequence.
[0020] Then, the semantic role label dictionary SrlDict and the semantic role table SrlList of the support set and the query set are constructed. The semantic role dictionary SrlDict is a set of all semantic role labels, and the semantic role table SrlList is composed of the semantic role label sequence of each sentence.
[0021] For all semantic role labels in the dictionary, use Word2vec to generate a semantic role label embedding matrix Among them, n srl represents the number of labels in the semantic role label dictionary, and d represents the embedding dimension.
[0022] Step 4: Generate word-level semantic feature vectors for the texts in the support set and query set;
[0023] First, the pre-trained model BERT is used to encode the text sentence and generate a word vector. Specifically, for sentence s, the feature vector w is obtained after BERT encoding, as shown in formula (1):
[0024] w=BERT(s), (1)
[0025] In a sentence, different words usually have different degrees of association or contribution to the semantic representation of the sentence. The word-level semantic feature vector s is constructed. w , as shown in formulas (2), (3) and (4):
[0026] u w =tanh(W w w t +b w ), (2)
[0027] α w =exp(u w ) / ∑ t exp(u w ), (3)
[0028] s w =∑ t α w u w , (4)
[0029] Where tanh(·) is the hyperbolic tangent function, W w To initialize the weights, update W during trainingw , w t represents the tth word in the sentence, b w represents the initialization bias value, α w represents the attention weight, and exp represents the exponential function with e as the base.
[0030] Step 5: Generate phrase-level semantic feature vectors for the texts in the support set and query set;
[0031] The initial embedding of the phrase tag sequence is obtained based on the phrase tag embedding matrix and phrase tag table obtained in step 2, and the deep features are generated using the bidirectional long-short term memory (Bi-LSTM) encoding. The self-attention mechanism is introduced to construct the semantic feature vector at the phrase level.
[0032] Specifically, according to the phrase tag embedding matrix W obtained in step 2 p And the phrase tag table PhraseList, get the initial embedding of the sentence phrase tag sequence in, Represents the phrase label vector in the sentence, N p is the number of phrase tags contained in the sentence;
[0033] A bidirectional long short-term memory network Bi-LSTM is used to encode the initial embedding of the phrase tag sequence, and the hidden layer dimension is set to 128 dimensions; different phrases in a sentence have different degrees of association or contribution to the semantic representation of the sentence; the attention weight at the phrase level is calculated, and then the semantic feature vector s at the phrase level is constructed. p , as shown in formulas (5), (6) and (7):
[0034] u p =tanh(W p p′ t +b p ), (5)
[0035] α p =exp(u p ) / ∑ t exp(u p ), (6)
[0036] s p =∑ t α p u p , (7)
[0037] Where tanh(·) is the hyperbolic tangent function, W p To initialize the weights, p is continuously updated during training.t ′ represents the tth phrase label, b p represents the initialization bias value, α p represents the attention weight, and exp represents the exponential function with e as the base.
[0038] Step 6: Generate semantic feature vectors at the semantic role level of the text in the support set and query set;
[0039] According to the semantic role embedding matrix and semantic role table obtained in step 3, the initial embedding of the semantic role label sequence is constructed, and the Bi-LSTM encoding is used to generate deep features. The self-attention mechanism is introduced to construct the semantic feature vector at the semantic role level.
[0040] Specifically, according to the semantic role label embedding matrix W obtained in step 3 srl And the semantic role table SrlList, get the initial embedding of the semantic role label sequence Among them, role z Represents the semantic role label vector in the sentence, z=1,2,...,N r , N r is the number of semantic role labels contained in the sentence;
[0041] The bidirectional long short-term memory network model Bi-LSTM is used to encode the initial embedding of the semantic role label sequence; the hidden layer dimension is set to 128 dimensions, and the vectors in the positive and negative directions are concatenated to obtain the final vector representation r′, whose dimension is 256 dimensions;
[0042] Calculate the attention weights at the semantic role level and construct the semantic feature vector s at the semantic role level r , as shown in formulas (8), (9) and (10):
[0043] u r =tanh(W r r t ′+b r ), (8)
[0044] α r =exp(u r ) / ∑ t exp(u r ), (9)
[0045] s r =∑ t α r u r , (10)
[0046] Where tanh(·) is the hyperbolic tangent function, W rTo initialize the weights, update during training, r t ′ represents the tth semantic role label, b r represents the initialization bias value, α r represents the attention weight, and exp represents the exponential function with e as the base.
[0047] Step 7: Generate a mixed semantic feature vector of the text in the support set and the query set, i.e., a sample vector, and generate a mixed semantic feature vector of the query sentence, i.e., a query vector;
[0048] The word-level semantic feature vector generated in step 4, the phrase-level semantic feature vector generated in step 5, and the semantic role-level semantic feature vector generated in step 6 are concatenated to obtain a final mixed semantic feature vector of the sample and the query sentence.
[0049] Specifically, in order to obtain the semantic feature vector s of a sentence, the word-level semantic feature vector s of sentence s is w , the phrase-level semantic feature vector s p , and the semantic feature vector s at the semantic role level r , for splicing:
[0050] s = concat(s w ,s p ,s r ), (11)
[0051] The samples in the support set are processed through step 7 to generate a mixed semantic feature vector of the samples as the sample vector. The query sentence samples in the query set are processed through step 7 to generate a mixed semantic feature vector of the query sentence as the query vector.
[0052] Step 8: Map the mixed semantic feature vector of the samples in the support set into the intent category representation;
[0053] First, the sample vector s in the support set ju After input into the capsule network, the conversion weight W is used s Transform its dimension:
[0054]
[0055] Among them, the sample vector s ju is the u-th sample vector in the support set of intent category j; for all sample vectors in the support set, the conversion weight W s is shared; the conversion weight W s It will be continuously updated during training; the weighted summation is used to obtain the predicted class vector of category j
[0056]
[0057] Among them, d ju It is called the coupling coefficient;
[0058] Second, use the squash function instead of the activation function:
[0059]
[0060] Where x is any variable;
[0061] Then, through the nonlinear squeezing function, the predicted intent class vector Scale to between 0 and 1 to get the intent class vector c j :
[0062]
[0063] Calculate the intent class vector c j With each sample The inner product of
[0064] Finally, update the coupling coefficient d ju ,
[0065]
[0066] d ju =softmax(b ju ), (17)
[0067] In the first iteration b ju Initialized to 0, indicating that each sample has the same impact on the category representation, and the coupling coefficient d is updated during the training process. ju and b ju , in order to change the impact of different samples on the category representation. The sum of the coupling coefficients of each sample in the support set is 1, which actually represents the abstract meaning of "each part forms a whole in different proportions". After multiple iterations, the sample information with greater relevance to the category representation will increase, while the sample information with less relevance to the category representation will be filtered out. Based on the idea of dynamic routing, it has better robustness and effectiveness compared with methods such as averaging sample vectors.
[0068] Step 9: Calculate the similarity between the query sentence and the intent category representation based on the dot product similarity method;
[0069] Calculate the query vector q obtained from step 7 and the representation of each intent category c obtained from step 8 j Similarity:
[0070] score1=SIM(q,cj ), (18)
[0071] Among them, SIM(·) indicates that the similarity is calculated using dot product.
[0072] Step 10: Calculate the hierarchical category features of the words;
[0073] For the labeled data in the dataset, assume that there are H intent categories in total; first remove the stop words, count the total number of words M, and number each feature word a, and convert it into a feature word dictionary D W ; For dictionary D W For each feature word a in , calculate its mixed feature factor θ to form a mixed feature factor dictionary
[0074] Calculate the word frequency, inverse document frequency, category frequency factor, and intra-category distribution uniformity factor of the feature words, multiply them to obtain the mixed feature factors of all feature words, and construct a mixed feature factor dictionary;
[0075] First, the calculation method of the feature word frequency is shown in formula (19):
[0076]
[0077] Among them, f(a,c j ) indicates that in category c j (j = 1, 2, 3, ..., H, H is the number of intent categories); f(c j ) indicates that in category c j The total number of all entries in;
[0078] Secondly, the calculation method of the inverse document frequency is shown in formula (20):
[0079]
[0080] Among them, N1 represents the total number of samples in the training set, and N2 represents the number of samples containing the feature word t in all intent categories;
[0081] Then, the calculation method of the category frequency factor β is shown in formula (21):
[0082]
[0083] Among them, N(a,c j ) indicates that in category c j The number of samples containing the feature word a, N(c j ) indicates category c j The total number of samples contained in, N(a,c o ) means that except for category c jThe number of samples containing the feature word a in the sample sets of other categories except ;
[0084] Finally, the calculation method of the intra-class distribution uniformity factor γ is shown in formula (22):
[0085]
[0086] Among them, f(a,c jm ) indicates that in category c j The frequency of feature word a in the mth sample, For category c j The total number of samples in Indicates that in category c i The average word frequency of the feature word α in , ε is a small constant; the calculation method of the mixed feature factor is shown in formula (23):
[0087] θ=TF*IDF*β*γ, (23)
[0088] Step 11: Calculate the similarity between the query sentence and the intent category based on the hierarchical category features;
[0089] For category c j All support set samples in , according to the mixed feature factor dictionary Construct a mixed feature factor sequence of the sample and take the mean as the representation of the category For the query to be classified, calculate its mixed feature factor sequence q θ , and each category represents Calculate similarity:
[0090]
[0091] Among them, SIM(·) means that the similarity is calculated using dot product;
[0092] Step 12: Generate a probability distribution of the intent category to which the query sentence belongs;
[0093] The similarity scores in step 9 and step 12 are combined and passed through the softmax function to obtain the final probability distribution of the query sentence belonging to each category.
[0094] Specifically, for the query sentence intended to be classified, a similarity score score1 is obtained in step 9, and a similarity score score2 is obtained in step 12.
[0095] The two similarity scores are combined to obtain the final similarity score between the query and the intent of each category:
[0096] score=score1+λscore2, (25)
[0097] Among them, λ is the balance factor.
[0098] After the softmax function, we get the probability distribution f of the query sentence belonging to each category. E :
[0099] f E =softmax(score). (26)
[0100] Beneficial Effects
[0101] The present invention adopts a small sample intent recognition method based on multi-level attention and hierarchical category features to classify the intent of query sentences. Compared with the existing related methods, the characteristics of this method are:
[0102] (1) To address the problem that existing intent recognition methods do not fully utilize text semantic information and statistical features, this method proposes a multi-level attention mechanism and hierarchical category features of feature words, fully mining the different levels of features of words, phrases, and semantic roles, and using text statistical features from four aspects: word frequency, inverse document frequency, intra-class distribution uniformity, and inter-class distribution uniformity. This method captures the statistical features of feature words within the same category and between different categories, which can effectively improve the accuracy of small sample intent recognition.
[0103] (2) In view of the lack of modeling from sample representation to category representation in existing intent recognition methods, this method proposes a category induction method based on dynamic routing. This method is based on the idea of dynamic routing in capsule networks, learns the nonlinear mapping relationship between sample representation and category representation, filters out features that are not related to classification, and reduces the impact of noise words on intent recognition.
[0104] (3) The method is experimented on a public data set, and the experimental results show the effectiveness and superiority of the method. The method has broad application prospects in the fields of question-answering systems, information retrieval, and conversational robots. BRIEF DESCRIPTION OF THE DRAWINGS
[0105] Figure 1 The present invention is a flowchart of small sample intention recognition based on multi-level attention and hierarchical category features. DETAILED DESCRIPTION
[0106] The small sample intention recognition method based on the present invention uses PyTorch as a development tool and Python as a development language. The following is a detailed description of a preferred implementation of the present invention based on multi-level attention and hierarchical category features.
[0107] Example
[0108] Small sample intent recognition methods based on multi-level attention and hierarchical category features, such as Figure 1 As shown, the following steps are included:
[0109] Step 1: Construct support set and query set;
[0110] Suppose the text x consists of words i =(x i1 ,x i2 ,x i3 ,...,x it ), x ik is a word, where i and t are natural numbers, and k = 1, 2, 3, ..., t. i The corresponding intent category label is y i , in, is the set of intent categories, N c is the number of intent categories. A set (x i ,y i ) constitutes a sample, the data set D = {(x1,y1),(x2,y2),...,(x m ,y m )}There are m samples in total;
[0111] Based on the dataset D, a small sample dataset is constructed, and then the support set and query set are constructed.
[0112] The small sample intent recognition task is usually composed of several meta-tasks. A meta-task T usually consists of two parts: support set and query set, that is, T = {S, Q}, where S represents the support set and Q represents the query set. The support set S consists of N S The support set consists of labeled samples. in For text, are the intent category labels of these texts respectively; the query set Q consists of N Q unlabeled samples, namely the query set in, It's text. is the intent category label that needs to be predicted.
[0113] For example, a support set with the intent category "PlayMusic" has three samples: {(play some seventiesmusic on Netflix,PlayMusic),(play music from 2015,PlayMusic),(play the songjingle bells,PlayMusic)}. Now there is a query set sample "play the song iheart", and the small sample intent recognition task is to predict the intent category label of the query set sample.
[0114] Step 2: Obtain the syntactic phrase label sequences of the texts in the support set and query set constructed in step 1, and generate a phrase label embedding matrix;
[0115] First, use the syntactic analyzer to perform syntactic analysis on the text sentence s to obtain a phrase tag sequence;
[0116] Let sentence s=(w1,w2,...,w n ), where w1,w2,...,w n Represents words, and n is the number of words in the sentence s.
[0117] Then, construct the phrase tag dictionary PhraseDict and phrase tag table PhraseList of the support set and query set; the phrase tag dictionary PhraseDict is the set of all phrase tags, and the phrase tag table PhraseList consists of the phrase tag sequence of each sentence; for all phrase tags in the phrase tag dictionary, use Word2vec to generate the phrase tag embedding matrix Among them, n p represents the number of tags in the phrase tag dictionary, and d represents the dimension of phrase tag embedding. In this embodiment, the dimension of phrase tag embedding is set to 200 dimensions.
[0118] For example, for the text “I want to book a restaurant not far from our college”, the syntactic phrase tag sequence obtained by using the Stanford parser is “('NP','VP','VP','VP','NP','NP','ADVP','ADVP','PP','NP','NP)”.
[0119] Step 3: Obtain the semantic role label sequences of the texts in the support set and query set constructed in step 1, and generate a semantic role label embedding matrix;
[0120] First, for sentence s, a semantic role labeling tool is used to label the text sentence s with semantic roles to obtain a semantic role label sequence.
[0121] Then, the semantic role label dictionary SrlDict and the semantic role table SrlList of the support set and the query set are constructed. The semantic role dictionary SrlDict is a set of all semantic role labels, and the semantic role table SrlList is composed of the semantic role label sequence of each sentence.
[0122] For all semantic role labels in the dictionary, use Word2vec to generate a semantic role label embedding matrix Among them, n srl represents the number of labels in the semantic role label dictionary, and d represents the embedding dimension.
[0123] In this embodiment, the dimension of semantic role label embedding is set to 200. For example, for the sentence "I want to book a restaurant not far from our college", the semantic role labeling tool HanLP is used to obtain the semantic role label sequence of the text as "('ARG0','PRED','ARG1','ARG1','ARG1','ARG1','ARG1','ARG1','ARG1','ARG1','ARG1')".
[0124] Step 4: Generate word-level semantic feature vectors for the texts in the support set and query set;
[0125] First, the pre-trained model BERT is used to encode the text sentence and generate a word vector. Specifically, for sentence s, the feature vector w is obtained after BERT encoding, as shown in formula (1):
[0126] w=BERT(s), (1)
[0127] In a sentence, different words usually have different degrees of association or contribution to the semantic representation of the sentence. The word-level semantic feature vector s is constructed. w , as shown in formulas (2), (3) and (4):
[0128] u w =tanh(W w w t +b w ), (2)
[0129] α w =exp(u w ) / ∑ t exp(u w ), (3)
[0130] s w =∑ t α w u w , (4)
[0131] Where tanh(·) is the hyperbolic tangent function, W w To initialize the weights, update W during training w , w t represents the tth word in the sentence, b w represents the initialization bias value, α w represents the attention weight, and exp represents the exponential function with e as the base.
[0132] Step 5: Generate phrase-level semantic feature vectors for the texts in the support set and query set;
[0133] The initial embedding of the phrase tag sequence is obtained based on the phrase tag embedding matrix and phrase tag table obtained in step 2, and the deep features are generated using the bidirectional long-short term memory (Bi-LSTM) encoding. The self-attention mechanism is introduced to construct the semantic feature vector at the phrase level.
[0134] Specifically, according to the phrase tag embedding matrix W obtained in step 2 p And the phrase tag table PhraseList, get the initial embedding of the sentence phrase tag sequence in, Represents the phrase label vector in the sentence, N p is the number of phrase tags contained in the sentence;
[0135] A bidirectional long short-term memory network Bi-LSTM is used to encode the initial embedding of the phrase tag sequence, and the hidden layer dimension is set to 128 dimensions; different phrases in a sentence have different degrees of association or contribution to the semantic representation of the sentence; the attention weight at the phrase level is calculated, and then the semantic feature vector s at the phrase level is constructed. p , as shown in formulas (5), (6) and (7):
[0136] u p =tanh(W p p′ t +b p ), (5)
[0137] α p =exp(u p ) / ∑ t exp(u p ), (6)
[0138] s p =∑ t α p u p , (7)
[0139] Where tanh(·) is the hyperbolic tangent function, W p To initialize the weights, p is continuously updated during training. t ′ represents the tth phrase label, b p represents the initialization bias value, α p represents the attention weight, and exp represents the exponential function with e as the base.
[0140] Step 6: Generate semantic feature vectors at the semantic role level of the text in the support set and query set;
[0141] According to the semantic role embedding matrix and semantic role table obtained in step 3, the initial embedding of the semantic role label sequence is constructed, and the Bi-LSTM encoding is used to generate deep features. The self-attention mechanism is introduced to construct the semantic feature vector at the semantic role level.
[0142] Specifically, according to the semantic role label embedding matrix W obtained in step 3 srl And the semantic role table SrlList, get the initial embedding of the semantic role label sequence Among them, role z Represents the semantic role label vector in the sentence, z=1,2,...,N r , N r is the number of semantic role labels contained in the sentence;
[0143] The bidirectional long short-term memory network model Bi-LSTM is used to encode the initial embedding of the semantic role label sequence; the hidden layer dimension is set to 128 dimensions, and the vectors in the positive and negative directions are concatenated to obtain the final vector representation r′, whose dimension is 256 dimensions;
[0144] Calculate the attention weights at the semantic role level and construct the semantic feature vector s at the semantic role level r , as shown in formulas (8), (9) and (10):
[0145] u r =tanh(W r r t ′+b r ), (8)
[0146] α r =exp(u r ) / ∑ t exp(u r), (9)
[0147] s r =∑ t α r u r , (10)
[0148] Where tanh(·) is the hyperbolic tangent function, W r To initialize the weights, update during training, r t ′ represents the tth semantic role label, b r represents the initialization bias value, α r represents the attention weight, and exp represents the exponential function with e as the base.
[0149] Step 7: Generate a mixed semantic feature vector of the text in the support set and the query set, i.e., a sample vector, and generate a mixed semantic feature vector of the query sentence, i.e., a query vector;
[0150] The word-level semantic feature vector generated in step 4, the phrase-level semantic feature vector generated in step 5, and the semantic role-level semantic feature vector generated in step 6 are concatenated to obtain a final mixed semantic feature vector of the sample and the query sentence.
[0151] Specifically, in order to obtain the semantic feature vector s of a sentence, the word-level semantic feature vector s of sentence s is w , the phrase-level semantic feature vector s p , and the semantic feature vector s at the semantic role level r , for splicing:
[0152] s = concat(s w ,s p ,s r ), (11)
[0153] The samples in the support set are processed through step 7 to generate a mixed semantic feature vector of the samples as the sample vector. The query sentence samples in the query set are processed through step 7 to generate a mixed semantic feature vector of the query sentence as the query vector.
[0154] Step 8: Map the mixed semantic feature vector of the samples in the support set into the intent category representation;
[0155] First, the sample vector s in the support set ju After input into the capsule network, the conversion weight W is used s Transform its dimension:
[0156]
[0157] Among them, the sample vector s juis the u-th sample vector in the support set of intent category j; for all sample vectors in the support set, the conversion weight W s is shared; the conversion weight W s It will be continuously updated during training; the weighted summation is used to obtain the predicted class vector of category j
[0158]
[0159] Among them, d ju It is called the coupling coefficient;
[0160] Second, use the squash function instead of the activation function:
[0161]
[0162] Where x is any variable;
[0163] Then, through the nonlinear squeezing function, the predicted intent class vector Scale to between 0 and 1 to get the intent class vector c j :
[0164]
[0165] Calculate the intent class vector c j With each sample The inner product of
[0166] Finally, update the coupling coefficient d j ,
[0167]
[0168] d ju =softmax(b ju ), (17)
[0169] In the first iteration b ju Initialized to 0, indicating that each sample has the same impact on the category representation, and the coupling coefficient d is updated during the training process. ju and b ju , in order to change the impact of different samples on the category representation. The sum of the coupling coefficients of each sample in the support set is 1, which actually represents the abstract meaning of "each part forms a whole in different proportions". After multiple iterations, the sample information with greater relevance to the category representation will increase, while the sample information with less relevance to the category representation will be filtered out. Based on the idea of dynamic routing, it has better robustness and effectiveness compared with methods such as averaging sample vectors.
[0170] For example, a support set with the intent category "Play Music" has three samples: "play some seventies music on netflix", "play music from 2015", and "play the song jingle bells". After the above steps, the category representation of the "Play Music" class can be obtained.
[0171] Step 9: Calculate the similarity between the query sentence and the intent category representation based on the dot product similarity method;
[0172] Calculate the query vector q obtained from step 7 and the representation of each intent category c obtained from step 8 j Similarity:
[0173] score1=SIM(q,c j ), (18)
[0174] Among them, SIM(·) indicates that the similarity is calculated using dot product.
[0175] Step 10: Obtain the hierarchical category features of the words;
[0176] For the labeled data in the dataset, assume that there are H intent categories in total; first remove the stop words, count the total number of words M, and number each feature word a, and convert it into a feature word dictionary D W ; For dictionary D W For each feature word a in , calculate its mixed feature factor θ to form a mixed feature factor dictionary
[0177] Calculate the word frequency, inverse document frequency, category frequency factor, and intra-category distribution uniformity factor of the feature words, multiply them to obtain the mixed feature factors of all feature words, and construct a mixed feature factor dictionary;
[0178] First, the calculation method of the feature word frequency is shown in formula (19):
[0179]
[0180] Among them, f(a,c j ) indicates that in category c j (j = 1, 2, 3, ..., H, H is the number of intent categories); f(c j ) indicates that in category c j The total number of all entries in;
[0181] Secondly, the calculation method of the inverse document frequency is shown in formula (20):
[0182]
[0183] Among them, N1 represents the total number of samples in the training set, and N2 represents the number of samples containing the feature word t in all intent categories;
[0184] Then, the calculation method of the category frequency factor β is shown in formula (21):
[0185]
[0186] Among them, N(a,c j ) indicates that in category c j The number of samples containing the feature word a, N(c j ) indicates category c j The total number of samples contained in, N(a,c o ) means that except for category c j The number of samples containing the feature word a in the sample sets of other categories except ;
[0187] Finally, the calculation method of the intra-class distribution uniformity factor γ is shown in formula (22):
[0188]
[0189] Among them, f(a,c jm ) indicates that in category c j The frequency of feature word a in the mth sample, For category c j The total number of samples in Indicates that in category c i The average word frequency of the feature word α in , ε is a small constant; the calculation method of the mixed feature factor is shown in formula (23):
[0190] θ=TF*IDF*β*γ, (23)
[0191] Step 11: Calculate the similarity between the query sentence and the intent category based on the hierarchical category features;
[0192] For category c j All support set samples in , according to the mixed feature factor dictionary Construct a mixed feature factor sequence of the sample and take the mean as the representation of the category
[0193] For the query to be classified, calculate its mixed feature factor sequence q θ , and each category represents Calculate similarity:
[0194]
[0195] Among them, SIM(·) means that the similarity is calculated using dot product;
[0196] Step 12: Generate a probability distribution of the intent category to which the query sentence belongs;
[0197] The similarity scores in step 9 and step 12 are combined and passed through the softmax function to obtain a probability distribution of the query sentence belonging to each category.
[0198] Specifically, for the query sentence of the to-be-classified intent, a similarity score score1 is obtained in step 9, and a similarity score score2 is obtained in step 12.
[0199] The two similarity scores are combined to obtain the final similarity score between the query and the intent of each category:
[0200] score=score1+λscore2 (25)
[0201] Among them, λ is the balance factor.
[0202] After the softmax function, the final probability distribution f of the query sentence belonging to each category is obtained. E :
[0203] f E =softmax(score), (26)
[0204] To illustrate the small sample intention recognition effect of the present invention, this experiment is conducted under the same conditions, using the same training set and test set to compare the three methods.
[0205] The first method is a conditional text generation method based on the pre-trained model BERT, the second method is a method based on comparing pre-training and fine-tuning models. The third is a small sample intent recognition method based on a multi-level attention mechanism and hierarchical category features of the present invention.
[0206] The evaluation index used is accuracy. For the recognition of known intent categories, the accuracy of the first method is 98.30%. For the recognition of unknown intent categories, the accuracy of the first method is 82.94%. For the recognition of known intent categories, the accuracy of the second method is 98.73%. For the recognition of unknown intent categories, the accuracy of the second method is 82.61%. For the recognition of known intent categories, the accuracy of the small sample intent recognition method based on multi-level attention mechanism and hierarchical category features of the present invention is 98.79%. For the recognition of unknown intent categories, the accuracy of the method of the present invention is 83.79%. The experimental results show that the performance of the small sample intent recognition method based on multi-level attention mechanism and hierarchical category features proposed by the present invention is better than that of the other two methods, which shows the effectiveness of the method of the present invention.
[0207] The above is only a preferred embodiment of the present invention, and the present invention should not be limited to the contents disclosed in the embodiment and the drawings. Any equivalent or modification completed without departing from the spirit disclosed in the present invention shall fall within the scope of protection of the present invention.
Claims
1. A small sample intent recognition method based on multi-level attention and hierarchical category features, characterized by The steps of the method include: Step 1: Construct support set and query set; Step 2: Obtain the syntactic phrase label sequences of the texts in the support set and query set constructed in step 1, and generate a phrase label embedding matrix; Step 3: Obtain the semantic role label sequences of the texts in the support set and query set constructed in step 1, and generate a semantic role label embedding matrix; Step 4: Generate word-level semantic feature vectors for the texts in the support set and query set; Step 5: Generate phrase-level semantic feature vectors for the texts in the support set and query set; Step 6: Generate semantic feature vectors at the semantic role level of the text in the support set and query set; Step 7: Generate a mixed semantic feature vector of the text in the support set and the query set, i.e., a sample vector, and generate a mixed semantic feature vector of the query sentence, i.e., a query vector; Step 8: Map the mixed semantic feature vector of the samples in the support set into the intent category representation; First, the sample vector s in the support set ju After input into the capsule network, the conversion weight W is used s Transform its dimension: Among them, the sample vector s ju is the u-th sample vector in the support set of intent category j; for all sample vectors in the support set, the conversion weight W s is shared; the conversion weight W s It will be continuously updated during training; the weighted summation is used to obtain the predicted class vector of category j Among them, d ju It is called the coupling coefficient; Second, use the squash function instead of the activation function: Where x is any variable; Then, through the nonlinear squeezing function, the predicted intent class vector Scale to between 0 and 1 to get the intent class vector c j : Calculate the intent class vector c j With each sample The inner product of Finally, update the coupling coefficient d ju , <h2 style=";text-align:left;direction:ltr">d<h2 style=";text-align:left;direction:ltr"> ju <h2 style=";text-align:left;direction:ltr"> =softmax(b<h2 style=";text-align:left;direction:ltr"> ju <h2 style=";text-align:left;direction:ltr"> ), (17) Step 9: Calculate the similarity between the query sentence and the intent category representation based on the dot product similarity method; Calculate the query vector q obtained from step 7 and the representation of each intent category c obtained from step 8 j Similarity: score1=SIM(q,c j ), (18) Among them, SIM(·) means that the similarity is calculated using dot product; Step 10: Obtain the hierarchical category features of the words; For the labeled data in the dataset, assume that there are H intent categories in total; first remove the stop words, count the total number of words M, and number each feature word t, and convert it into a feature word dictionary D W ; For dictionary D W For each feature word a in , calculate its mixed feature factor θ and construct a mixed feature factor dictionary Calculate the word frequency, inverse document frequency, category frequency factor, and intra-category distribution uniformity factor of the feature words, multiply them to obtain the mixed feature factors of all feature words, and construct a mixed feature factor dictionary; First, the calculation method of the feature word frequency is shown in formula (19): Among them, f(a,c j ) indicates that in category c j (i=1,2,3,...,H, H is the number of intent categories); f(c j ) indicates that in category c j The total number of all entries in; Secondly, the calculation method of the inverse document frequency is shown in formula (20): Among them, N1 represents the total number of samples in the training set, and N2 represents the number of samples containing the feature word t in all intent categories; Then, the calculation method of the category frequency factor β is shown in formula (21): Among them, N(a,c j ) indicates that in category c j The number of samples containing the feature word a, N(c j ) indicates category c j The total number of samples contained in, N(a,c o ) means that except for category c j The number of samples containing the feature word a in the sample sets of other categories except ; Finally, the calculation method of the intra-class distribution uniformity factor γ is shown in formula (22): Among them, f(a,c jm ) indicates that in category c j The frequency of feature word a in the mth sample, For category c j The total number of samples in Indicates that in category c i The average word frequency of the feature word α, ε is a small constant; The calculation method of the mixed characteristic factor is shown in formula (23): θ=TF*IDF*β*γ, (23) Step 11: Calculate the similarity between the query sentence and the intent category based on the hierarchical category features; For category c j All support set samples in , according to the mixed feature factor dictionary Construct a mixed feature factor sequence of the sample and take the mean as the representation of the category For the query to be classified, calculate its mixed feature factor sequence q θ , and each category represents Calculate similarity: Among them, SIM(·) means that the similarity is calculated using dot product; Step 12: Generate a probability distribution of the intent category to which the query belongs The similarity scores in step 9 and step 12 are combined and passed through the softmax function to obtain the final probability distribution of the query sentence belonging to each category. For the query sentence to be classified, a similarity score score1 is obtained in step 9, and a similarity score score2 is obtained in step 12; The two similarity scores are combined to obtain the final similarity score between the query and the intent of each category: score=score1+λscore2, (25) Among them, λ is the balance factor; After the softmax function, we get the probability distribution f of the query sentence belonging to each category. E : f E =softmax(score) (26)。 2. The small sample intention recognition method based on multi-level attention and hierarchical category features according to claim 1 is characterized in that: In step 1, the method of constructing the support set and query set is: Suppose the text x consists of words i =(x i1 ,x i2 ,x i3 ,...,x it ), x ik is a word, where i and t are natural numbers, k = 1, 2, 3, ..., t, and the text x i The corresponding intent category label is y i , in, is the set of intent categories, N c is the number of intent categories, a set (x i ,y i ) constitutes a sample, the data set D = {(x1,y1),(x2,y2),...,(x m ,y m )}There are m samples in total; Based on the dataset D, a small sample dataset is constructed, and then the support set and query set are constructed; The small sample intent recognition task is composed of several meta-tasks. A meta-task T consists of two parts: support set and query set, that is, T = {S, Q}, where S represents the support set and Q represents the query set. The support set S consists of N S The support set consists of labeled samples. in For text, are the intent category labels of these texts respectively; the query set Q consists of N Q unlabeled samples, namely the query set in, It's text. is the intent category label that needs to be predicted.
3. The small sample intention recognition method based on multi-level attention and hierarchical category features according to claim 2 is characterized in that: In step 2, the syntactic phrase label sequences of the texts in the support set and query set constructed in step 1 are obtained, and the method for generating the phrase label embedding matrix is: First, use the syntactic analyzer to perform syntactic analysis on the text sentence s to obtain a phrase tag sequence; Let sentence s=(w1,w2,...,w n ), where w1,w2,...,w n represents words, n is the number of words in the sentence s; Then, construct the phrase tag dictionary PhraseDict and phrase tag table PhraseList of the support set and query set; the phrase tag dictionary PhraseDict is the set of all phrase tags, and the phrase tag table PhraseList consists of the phrase tag sequence of each sentence; for all phrase tags in the phrase tag dictionary, use Word2vec to generate the phrase tag embedding matrix Among them, n p represents the number of labels in the phrase label dictionary, and d represents the dimension of the phrase label embedding.
4. The small sample intention recognition method based on multi-level attention and hierarchical category features according to claim 3 is characterized in that: In step 3, the semantic role label sequences of the texts in the support set and query set constructed in step 1 are obtained, and the method for generating the semantic role label embedding matrix is: First, for sentence s, use the semantic role labeling tool to label the text sentence s with semantic roles to obtain a semantic role label sequence; Then, construct the semantic role label dictionary SrlDict and semantic role table SrlList of the support set and query set; The semantic role dictionary SrlDict is the set of all semantic role labels, and the semantic role table SrlList consists of the semantic role label sequence of each sentence; For all semantic role labels in the dictionary, use Word2vec to generate a semantic role label embedding matrix Among them, n srl represents the number of labels in the semantic role label dictionary, and d represents the embedding dimension.
5. The small sample intention recognition method based on multi-level attention and hierarchical category features according to claim 4 is characterized in that: In step 4, the method for generating word-level semantic feature vectors of the support set and query set text is: First, the pre-trained model BERT is used to encode the text sentence and generate a word vector. Specifically, for sentence s, the feature vector w is obtained after BERT encoding, as shown in formula (1): w=BERT(s), (1) In a sentence, different words usually have different degrees of association or contribution to the semantic representation of the sentence. The word-level semantic feature vector s is constructed. w , as shown in formulas (2), (3) and (4): u w =tanh(W w w t +b w ), (2) α w =exp(in w ) / ∑ t exp(in w ), (3) s w =∑ t a w you w , (4) Where tanh(·) is the hyperbolic tangent function, W w To initialize the weights, update W during training w , w t represents the tth word in the sentence, b w represents the initialization bias value, α w represents the attention weight, and exp represents the exponential function with e as the base.
6. The small sample intention recognition method based on multi-level attention and hierarchical category features according to claim 5 is characterized in that: In step 5, the method for generating the phrase-level semantic feature vectors of the support set and the query set text is: According to the phrase tag embedding matrix W obtained in step 2 p And the phrase tag table PhraseList, get the initial embedding of the sentence phrase tag sequence in, Represents the phrase label vector in the sentence, N p is the number of phrase tags contained in the sentence; The bidirectional long short-term memory network model Bi-LSTM is used to encode the initial embedding of the phrase tag sequence, and the hidden layer dimension is set to 128 dimensions; different phrases in the sentence have different degrees of association or contribution to the semantic representation of the sentence; the attention weight at the phrase level is calculated, and then the semantic feature vector s at the phrase level is constructed. p , as shown in formulas (5), (6) and (7): u p =tanh(W p p t ′+b p ), (5) α p =exp(in p ) / ∑ t exp(in p ), (6) s p =∑ t a p you p , (7) Where tanh(·) is the hyperbolic tangent function, W p To initialize the weights, p is continuously updated during training. t ′ represents the tth phrase label, b p represents the initialization bias value, α p represents the attention weight, and exp represents the exponential function with e as the base.
7. The small sample intention recognition method based on multi-level attention and hierarchical category features according to claim 6 is characterized in that: In step 6, the method for generating semantic feature vectors at the semantic role level of the support set and query set text is: According to the semantic role label embedding matrix W obtained in step 3 srl And the semantic role table SrlList, get the initial embedding of the semantic role label sequence Among them, role z Represents the semantic role label vector in the sentence, z=1,2,...,N r , N r is the number of semantic role labels contained in the sentence; The bidirectional long short-term memory network model Bi-LSTM is used to encode the initial embedding of the semantic role label sequence; the hidden layer dimension is set to 128 dimensions, and the vectors in the positive and negative directions are concatenated to obtain the final vector representation r′, whose dimension is 256 dimensions; Calculate the attention weights at the semantic role level and construct the semantic feature vector s at the semantic role level r , as shown in formulas (8), (9) and (10): u r =tanh(W r r t ′+b r ), (8) α r =exp(in r ) / ∑ t exp(in r ), (9) s r =∑ t a r you r , (10) Where tanh(·) is the hyperbolic tangent function, W r To initialize the weights, update during training, r t ′ represents the tth semantic role label, b r represents the initialization bias value, α r represents the attention weight, and exp represents the exponential function with e as the base.
8. The small sample intention recognition method based on multi-level attention and hierarchical category features according to claim 7 is characterized in that: In step 7, the method for generating a mixed semantic feature vector of the support set and the query set text is: the word-level semantic feature vector s of the sentence s generated in step 4 is converted into w , the phrase-level semantic feature vector s generated in step 5 p , and the semantic feature vector s at the semantic role level generated in step 6 r , for splicing: concat(s w ,s p ,s r ),(11) The samples in the support set are processed through step 7 to generate a mixed semantic feature vector of the samples as the sample vector; the query sentence samples in the query set are processed through step 7 to generate a mixed semantic feature vector of the query sentence as the query vector.
