Disclosure of Invention
In order to effectively solve the problems in the prior art, the embodiments of the present invention creatively provide a semantic analysis method and apparatus based on rule fusion, and a readable storage medium.
The invention provides a semantic analysis method based on rule fusion, which comprises the following steps: acquiring text data; pre-training the text data on a data set to obtain a plurality of word vectors and/or word vectors; obtaining a rule vector corresponding to each word vector and/or word vector through matching of a system rule engine; combining each word vector and/or word vector with the corresponding regular vector to obtain a corresponding combined vector; and sequentially taking all the obtained combination vectors as the input of a recurrent neural network to obtain intention data for representing the text data.
Preferably, the pre-training of the text data on the data set to obtain a plurality of word vectors and/or word vectors includes: performing word segmentation processing on the text data to obtain a word segmentation processing result; preprocessing the word segmentation processing result on a data set to generate a plurality of word vectors and/or word vectors;
preferably, the sequentially using all the obtained combination vectors as the input of the recurrent neural network to obtain the intention data for characterizing the text data includes: sequentially inputting the obtained combined vectors into a recurrent neural network layer for coding to obtain a first coding result; combining all the rule vectors obtained by matching and performing feature coding to obtain a second coding result; fusing the obtained first coding result and the second coding result to obtain a fused coding result; and adding the fusion coding result to a Softmax layer for intention recognition, thereby obtaining intention data representing the text data.
Preferably, all the matched rule vectors are combined, and feature coding is performed after pooling operation.
Preferably, in the process of sequentially inputting the obtained combination vectors into a recurrent neural network layer for coding, the method further comprises the step of taking the sequentially obtained first coding result as the input of a conditional random field CRF, so as to obtain the sequence labels corresponding to the word and/or word vectors.
Another aspect of the present invention provides a semantic analysis apparatus based on rule fusion, where the apparatus includes: the data acquisition module is used for acquiring text data; the character and/or word vector generation module is used for pre-training the text data on a data set to obtain a plurality of character vectors and/or word vectors; the rule vector generation module is used for obtaining a rule vector corresponding to each word vector and/or word vector through matching of a system rule engine; the combination module is used for combining the word vectors and/or the word vectors with the corresponding regular vectors to obtain combined vectors; and the intention identification module is used for sequentially taking all the obtained combination vectors as the input of the recurrent neural network to obtain intention data for representing the text data.
Preferably, the word and/or word vector generation module is specifically configured to: performing word segmentation processing on the text data to obtain a word segmentation processing result; and pre-training the word segmentation processing result on a data set to obtain a plurality of word vectors and/or word vectors.
Preferably, the intention identifying module is specifically configured to: sequentially inputting the obtained combined vectors into a recurrent neural network layer for coding to obtain a first coding result; combining all the rule vectors obtained by matching, and performing feature coding after pooling operation to obtain a second coding result; fusing the obtained first coding result and the second coding result to obtain a fused coding result; and adding the fusion coding result to a Softmax layer for intention recognition, thereby obtaining intention data representing the text data.
Preferably, the apparatus further comprises a sequence recognition module, which takes the first encoding result obtained in sequence as an input of the conditional random field CRF, so as to obtain the sequence labels corresponding to the words and/or word vectors.
In another aspect, the present invention further provides a computer-readable storage medium, which includes a set of computer-executable instructions, when executed, for performing the rule fusion-based semantic analysis method.
The semantic analysis method, the semantic analysis device and the readable storage medium based on rule fusion of the embodiment of the invention are characterized in that text data is preprocessed through a data set to obtain a plurality of word vectors and/or word vectors, rule vectors corresponding to the word vectors and/or the word vectors are matched through a rule engine, then each word vector and/or word vector is combined with the corresponding rule vector to form a combined vector, the combined vector is used as input of a recurrent neural network to obtain intention data for representing the text data, and the rule engine is combined on the basis of a depth model, so that the output data can be more accurate compared with the prior art.
It is to be understood that the teachings of the present invention need not achieve all of the above-described benefits, but rather that specific embodiments may achieve specific technical results, and that other embodiments of the present invention may achieve benefits not mentioned above.
Detailed Description
In order to make the objects, features and advantages of the present invention more obvious and understandable, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
As shown in fig. 1, an embodiment of the present invention provides a semantic analysis method based on rule fusion, where the method includes:
step 101, data acquisition: text data is acquired.
Step 102, preprocessing text data: and pre-training the text data on a data set to obtain a plurality of word vectors and/or word vectors.
Step 103, loading a rule engine: and matching by a system rule engine to obtain a rule vector corresponding to each word vector and/or word vector.
Step 104, vector preprocessing: and combining each word vector and/or word vector with the corresponding regular vector to obtain a corresponding combined vector.
Step 105, intention recognition: and sequentially taking all the obtained combination vectors as the input of a recurrent neural network to obtain intention data for representing the text data, wherein the intention data is specifically represented as: sequentially inputting the obtained combined vectors into a recurrent neural network layer for coding to obtain a first coding result; combining all the rule vectors obtained by matching and performing feature coding to obtain a second coding result; fusing the obtained first coding result and the second coding result to obtain a fused coding result; and adding the fusion coding result to a Softmax layer for intention recognition, thereby obtaining intention data representing the text data.
In the embodiment of the present invention, first, in step 101, text data is obtained, where the text data is text data of a specific field, the specific field refers to the same type of data or resource and services provided around the data or resource, such as "restaurant", "hotel", "airplane ticket", "train ticket", "yellow phone page", and the text data may be a third-party corpus such as wiki, or data crawled from the internet, and the like.
In step 102, the obtained text data is processed by a word segmentation device such as jieba or a machine learning algorithm based on statistics to obtain at least one word and/or word, and the obtained word and/or word is processed by a data set for word vector pre-training to obtain a corresponding word and/or word vector, wherein the data set is preferably an encyclopedic data set.
And step 103, loading a rule engine, matching rules of the characters and/or words in the corresponding text through the rule engine, and representing all matched rules in one-hot codes.
Further, a rule vector matrix is initialized, and a rule vector of a specified rule is obtained by multiplying the one-hot vector by the initialized rule vector matrix.
Through step 104, combining the obtained multiple word and/or phrase vectors with the corresponding regular vectors to obtain a combined vector, where the specific combination mode is concatenation, for example: if the word and/or word vector w is [ a1, a2], the corresponding regular vector r is [ b1, b2], and the combined vector X after concatenation is [ w, r ], i.e., [ a1, a2, b1, b2 ].
By step 105, shown in connection with FIG. 2, where Xt-1,Xt,Xt+1Respectively representing the input values of the combined vector at t-1, t +1, ht-1,ht,ht+1Respectively representing hidden state vector values of the combined vector at t-1, t and t +1 moments, yt-1,yt,yt+1Respectively representing the output values of the combined vector at t-1, t and t +1, wherein w1 and w2 are weighted values, and the value of the hidden state vector h at t is: h ist=f(w1Xt+w2ht-1)。
Multiplying the obtained plurality of combined vectors X by a weight w1 andtaking the multiplication results as the input of the recurrent neural network in turn, in this embodiment, the recurrent neural network is preferably a bidirectional recurrent neural network, and the first coding result, i.e. the hidden layer state vector value h at the last moment, is obtainedn。
Combining all the matched regular vectors such as R1 and r2.. the combination mode is splicing, and the vector R obtained by combining R1, R2 and R3 is [ R1, R2 and R3]]Performing averaging pooling or max pooling on the vector R obtained by splicing to obtain a feature code R ', wherein the feature code R' is a second coding result, and then hiding the last-moment first coding result into a hidden state vector hnAnd fusing the second coding result in a splicing mode, wherein the splicing mode is consistent with the splicing mode to obtain a fused coding result F, and finally inputting the fused coding result F into a softmax layer for intention identification to obtain intention data representing the text data.
Further, after passing through the neural cycle network, the method further includes a step 106 of labeling the sequence: and sequentially passing the obtained first coding result through a conditional random field CRF to obtain the sequence labels of the corresponding characters and/or word vectors.
By step 106, the first encoding result generated by each cycle is input into the conditional random field CRF according to step 105, and the sequence label corresponding to each word and/or word vector is obtained.
Through the steps, the existing depth model is combined with the rule engine, so that the output intention identification and sequence marking are more accurate.
Based on the above mentioned semantic analysis method based on rule fusion, the invention further provides a semantic analysis device based on rule fusion.
As shown in fig. 3, the apparatus includes:
and the data acquisition module 301 is configured to acquire text data.
A word and/or word vector generation module 302, configured to perform preprocessing on the text data on a data set to generate a plurality of word vectors and/or word vectors.
And the rule vector generating module 303 is configured to obtain a rule vector corresponding to each word vector and/or word vector through matching by a system rule engine.
And the combination module 304 is configured to combine the word vector and/or the word vector with the corresponding rule vector to obtain a combination vector.
An intention identifying module 305, configured to use all the obtained combination vectors as an input of a recurrent neural network in turn, and obtain intention data for characterizing the text data, which is embodied as: sequentially inputting the obtained combined vectors into a recurrent neural network layer for coding to obtain a first coding result; combining all the rule vectors obtained by matching, and performing feature coding after pooling operation to obtain a second coding result; fusing the obtained first coding result and the second coding result to obtain a fused coding result; and adding the fusion coding result to a SoftMax layer for intention identification, thereby obtaining intention data representing the text data.
In the embodiment of the present invention, first, the data acquisition module 301 acquires text data in a specific field.
Through the word and/or word vector generation module 302, the obtained text data is processed by a word segmentation device such as jieba or a machine learning algorithm based on statistics to obtain at least one word and/or word, and then the obtained word and/or word is processed by a data set for pre-training word vectors to obtain a corresponding word and/or word vector, wherein the data set is preferably an encyclopedia data set.
And loading a rule engine through a rule vector generation module 303, matching rules of the characters and/or words in the corresponding text through the rule engine, and representing all matched rules by one-hot coding.
Further, a rule vector matrix is initialized, and a rule vector of a specified rule is obtained by multiplying the one-hot vector by the initialized rule vector matrix.
The obtained multiple word and/or word vectors and the corresponding regular vectors are combined in a splicing manner by the combination module 304 to obtain a combined vector.
The intent recognition module 305 sequentially uses the obtained multiple combined vectors as an input of a recurrent neural network, in this embodiment, the recurrent neural network is a bidirectional recurrent neural network, and a first encoding result, that is, a hidden state vector value at the last moment, is obtained.
Combining all the rule vectors obtained by matching, such as R1 and r2.. the combination mode is splicing, for example, the vector R obtained by combining R1, R2 and R3 is [ R1, R2 and R3], performing averaging pooling or max pooling on the vector R obtained by splicing to obtain a feature code R ', wherein the feature code R' is a second coding result, then fusing the first coding result and the second coding result at the last moment, wherein the fusion mode is splicing, the splicing mode is consistent with the splicing mode, so that a fusion coding result F is obtained, and finally inputting the fusion coding result F into a SoftMax layer for intention identification, so that intention data representing text data is obtained.
Further, the apparatus also includes a sequence identification module 306: and sequentially inputting the obtained first coding result into a conditional random field CRF so as to obtain sequence labels corresponding to the characters and/or word vectors.
The first coding result obtained after each cycle is input to the conditional random field CRF by the sequence recognition module 306, so as to obtain a sequence label corresponding to each word and/or word vector.
Through the module, the rule engine is combined on the basis of the existing depth model, so that the output intention identification and sequence marking are more accurate.
Based on the above-mentioned method and apparatus for rule fusion based semantic analysis, the present invention additionally provides a computer-readable storage medium comprising a set of computer-executable instructions for any one of the rule fusion based semantic analysis methods.
The semantic analysis method, the semantic analysis device and the readable storage medium based on rule fusion in the embodiment of the invention are characterized in that text data is firstly pre-trained through a data set to obtain a plurality of word vectors and/or word vectors, then the rule vectors corresponding to the word vectors and/or word vectors are matched through a rule engine, then each word vector and/or word vector is combined with the corresponding rule vector to form a combined vector, the combined vector is used as the input of a recurrent neural network to obtain intention data for representing the text data, and the rule engine is combined on the basis of a depth model, so that the output data can be more accurate compared with the prior art.
In the description herein, references to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction.
Furthermore, the terms "first", "second" and "first" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. In the description of the present invention, "a plurality" means two or more unless specifically defined otherwise.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the appended claims.