Language parsing method, device, electronic device and storage medium
By obtaining the target vector sequence of the language to be parsed and making predictions, and combining with the prediction sequences of other decoders, the limitations of the language analysis method in the prior art are solved, and more accurate language analysis results are achieved.
Patent Information
- Application Number
- CN202211370706.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-03
- Publication Date
- 2025-06-03
- Estimated Expiration
- 2042-11-03
AI Technical Summary
The implementation process of language analysis methods in the prior art has certain limitations, which leads to the inability of electronic devices to obtain the single-objective semantic analysis results accurately.
By obtaining the language to be parsed, determining its corresponding target vector sequence, and using a bidirectional long and short-term memory neural network for prediction, the target prediction sequence corresponding to the target decoder is obtained. Combining the prediction sequences of other decoders, the target analysis results of the language to be parsed are determined.
It realizes that electronic devices can obtain more accurate target analysis results corresponding to the language to be parsed, and improves the accuracy of language analysis.
Smart Images

Figure CN115759111B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, and in particular, to a language parsing method, apparatus, electronic device, and storage medium. Background Art
[0002] With the booming development of the Internet and the rapid expansion of network resources, the Knowledge Graph has become an important part of many artificial intelligence systems. This Knowledge Graph stores a vast amount of information, and the acquisition of this information depends on a specific formal query language. An electronic device can use semantic parsing technology to parse natural language to obtain the above-mentioned formal query language, thereby providing an efficient way for non-professional knowledge people to query this information.
[0003] There are two existing language parsing methods: The first method is that the electronic device parses at least one target formal language corresponding to the natural language one by one to obtain at least one single-target semantic parsing result; the second method is that the electronic device uses at least one decoder to parse at least one target formal language respectively to obtain at least one single-target semantic parsing result.
[0004] Regardless of which of the above language parsing methods, due to certain limitations in the implementation process of these language parsing methods, it is easy to cause the electronic device to fail to accurately obtain the single-target semantic parsing result. Summary of the Invention
[0005] The present invention provides a language parsing method, apparatus, electronic device, and storage medium to solve the defect that the implementation process of the language parsing method in the prior art has certain limitations, which easily causes the electronic device to fail to accurately obtain the single-target semantic parsing result, and realizes that the electronic device can obtain a relatively accurate target parsing result corresponding to the language to be parsed.
[0006] The present invention provides a language parsing method, including:
[0007] Obtain the language to be parsed;
[0008] Determine the target vector sequence corresponding to the language to be parsed;
[0009] Perform prediction on the target vector sequence to determine the target prediction sequence corresponding to the target decoder;
[0010] Determine the target parsing result corresponding to the language to be parsed according to the target vector sequence, the target prediction sequence, and the other prediction sequences corresponding to the other decoders obtained.
[0011] A language parsing method provided by the present invention for determining a target vector sequence corresponding to the language to be parsed includes: obtaining the target vector sequence corresponding to the language to be parsed based on a bidirectional long short-term memory neural network, where the target vector sequence includes vector sequences corresponding to various formal language information of the language to be parsed.
[0012] A language parsing method provided by the present invention for obtaining the target vector sequence corresponding to the language to be parsed based on a bidirectional long short-term memory neural network includes: obtaining an intermediate sequence based on the encoding formula in the bidirectional long short-term memory neural network; obtaining the target vector sequence corresponding to the language to be parsed according to the sequence formula; where the encoding formula is h i = LSTM(x i , h i-1 ); q = (x 1 , x 2 , …, x i ); the sequence formula is h = (h 1 , h 2 , …, h |q| ); q represents the language to be parsed; x i represents the i-th character in the language to be parsed q; h represents the target vector sequence; h i represents the i-th intermediate sequence in the target vector sequence h; h |q| represents the |q|-th intermediate sequence in the target vector sequence h; h i-1 represents the (i - 1)-th intermediate sequence in the target vector sequence h.
[0013] A language parsing method provided by the present invention for predicting the target vector sequence to determine the target prediction sequence corresponding to the target decoder includes: predicting the target vector sequence based on a first long short-term memory neural network and a first attention mechanism to obtain the target prediction sequence corresponding to the target decoder.
[0014] A language parsing method provided by the present invention for predicting the target vector sequence based on a first long short-term memory neural network and a first attention mechanism to obtain the target prediction sequence corresponding to the target decoder includes: determining a first context vector corresponding to the target vector sequence based on the first attention mechanism; obtaining a decoding vector based on the first long short-term memory neural network according to the first context vector; obtaining the vector sequence corresponding to the target vector sequence at the previous moment; obtaining the target prediction sequence corresponding to the target decoder according to the first context vector, the decoding vector, and the vector sequence corresponding to the previous moment.
[0015] A language parsing method provided by the present invention, which determines the target parsing result corresponding to the language to be parsed according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders obtained, includes: determining the target parsing result corresponding to the language to be parsed based on a second long short-term memory neural network and a second attention mechanism according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders obtained.
[0016] A language parsing method provided by the present invention, which determines the target parsing result corresponding to the language to be parsed based on a second long short-term memory neural network and a second attention mechanism according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders obtained, includes: receiving other prediction sequences sent by other decoders; determining a second context vector corresponding to the target vector sequence, a third context vector corresponding to the target prediction sequence, and a fourth context vector corresponding to the other prediction sequence based on the second attention mechanism; and obtaining the target parsing result corresponding to the language to be parsed based on the second long short-term memory neural network according to the second context vector, the third context vector, and the fourth context vector.
[0017] The present invention also provides a language parsing device, including:
[0018] An acquisition module, configured to acquire the language to be parsed and the vector sequence to be parsed corresponding to the language to be parsed;
[0019] A processing module, configured to determine the target vector sequence corresponding to the language to be parsed; perform prediction on the target vector sequence to determine the target prediction sequence corresponding to the target decoder; and determine the target parsing result corresponding to the language to be parsed according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders obtained.
[0020] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, where the processor implements the language parsing method as described in any one of the above when executing the program.
[0021] The present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored, and the computer program implements the language parsing method as described in any one of the above when being executed by a processor.
[0022] The present invention also provides a computer program product, including a computer program, where the computer program implements the language parsing method as described in any one of the above when being executed by a processor.
[0023] The language parsing method, device, electronic device, and storage medium provided by the present invention obtain the language to be parsed, determine the target vector sequence corresponding to the language to be parsed, predict the target vector sequence to determine the target prediction sequence corresponding to the target decoder, and determine the target parsing result corresponding to the language to be parsed according to the target vector sequence, the target prediction sequence, and the other prediction sequences corresponding to other decoders obtained. The electronic device can use different decoders to simultaneously decode different prediction sequences. In addition, the electronic device can also utilize the complementary relationship between different types of formal languages, enabling the target decoder to assist each other with the target prediction sequence and the other prediction sequences corresponding to other decoders during the decoding process, jointly improving the decoding accuracy of each decoder, and thus obtaining a relatively accurate target parsing result corresponding to the language to be parsed. That is, this method is used to solve the defect that the implementation process of the language parsing method in the prior art has certain limitations, which easily leads to the electronic device being unable to accurately obtain a single-target semantic parsing result, and realizes that the electronic device can obtain a relatively accurate target parsing result corresponding to the language to be parsed. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] To more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the following drawings are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0025] Figure 1 It is one of the schematic diagrams of the scenario of the language parsing method provided by the present invention;
[0026] Figure 2 It is the flowchart of the language parsing method provided by the present invention;
[0027] Figure 3 It is the second schematic diagram of the scenario of the language parsing method provided by the present invention;
[0028] Figure 4 It is the structural schematic diagram of the language parsing device provided by the present invention;
[0029] Figure 5 It is the structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0030] To make the objectives, technical solutions, and advantages of the present invention clearer, the technical solutions in the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the present invention. Apparently, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present invention without making creative efforts fall within the protection scope of the present invention.
[0031] It should be noted that the electronic devices involved in the embodiments of the present invention may include, but are not limited to, tablet computers, desktop computers, mobile terminals, wearable devices, etc.
[0032] As Figure 1 shown, it is a schematic diagram of the scenario of the language parsing method provided by the present invention. In Figure 1 , the electronic device 10 may include: an encoder (Encoder) 101 and at least i decoders (Decoder) 102, where i is an integer greater than or equal to 1.
[0033] Among them, the at least i decoders 102 may include: a first decoder 1021, a second decoder 1022,..., an i-th decoder 102i.
[0034] The electronic device 10 obtains the language to be parsed;
[0035] The encoder 101 is configured to encode the language to be parsed to obtain a target vector sequence corresponding to the language to be parsed, and the target vector sequence may include sequences corresponding to at least one type of formal language.
[0036] The decoder 102 is configured to decode the target vector sequence to obtain a parsing result corresponding to the language to be parsed.
[0037] In some embodiments, the process of the decoder 102 decoding the vector sequence to obtain a parsing result has two decoding stages. In the first decoding stage, the decoder 102 makes a rough prediction on the vector sequence to obtain a prediction sequence; in the second decoding stage, the decoder decodes the prediction sequence to obtain a parsing result corresponding to the language to be parsed, and the parsing result may be a knowledge graph.
[0038] Different decoders 102 decode vector sequences corresponding to different types of formal languages. That is to say, the target decoder can decode the vector sequence corresponding to the target type of formal language to obtain a target prediction sequence, and then decode the target prediction sequence to obtain a target parsing result corresponding to the language to be parsed. Among them, the target decoder is any one of the at least i decoders 102 described above.
[0039] The electronic device uses at least i decoders 102 to obtain at least i target parsing results; then, the electronic device obtains the parsing result corresponding to the language to be parsed according to the at least i target parsing results.
[0040] It should be noted that the execution subject involved in the embodiments of the present invention may be a language parsing device or an electronic device. Hereinafter, the embodiments of the present invention will be further described by taking an electronic device as an example.
[0041] Such as Figure 2 shown, is a schematic flowchart of the language parsing method provided by the present invention, which may include:
[0042] 201. Obtain the language to be parsed.
[0043] Natural language refers to a language that naturally evolves with culture and is used for mutual communication between humans.
[0044] Optionally, natural languages may include, but are not limited to: Chinese, English, French, etc.
[0045] The language to be parsed refers to any one of the above natural languages.
[0046] 202. Determine the target vector sequence corresponding to the language to be parsed.
[0047] After obtaining the language to be parsed, the electronic device can use an encoder to encode the language to be parsed to obtain the target vector sequence corresponding to the language to be parsed.
[0048] There is a bidirectional long short-term memory neural network (Bi-Long Short Term Memory, Bi-LSTM) in the encoder, and the Bi-LSTM includes 2 independent long short-term memory neural networks (Long Short Term Memory, LSTM).
[0049] The electronic device inputs the sequence corresponding to the language to be parsed in the forward sequence into the first LSTM in the Bi-LSTM, and the first LSTM can extract features from the forward sequence to obtain the first feature vector sequence; the electronic device inputs the sequence corresponding to the language to be parsed in the reverse sequence into the second LSTM in the Bi-LSTM, and the second LSTM can extract features from the reverse sequence to obtain the second feature vector sequence; then, the electronic device uses a decoder to splice the first feature vector sequence and the second feature vector sequence to obtain the target vector sequence corresponding to the language to be parsed. In addition, when the Bi-LSTM obtains the target vector sequence corresponding to time t, it can also obtain the target vector sequence before time t and the target vector sequence after time t.
[0050] In some embodiments, for the electronic device to determine the target vector sequence corresponding to the language to be parsed, it may include: the electronic device obtains the target vector sequence corresponding to the language to be parsed based on a bidirectional long short-term memory neural network.
[0051] Among them, the target vector sequence may include sequences corresponding to at least one type of formal language respectively.
[0052] Optionally, after obtaining the target vector sequence corresponding to the language to be parsed, the method may include: the electronic device sends the target vector sequence to at least one decoder.
[0053] The electronic device encodes the language to be parsed using an encoder to obtain sequences corresponding to at least one type of formal language respectively; then, the electronic device sends these sequences to the corresponding decoders respectively.
[0054] Exemplarily, the electronic device sends the sequence corresponding to the first formal language information to the first decoder; the electronic device sends the sequence corresponding to the second formal language information to the second decoder, where the first formal language information is different from the second formal language information.
[0055] Optionally, for the electronic device to obtain the target vector sequence corresponding to the language to be parsed based on a bidirectional long short-term memory neural network, it may include: the electronic device obtains an intermediate sequence based on the encoding formula in the bidirectional long short-term memory neural network; the electronic device obtains the target vector sequence corresponding to the language to be parsed according to the sequence formula.
[0056] Among them, the encoding formula is h i = LSTM(x i , h i-1 ); q = (x 1 , x 2 , …, x i );
[0057] The sequence formula is h = (h 1 , h 2 , …, h |q| );
[0058] q represents the language to be parsed; x i represents the i-th character in the language to be parsed q; h represents the target vector sequence; h i represents the i-th intermediate sequence in the target vector sequence h; h |q| represents the |q|-th intermediate sequence in the target vector sequence h; h i-1 represents the (i - 1)-th intermediate sequence in the target vector sequence h.
[0059] Based on the encoding formula and the sequence formula, the electronic device can obtain a relatively accurate target vector sequence corresponding to the language to be parsed.
[0060] 203. Predict the target vector sequence to determine the target prediction sequence corresponding to the target decoder.
[0061] After the electronic device sends the target vector sequence obtained by the encoder to the target encoder, the target encoder can predict the sequence corresponding to the target type formal language in the target vector sequence to obtain the target prediction sequence corresponding to the target encoder. This process is the process executed by the target encoder in the first decoding stage.
[0062] In some embodiments, when the electronic device predicts the target vector sequence to determine the target prediction sequence corresponding to the target decoder, it may include: The electronic device predicts the target vector sequence based on the first long short-term memory neural network and the first attention mechanism to obtain the target prediction sequence corresponding to the target decoder.
[0063] Among them, the first long short-term memory neural network LSTM is a recurrent neural network (Recurrent Neural Network, RNN), which can process the correlation between target vector sequences in time. That is to say, the LSTM can predict the target vector sequence in time.
[0064] The first attention mechanism refers to a model that also pays attention to the information that is easily overlooked in the target vector sequence during the process of processing the target vector sequence.
[0065] In some embodiments, when the electronic device predicts the target vector sequence based on the first long short-term memory neural network and the first attention mechanism to obtain the target prediction sequence corresponding to the target decoder, it may include: The electronic device determines the first context vector corresponding to the target vector sequence based on the first attention mechanism; the electronic device obtains the decoding vector based on the first long short-term memory neural network according to the first context vector; the electronic device obtains the vector sequence corresponding to the target vector sequence at the previous moment; the electronic device obtains the target prediction sequence corresponding to the target decoder according to the first context vector, the decoding vector, and the vector sequence corresponding to the previous moment.
[0066] Optionally, when the electronic device determines the first context vector corresponding to the target vector sequence based on the first attention mechanism, it may include: The electronic device obtains the first context vector corresponding to the target vector sequence according to the first vector formula in the first attention mechanism.
[0067] Among them, the first vector formula is
[0068] ctx e1represents the first context vector; α i represents the i-th intermediate sequence h i The corresponding weight coefficient.
[0069] Optionally, the weight coefficients corresponding to different time series can be the same or different, and no specific limitation is made here.
[0070] In some embodiments, the sum of the i weight coefficients respectively corresponding to the i intermediate sequences is 1. That is:
[0071] According to the first vector formula, the electronic device can obtain the first context vector corresponding to a relatively accurate target vector sequence.
[0072] Optionally, based on the first context vector, the electronic device obtains a decoding vector based on the first long short-term memory neural network, which may include: the electronic device obtains the decoding vector according to the first decoding formula in the first long short-term memory neural network.
[0073] Among them, the first decoding formula is
[0074] represents the decoding vector corresponding to time t; represents the vector sequence corresponding to the target vector sequence at the previous time t - 1; The decoding vector corresponding to time t - 1; represents the vector sequence corresponding to the target vector sequence at the previous time t - 1 and the concatenated vector of the first context vector ctx e1 of.
[0075] According to the first decoding formula, the electronic device can obtain a relatively accurate decoding vector.
[0076] Optionally, based on the first context vector, the decoding vector, and the vector sequence corresponding to the previous time, the electronic device obtains the target prediction sequence corresponding to the target decoder, which may include: the electronic device obtains the decoding sequence according to the second decoding formula in the fully connected layer; the electronic device obtains the target prediction sequence corresponding to the target decoder according to the prediction sequence formula.
[0077] Among them, the second decoding formula is
[0078] The prediction sequence formula is
[0079] represents the target vector sequence; p represents the decoding sequence; softmax(·) represents the exponential normalization function; FFN(·) represents the feedforward neural network; Represents the decoded vector The first context vector ctx e1 And the target vector sequence The vector sequence corresponding to the previous moment The concatenated vector; argmax(·) represents the function that returns the maximum value.
[0080] Based on the second decoding formula and the prediction sequence formula, the electronic device can obtain a relatively accurate target prediction sequence corresponding to the target decoder.
[0081] 204. Determine the target parsing result corresponding to the language to be parsed according to the target vector sequence, the target prediction sequence, and the other prediction sequences corresponding to the other decoders obtained.
[0082] After the electronic device obtains the target vector sequence corresponding to the language to be parsed and the target prediction sequence corresponding to the target decoder, it can obtain the other prediction sequences sent by the other decoders except the target decoder among at least i decoders. The number of the other decoders is i - 1, and the number of the other prediction sequences is i - 1. Then, the electronic device determines the target parsing result corresponding to the language to be parsed according to the target vector sequence, the target prediction sequence, and the other prediction sequences. This process is the process executed by the target encoder in the second decoding stage.
[0083] Exemplarily, as Figure 3 shown, is a schematic diagram of the scenario of the language parsing method provided by the present invention. In Figure 3 , the electronic device 30 includes an encoder 301 and decoders 302.
[0084] Among them, the number of the encoders 301 is 1, and the number of the decoders 302 is 3. These 3 decoders are respectively the Prolog Decoder 3021, the FunQL Decoder 3022, and the Structured Query Language Decoder (SQL Decoder) 3023.
[0085] The electronic device 30 obtains the language to be parsed;
[0086] The encoder 301 is used to encode the language to be parsed to obtain the target vector sequence corresponding to the language to be parsed. The target vector sequence may include a first sequence corresponding to the formal language of the prologue type, a second sequence corresponding to the formal language of the semantic analysis type, and a third sequence corresponding to the formal language of the structured query type;
[0087] The Prolog Decoder 3021 is used to predict the first sequence in the first-stage decoding to obtain the first prediction sequence;
[0088] A semantic analysis decoder 3022, configured to predict a second sequence in a first-stage decoding to obtain a second prediction sequence;
[0089] A structured query language decoder 3023, configured to predict a third sequence in a first-stage decoding to obtain a third prediction sequence;
[0090] A preface decoder 3021, configured to obtain a target preface result corresponding to the language to be parsed according to the first prediction sequence, the second prediction sequence corresponding to the semantic analysis decoder 3022, and the third prediction sequence corresponding to the structured query language decoder 3023 in a second-stage decoding;
[0091] A semantic analysis decoder 3022, configured to obtain a target language analysis result corresponding to the language to be parsed according to the second prediction sequence, the first prediction sequence corresponding to the preface decoder 3021, and the third prediction sequence corresponding to the structured query language decoder 3023 in a second-stage decoding;
[0092] A structured query language decoder 3023, configured to obtain a target structured query result corresponding to the language to be parsed according to the third prediction sequence, the first prediction sequence corresponding to the preface decoder 3021, and the second prediction sequence corresponding to the semantic analysis decoder 3022 in a second-stage decoding;
[0093] An electronic device 30 obtains a knowledge graph set corresponding to the language to be parsed according to the target preface result, the target language analysis result, and the target structured query result.
[0094] In some embodiments, the electronic device determines a target parsing result corresponding to the language to be parsed according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders obtained, which may include: the electronic device determines a target parsing result corresponding to the language to be parsed based on a second long short-term memory neural network and a second attention mechanism according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders obtained.
[0095] Wherein, the explanation of the second long short-term memory neural network is similar to the explanation of the first long short-term memory neural network in step 203, and the explanation of the second attention mechanism is similar to the explanation of the first attention mechanism in step 203, and no specific details are described here.
[0096] In some embodiments, the electronic device determines the target parsing result corresponding to the language to be parsed based on the second long short-term memory neural network and the second attention mechanism, according to the target vector sequence, the target prediction sequence, and the other prediction sequences corresponding to other decoders obtained, which may include: the electronic device receives the other prediction sequences sent by other decoders; the electronic device determines the second context vector corresponding to the target vector sequence, the third context vector corresponding to the target prediction sequence, and the fourth context vector corresponding to the other prediction sequences based on the second attention mechanism; the electronic device obtains the target parsing result corresponding to the language to be parsed based on the second context vector, the third context vector, and the fourth context vector, based on the second long short-term memory neural network.
[0097] Optionally, the electronic device determines the second context vector corresponding to the target vector sequence, the third context vector corresponding to the target prediction sequence, and the fourth context vector corresponding to the other prediction sequences based on the second attention mechanism, which may include: the electronic device obtains the second context vector corresponding to the target vector sequence according to the second vector formula in the second attention mechanism; the electronic device obtains the third context vector corresponding to the target prediction sequence according to the third vector formula in the second attention mechanism; the electronic device obtains the fourth context vector corresponding to the other prediction sequences according to the fourth vector formula in the attention mechanism.
[0098] Among them, the second vector formula is
[0099] The third vector formula is
[0100] The fourth vector formula is
[0101] ctx e2 represents the second context vector; ctx c represents the third context vector; ctx o represents the fourth context vector; represents the decoding vector corresponding to the one-stage hidden state sequence of other decoders; represents the concatenated vector sequence corresponding to the one-stage decoding sequence of the other decoder.
[0102] The electronic device can obtain relatively accurate second context vector, third context vector, and fourth context vector respectively according to the second vector formula, the third vector formula, and the fourth vector formula.
[0103] Optionally, the electronic device obtains a target parsing result corresponding to the language to be parsed based on the second context vector, the third context vector, and the fourth context vector and based on the second long short-term memory neural network, which may include: the electronic device obtains an intermediate decoding vector according to a third decoding formula in the second long short-term memory neural network; the electronic device obtains a target parsing result corresponding to the language to be parsed according to the intermediate decoding vector.
[0104] Among them, the third decoding formula is S t = LSTM([y t-1 , ctx e2 , ctx c , ctx o , S t-1 );
[0105] S t represents the intermediate decoding vector corresponding to time t; S t-1 represents the intermediate decoding vector corresponding to time t-1; y t-1 represents the target parsing result corresponding to time t-1.
[0106] After the electronic device obtains a relatively accurate intermediate decoding vector S t according to the third decoding formula, it can splice the intermediate decoding vector S t , the second context vector ctx e2 , the third context vector ctx c and the fourth context vector ctx o to obtain a target splicing vector [S t , ctx e2 , ctx c , ctx o ; then, the electronic device inputs the target splicing vector [S t , ctx e2 , ctx c , ctx o into the fully connected layer in the second long short-term memory neural network to obtain a probability distribution prediction of the target parsing result y t-1 corresponding to time t-1, so as to obtain a target parsing result corresponding to the language to be parsed.
[0107] In some embodiments, after step 204, the method may further include: the electronic device obtains a target loss function corresponding to the target parsing result; the electronic device obtains a total loss function corresponding to the parsing result according to at least one target loss function; the electronic device updates data of the encoder and the decoder in the electronic device based on the total loss function.
[0108] Optionally, the electronic device obtains a loss function corresponding to the target parsing result, which may include: the electronic device obtains a first loss corresponding to the target decoder for the language to be parsed during the first-stage decoding according to a first loss formula; the electronic device obtains a second loss corresponding to the target decoder for the language to be parsed during the second-stage decoding according to a second loss formula; the electronic device obtains a target loss function corresponding to the target parsing result of the language to be parsed according to a third loss formula.
[0109] Among them, the first loss formula is
[0110] The second loss formula is
[0111] The third loss formula is
[0112] represents the first loss; represents the second loss; L i represents the i-th target loss function corresponding to the i-th decoder.
[0113] According to the first loss formula, the second loss formula, and the third loss formula, the electronic device can obtain relatively accurate first loss, second loss, and the target loss function corresponding to the target parsing result respectively.
[0114] Optionally, the electronic device obtains a total loss function corresponding to the parsing result according to at least one target loss function, which may include: the electronic device obtains a total loss function corresponding to the parsing result according to a fourth loss formula.
[0115] Among them, the fourth loss formula is
[0116] L represents the total loss function corresponding to the parsing result.
[0117] The electronic device sums up the i target loss functions corresponding to at least i target parsing results to obtain a relatively accurate total loss function corresponding to the parsing result; then, the electronic device can accurately update the data of the encoder and decoder in the electronic device based on this total loss function.
[0118] In an embodiment of the present invention, a language to be parsed is obtained; a target vector sequence corresponding to the language to be parsed is determined; the target vector sequence is predicted to determine a target prediction sequence corresponding to a target decoder; and a target parsing result corresponding to the language to be parsed is determined according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders obtained. An electronic device can utilize different decoders to simultaneously decode different prediction sequences. In addition, the electronic device can also utilize the complementary relationship between different types of formal languages, enabling the target decoder to assist each other with the target prediction sequence and other prediction sequences corresponding to other decoders during the decoding process, jointly improving the decoding accuracy of each decoder, and thus obtaining a relatively accurate target parsing result corresponding to the language to be parsed. That is, this method is used to solve the defect that the implementation process of the language parsing method in the prior art has certain limitations, which easily leads to the inability of the electronic device to accurately obtain a single-target semantic parsing result, and realizes that the electronic device can obtain a relatively accurate target parsing result corresponding to the language to be parsed.
[0119] The language parsing device provided by the present invention will be described below, and the language parsing device described below can be correspondingly referred to the language parsing method described above.
[0120] As Figure 4 shown, it is a structural schematic diagram of the language parsing device provided by the present invention, which may include:
[0121] An obtaining module 401, configured to obtain a language to be parsed and a to-be-parsed vector sequence corresponding to the language to be parsed;
[0122] A processing module 402, configured to determine a target vector sequence corresponding to the language to be parsed; predict the target vector sequence to determine a target prediction sequence corresponding to a target decoder; and determine a target parsing result corresponding to the language to be parsed according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders obtained.
[0123] Optionally, the processing module 402 is specifically configured to obtain a target vector sequence corresponding to the language to be parsed based on a bidirectional long short-term memory neural network, where the target vector sequence includes vector sequences corresponding to various formal language information of the language to be parsed.
[0124] Optionally, the processing module 402 is specifically configured to obtain an intermediate sequence based on an encoding formula in the bidirectional long short-term memory neural network; and obtain a target vector sequence corresponding to the language to be parsed according to a sequence formula; where the encoding formula is h i = LSTM(x i , h i-1 ); q = (x 1 , x 2, …, x i ); The sequence formula is h = (h 1 , h 2 , …, h |q| ); q represents the language to be parsed; x i represents the i-th character in the language q to be parsed; h represents the target vector sequence; h i represents the i-th intermediate sequence in the target vector sequence h; h |q| represents the |q|-th intermediate sequence in the target vector sequence h; h i-1 represents the (i - 1)-th intermediate sequence in the target vector sequence h.
[0125] Optionally, the processing module 402 is specifically configured to predict the target vector sequence based on the first long short-term memory neural network and the first attention mechanism to obtain a target prediction sequence corresponding to the target decoder.
[0126] Optionally, the processing module 402 is specifically configured to determine a first context vector corresponding to the target vector sequence based on the first attention mechanism; and obtain a decoding vector based on the first long short-term memory neural network according to the first context vector.
[0127] The acquisition module 401 is specifically configured to acquire a vector sequence corresponding to the target vector sequence at the previous moment.
[0128] The processing module 402 is specifically configured to obtain a target prediction sequence corresponding to the target decoder according to the first context vector, the decoding vector, and the vector sequence corresponding to the previous moment.
[0129] Optionally, the processing module 402 is specifically configured to determine a target parsing result corresponding to the language to be parsed based on the second long short-term memory neural network and the second attention mechanism according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders.
[0130] Optionally, the acquisition module 401 is specifically configured to receive other prediction sequences sent by other decoders;
[0131] The processing module 402 is specifically configured to determine a second context vector corresponding to the target vector sequence, a third context vector corresponding to the target prediction sequence, and a fourth context vector corresponding to the other prediction sequences based on the second attention mechanism; and obtain a target parsing result corresponding to the language to be parsed based on the second long short-term memory neural network according to the second context vector, the third context vector, and the fourth context vector.
[0132] Figure 5 Illustrates a schematic diagram of the physical structure of an electronic device, such as Figure 5As shown, the electronic device may include: a processor 510, a communications interface 520, a memory 530, and a communication bus 540. Among them, the processor 510, the communications interface 520, and the memory 530 communicate with each other via the communication bus 540. The processor 510 may invoke the logical instructions in the memory 530 to execute a language parsing method, which includes: obtaining the language to be parsed; determining the target vector sequence corresponding to the language to be parsed; predicting the target vector sequence to determine the target prediction sequence corresponding to the target decoder; and determining the target parsing result corresponding to the language to be parsed according to the target vector sequence, the target prediction sequence, and the other prediction sequences corresponding to the other decoders obtained.
[0133] In addition, when the logical instructions in the above-mentioned memory 530 are implemented in the form of software functional units and sold or used as independent products, they may be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, may be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs that can store program codes.
[0134] On the other hand, the present invention also provides a computer program product. The computer program product includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the language parsing method provided by the above-mentioned various methods, which includes: obtaining the language to be parsed; determining the target vector sequence corresponding to the language to be parsed; predicting the target vector sequence to determine the target prediction sequence corresponding to the target decoder; and determining the target parsing result corresponding to the language to be parsed according to the target vector sequence, the target prediction sequence, and the other prediction sequences corresponding to the other decoders obtained.
[0135] In another aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements a language parsing method provided by the above-mentioned various methods. The method includes: obtaining a language to be parsed; determining a target vector sequence corresponding to the language to be parsed; predicting the target vector sequence to determine a target prediction sequence corresponding to a target decoder; and determining a target parsing result corresponding to the language to be parsed according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders obtained.
[0136] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. A person of ordinary skill in the art can understand and implement it without creative labor.
[0137] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution, in essence, or the part that contributes to the prior art can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0138] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments or perform equivalent replacements for some of the technical features. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A language parsing method, characterized in that, it includes: obtaining the language to be parsed; determining a target vector sequence corresponding to the language to be parsed, including: based on a bidirectional long short-term memory neural network, obtaining the target vector sequence corresponding to the language to be parsed, and the target vector sequence includes vector sequences corresponding to various formal language information of the language to be parsed; performing prediction on the target vector sequence to determine a target prediction sequence corresponding to a target decoder, including: based on a first long short-term memory neural network and a first attention mechanism, performing prediction on the target vector sequence to obtain the target prediction sequence corresponding to the target decoder, and the target decoder is used to decode the vector sequence corresponding to the target type formal language in the various formal language information to obtain the target prediction sequence; determining a target parsing result corresponding to the language to be parsed according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders obtained, and the target parsing result is obtained through the target decoder.
2. The method according to claim 1, characterized in that, the obtaining the target vector sequence corresponding to the language to be parsed based on the bidirectional long short-term memory neural network includes: obtaining an intermediate sequence based on the encoding formula in the bidirectional long short-term memory neural network; obtaining the target vector sequence corresponding to the language to be parsed according to the sequence formula; wherein, the encoding formula is h i = LSTM(x i , h i-1 ); q = (x 1 , x 2 , …, x i ); The sequence formula is h = (h 1 , h 2 , …, h |q| ); q represents the language to be parsed; x i represents the i-th character in the language q to be parsed; h represents the target vector sequence; h i represents the i-th intermediate sequence in the target vector sequence h; h |q| represents the |q|-th intermediate sequence in the target vector sequence h; h i-1 represents the (i - 1)-th intermediate sequence in the target vector sequence h.
3. The method according to claim 1, characterized in that, the performing prediction on the target vector sequence based on the first long short-term memory neural network and the first attention mechanism to obtain the target prediction sequence corresponding to the target decoder includes: determining a first context vector corresponding to the target vector sequence based on the first attention mechanism; obtaining a decoding vector based on the first long short-term memory neural network according to the first context vector; obtaining the vector sequence corresponding to the previous moment of the target vector sequence; obtaining the target prediction sequence corresponding to the target decoder according to the first context vector, the decoding vector, and the vector sequence corresponding to the previous moment.
4. The method according to any one of claims 1-2, characterized in that, the determining the target parsing result corresponding to the language to be parsed according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders obtained includes: determining the target parsing result corresponding to the language to be parsed based on a second long short-term memory neural network and a second attention mechanism according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders obtained.
5. The method according to claim 4, characterized in that, the determining the target parsing result corresponding to the language to be parsed based on the second long short-term memory neural network and the second attention mechanism according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders obtained includes: receiving other prediction sequences sent by other decoders; Based on the second attention mechanism, determine the second context vector corresponding to the target vector sequence, the third context vector corresponding to the target prediction sequence, and the fourth context vector corresponding to the other prediction sequences; Based on the second context vector, the third context vector, and the fourth context vector, and based on a second long short-term memory neural network, obtain the target parsing result corresponding to the language to be parsed.
6. A language parsing device, characterized in that, it includes: an acquisition module, configured to acquire a language to be parsed and a vector sequence to be parsed corresponding to the language to be parsed; a processing module, configured to determine a target vector sequence corresponding to the language to be parsed, including: based on a bidirectional long short-term memory neural network, obtain a target vector sequence corresponding to the language to be parsed, the target vector sequence including vector sequences corresponding to various formal language information of the language to be parsed; perform prediction on the target vector sequence to determine a target prediction sequence corresponding to a target decoder, including: based on a first long short-term memory neural network and a first attention mechanism, perform prediction on the target vector sequence to obtain a target prediction sequence corresponding to the target decoder, the target decoder being configured to decode the vector sequence corresponding to the target type formal language in the various formal language information to obtain the target prediction sequence; according to the target vector sequence, the target prediction sequence, and other prediction sequences corresponding to other decoders obtained, determine the target parsing result corresponding to the language to be parsed, the target parsing result being obtained through the target decoder.
7. An electronic device, including: a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that when the processor executes the program, it implements the language parsing method according to any one of claims 1 to 5.
8. A non-transitory computer-readable storage medium, on which a computer program is stored, characterized in that, when the computer program is executed by a processor, it implements the language parsing method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Knowledge extraction method and system based on memory neural network and device
CN108304911A
SQL (Structured Query Language) conversion method and system based on language model coding and multi-task decoding
CN112988785A