A syntax analysis method, device, equipment and storage medium
By using the grammatical parsing model in the dictionary pen to parse the hierarchical grammatical structure and the dependence between words of the target sentences, a joint parsing tree is generated, which solves the problem that the existing dictionary pen cannot provide grammatical information and improves the user's ability to learn language.
Patent Information
- Application Number
- CN202111175440.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-09
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2041-10-09
AI Technical Summary
Existing dictionary pens cannot perform grammatical analysis of scanned text and cannot provide user grammatical information, which limits users' ability to learn language.
A pre-established grammar parsing model is used to obtain target sentences, parse their hierarchical grammar structure information and dependency information between words, generate a joint parsing tree, and display detailed grammar information.
It realizes detailed grammatical information analysis of the target sentences, helps users learn language better and improves the assisted learning ability of the dictionary pen.
Smart Images

Figure CN113901798B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of natural language processing, and in particular to a grammar parsing method, apparatus, device and storage medium. Background Art
[0002] When people learn a language, especially a non-native language, they usually encounter some unfamiliar words. In order to help users learn the language, various dictionary pens are launched on the market. Users can quickly learn the meaning of unfamiliar words by scanning unfamiliar words with dictionary pens. However, existing dictionary pens can only translate the scanned text, but cannot perform grammatical analysis. This means that users can only simply understand the meaning of words through dictionary pens, but cannot learn grammatical information. Therefore, existing dictionary pens are of limited help to users. Summary of the invention
[0003] In view of this, the present application provides a grammatical parsing method, apparatus, device and storage medium for parsing grammatical information of a text, thereby helping users to better learn a language. The technical solution is as follows:
[0004] A grammar parsing method, comprising:
[0005] Get the target sentence;
[0006] Using a pre-established grammatical parsing model, parsing the hierarchical grammatical structure information and the inter-word dependency relationship information of the target sentence, and generating a joint parsing tree that can simultaneously present the hierarchical grammatical structure information and the inter-word dependency relationship information of the target sentence according to the parsing result;
[0007] The grammatical parsing model is obtained by training using training sentences and a joint parsing tree corresponding to the training sentences.
[0008] Optionally, the parsing of the hierarchical grammatical structure information and inter-word dependency information of the target sentence includes:
[0009] Taking the target sentence as the text to be parsed, predicting the component labels of the text to be parsed, and predicting the segmentation method of the text to be parsed;
[0010] Predicting dependency relationship labels between text segments obtained after segmenting the text to be parsed according to the segmentation method;
[0011] For each segmented text segment, if the text segment includes multiple words, the text segment is used as the text to be parsed, and the component labels of the text to be parsed and subsequent steps are performed.
[0012] Optionally, the joint parse tree includes a plurality of leaf nodes and a plurality of non-leaf nodes, each leaf node represents a word in the target sentence, each non-leaf node represents a phrase in the target sentence, the next level of each non-leaf node is a leaf node and / or a non-leaf node, and the information of each node includes the word or phrase represented by the node and a component label of the word or phrase represented by the node;
[0013] Nodes at different levels with a hierarchical relationship are connected through a first connection line, and nodes at the same level with a dependency relationship are connected through a second connection line, and each second connection line has a dependency relationship label.
[0014] Optionally, predicting the component labels of the text to be parsed includes:
[0015] Predicting the probability that the component labels of the text to be parsed are the set component labels, and determining the component labels of the text to be parsed according to the probability that the component labels of the text to be parsed are the set component labels;
[0016] The method of predicting the segmentation of the text to be parsed includes:
[0017] The scores of the candidate segmentation methods for the text to be parsed are predicted, and the segmentation method for the text to be parsed is determined according to the scores of the candidate segmentation methods for the text to be parsed.
[0018] Optionally, the predicted component labels of the text to be parsed are probabilities of each set component label, including:
[0019] Determine a representation vector of the text to be parsed according to a forward vector of a first word, a forward vector of a backward adjacent word of a second word, a backward vector of the second word, and a backward vector of a forward adjacent word of the first word, wherein the first word is the first word of the text to be parsed, the second word is the last word of the text to be parsed, the forward vector of a word can represent the semantics of the word when the target sentence is examined from front to back, and the backward vector of a word can represent the semantics of the word when the target sentence is examined from back to front;
[0020] According to the representation vector of the text to be parsed, the probability that the component label of the text to be parsed is each set component label is predicted.
[0021] Optionally, determining the representation vector of the text to be parsed according to the forward vector of the first word, the forward vector of the backward adjacent word of the second word, the backward vector of the second word, and the backward vector of the forward adjacent word of the first word includes:
[0022] Subtracting the forward vector of the first word from the forward vector of the backward adjacent word of the second word to obtain a forward vector difference, and subtracting the backward vector of the second word from the backward vector of the forward adjacent word of the first word to obtain a backward vector difference;
[0023] The forward vector difference is concatenated with the backward vector difference, and the concatenated vector is used as a representation vector of the text to be parsed.
[0024] Optionally, the process of acquiring the forward vector and the backward vector of a word in the target sentence includes:
[0025] For each word in the target sentence: using the grammatical parsing model to obtain the word vector, part-of-speech representation vector and position representation vector of the word, summing the part-of-speech representation vector of the word with the position representation vector of the word, and concatenating the summed vector with the word vector of the word, and using the concatenated vector as the representation vector of the word; to obtain the representation vector of each word in the target sentence;
[0026] The grammatical parsing model is used to perform attention calculation on the representation vector of the word and the representation vectors of other words in the target sentence to obtain the context vector of the word, and the forward vector and backward vector of the word are obtained according to the context vector of the word.
[0027] Optionally, the predicted scores of the candidate segmentation methods of the text to be parsed include:
[0028] For each candidate split method:
[0029] Predict the probability that each text segment obtained by segmenting the text to be parsed according to the candidate segmentation method is a phrase component, so as to obtain the probability corresponding to each text segment;
[0030] The probabilities corresponding to the text segments are summed up, and the summed probability is used as the score of the candidate segmentation method;
[0031] To obtain the scores of each candidate segmentation method for the text to be parsed.
[0032] Optionally, the predicting of dependency relationship labels between text segments obtained after segmenting the text to be parsed according to the segmentation method includes:
[0033] Predicting scores of candidate arc drawing methods of a text segment obtained after segmenting the text to be parsed according to the segmentation method, and determining a target arc drawing method according to the scores of the candidate arc drawing methods, wherein each arc under each candidate arc drawing method is a directed arc from a word in one text segment to a word in another text segment;
[0034] For each arc under the target arc drawing method, the probability that the dependency labels of the two words connected by the arc are the set dependency labels is predicted, and the dependency labels of the two words connected by the arc are determined according to the probability that the dependency labels of the two words connected by the arc are the set dependency labels.
[0035] Optionally, the predicting that the dependency labels of the two words connected by the arc are the probabilities of the set dependency labels includes:
[0036] Obtain one or more of the following features of the two words connected by the arc: word-level features, distance features, and sentence-level features;
[0037] Determine a characterization vector of the arc according to the acquired features;
[0038] According to the representation vector of the arc, the probability of the dependency labels of the two words connected by the arc being the set dependency labels is predicted.
[0039] Optionally, obtain sentence-level features of the two words connected by the arc, including:
[0040] Obtaining a representation vector of a first part and a representation vector of a last part of three parts obtained by dividing the target sentence using the two words connected by the arc as a dividing line;
[0041] The representation vector of the last part is subtracted from the representation vector of the first part, and the vector obtained by the subtraction is used as a sentence-level feature of the two words connected by the arc.
[0042] Optionally, the process of establishing the grammar parsing model includes:
[0043] The training text is used as the text to be parsed, and the grammar parsing model is used to predict the probability that the component labels of the text to be parsed are the set component labels and the scores of each candidate segmentation method of the text to be parsed as the first prediction result;
[0044] For each candidate segmentation method of the text to be parsed, predict the scores of each candidate arc drawing method of the text segment obtained by segmenting the text to be parsed according to the candidate segmentation method, and the probability that the dependency labels of two words connected by each arc under each candidate arc drawing method are set dependency labels, so as to obtain the prediction results under each candidate segmentation method as the second prediction results;
[0045] updating parameters of a grammar parsing model according to the first prediction result, the second prediction result, and a relevant part of a joint parse tree corresponding to the training text;
[0046] For each text segment obtained by segmenting according to each candidate segmentation method, if the text segment includes multiple words, the text segment is used as the text to be parsed, and the method of using the grammatical parsing model to predict the probability of the component labels of the text to be parsed being the set component labels and the scores of each candidate segmentation method of the text to be parsed and subsequent steps are performed.
[0047] Optionally, updating parameters of the grammar parsing model according to the first prediction result, the second prediction result, and a relevant part of the joint parse tree corresponding to the training text includes:
[0048] Determining a first prediction loss of a grammatical parsing model according to a relevant portion of the hierarchical grammatical structure information presented by the first prediction result and the joint parse tree corresponding to the training text;
[0049] Determining a second prediction loss of the grammatical parsing model according to a relevant portion of the inter-word dependency information presented by the second prediction result and the joint parse tree corresponding to the training text;
[0050] The first prediction loss and the second prediction loss are fused, and parameters of the grammatical parsing model are updated according to the fused loss.
[0051] A grammar analysis device, comprising: a text acquisition module and a grammar analysis module;
[0052] The text acquisition module is used to acquire the target sentence;
[0053] The grammar parsing module is used to parse the hierarchical grammar structure information and the inter-word dependency relationship information of the target sentence using a pre-established grammar parsing model, and generate a joint parse tree that can simultaneously present the hierarchical grammar structure information and the inter-word dependency relationship information of the target sentence according to the parsing result;
[0054] The grammatical parsing model is obtained by training using training sentences and a joint parsing tree corresponding to the training sentences.
[0055] A grammar parsing device, comprising: a memory and a processor;
[0056] The memory is used to store programs;
[0057] The processor is used to execute the program to implement each step of the grammar parsing method described in any one of the above items.
[0058] A readable storage medium stores a computer program, and when the computer program is executed by a processor, the computer program implements each step of any of the above-mentioned grammar parsing methods.
[0059] Through the above scheme, it can be seen that the grammatical parsing method provided by the present application first obtains the target sentence, and then uses the pre-established grammatical parsing model to parse the hierarchical grammatical structure information and word dependency information of the target sentence, and generates a joint parsing tree that can simultaneously present the hierarchical grammatical structure information and word dependency information of the target sentence according to the parsing result. The grammatical parsing method provided by the embodiment of the present application can parse out more detailed grammatical information of the target sentence. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0061] Figure 1 A flowchart of a grammar parsing method provided in an embodiment of the present application;
[0062] Figure 2 A schematic diagram of a process for parsing hierarchical grammatical structure information and inter-word dependency information of a target sentence using a pre-established grammatical parsing model provided in an embodiment of the present application;
[0063] Figure 3 A schematic diagram of an example of hierarchical grammatical structure information provided in an embodiment of the present application;
[0064] Figure 4 A schematic diagram of an example of inter-word dependency information provided in an embodiment of the present application;
[0065] Figure 5 A schematic diagram of an example of a joint parsing tree provided in an embodiment of the present application;
[0066] Figure 6 A flowchart of using a grammatical parsing model to predict component labels of a text to be parsed and a segmentation method of the text to be parsed provided in an embodiment of the present application;
[0067] Figure 7 A schematic diagram of a part-of-speech tagging model provided in an embodiment of the present application predicting a part-of-speech tag;
[0068] Figure 8 A schematic diagram of a part-of-speech tag predicted for a sentence using a part-of-speech tagging model provided in an embodiment of the present application;
[0069] Fig. 9A schematic diagram of a process for predicting dependency labels between text segments obtained after segmenting the text to be parsed according to the segmentation method of the text to be parsed using a grammatical parsing model provided in an embodiment of the present application;
[0070] Fig.10 A schematic diagram of two candidate arc drawing methods for three text segments provided in an embodiment of the present application;
[0071] Fig.11 A schematic diagram of a process for training a grammar parsing model using a training sentence and a joint parse tree corresponding to the training sentence provided in an embodiment of the present application;
[0072] Fig.12 A schematic diagram of the structure of a grammar parsing device provided in an embodiment of the present application;
[0073] Fig.13 A schematic diagram of the structure of a grammar parsing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0074] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0075] In order to obtain the grammatical information of the target sentence, the applicant conducted research. The initial idea was to use a natural language processing toolkit combined with a rule-based parsing method, that is, to first parse the target sentence with a natural language processing tool, and then determine the grammatical information of the target sentence based on some rules. However, the technologies of natural language processing packages are relatively early technologies, and the processing effect on the target sentence is poor. The rules used are also relatively simple, and the grammatical information finally determined is not comprehensive enough to meet the learning requirements of users.
[0076] In view of the problems existing in the parsing method of natural language processing toolkit combined with rules, the inventor of this case tried to propose a grammatical parsing method that does not use rules and can parse out more comprehensive and detailed grammatical information. To this end, the applicant conducted in-depth research and finally proposed a grammatical parsing method with better effect through continuous research. The grammatical parsing method can be applied to electronic devices with data processing capabilities. The electronic device can be a server on the network side (it can be a single server, or multiple servers or server clusters), or a terminal used on the user side, such as a smart phone, a dictionary pen, etc. Next, the grammatical parsing method provided by this application is introduced through the following embodiments.
[0077] First embodiment
[0078] See also Figure 1 , shows a schematic flow chart of a grammar parsing method provided in an embodiment of the present application, which may include:
[0079] Step S101: Obtain a target sentence.
[0080] Optionally, the target sentence may be an English sentence. Of course, this embodiment is not limited thereto, and the target sentence may also be a sentence in other languages.
[0081] Step S102: parse the hierarchical grammatical structure information and inter-word dependency information of the target sentence using the pre-established grammatical parsing model, and generate a joint parsing tree that can simultaneously present the hierarchical grammatical structure information and inter-word dependency information of the target sentence based on the parsing result.
[0082] Among them, the grammatical parsing model is trained by using training sentences and the joint parse tree corresponding to the training sentences. The joint parse tree corresponding to the training sentences can simultaneously present the hierarchical grammatical structure information of the training sentences and the dependency relationship information between words.
[0083] See also Figure 2 , showing a flow chart of "using a pre-established grammar parsing model to parse the hierarchical grammatical structure information and inter-word dependency information of the target sentence" in step S102, which may include:
[0084] Step S201: taking the target sentence as the text to be parsed.
[0085] Step S202: using the grammatical parsing model, predicting the component labels of the text to be parsed, and predicting the segmentation method of the text to be parsed.
[0086] Among them, the component label of the text to be parsed is one of the set multiple component labels, and the component label of the text to be parsed is used to indicate what type of phrase the text to be parsed is. For example, if the component label of the text to be parsed is VP, it means that the text to be parsed is a verb phrase, and if the component label of the text to be parsed is NP, it means that the text to be parsed is a noun phrase.
[0087] Step S203: using the grammatical parsing model, predicting dependency relationship labels between text segments obtained after segmenting the text to be parsed according to the segmentation method of the text to be parsed.
[0088] Among them, the dependency relationship between text segments refers to the dependency relationship between a word in one text segment and a word in another text segment, that is, the dependency relationship actually refers to the dependency relationship between two words. It should be noted that, of the two words with a dependency relationship, one is the core word (head) and the other is the dependent word (dependent).
[0089] There are many types of dependency relationships: nominal clause modification, related clause modification, adverbial clause modification, clause complement, clause subject (including passive), open complement, etc.; adverbial modification, emphasis, place adverbial modification, adjective modification, preposition modification, noun modification (possessive, time, etc.), time modification, place modification, etc.; compound words (verbs, nouns, etc.), foreign words, quantifiers, possessive, pronoun reference, etc.; noun subject (including passive), object (time and space, etc.), auxiliary verb, passive voice auxiliary verb, etc.; root, coordinating conjunction, parallel, conjunction preposition, determiner, punctuation and other marks. The dependency label between two words is used to indicate the specific dependency relationship between the two words.
[0090] Step S204: for each text segment obtained by segmenting the text to be parsed according to the segmentation method of the text to be parsed, if the text segment includes multiple words, the text segment is used as the text to be parsed, and step S202 and subsequent steps are executed.
[0091] It should be noted that, for each text segment obtained by segmentation, if the text segment includes a word, the processing of the text segment can be terminated.
[0092] The above analysis process is explained below with reference to a specific example.
[0093] Assume that the text to be parsed is "Federal Paper Board sells paper and wood products.":
[0094] Take the text to be parsed "Federal Paper Board sells paper and wood products." as the text to be parsed and execute:
[0095] First, predict the component labels of "Federal Paper Board sells paper and wood products."; then, determine the segmentation method of "Federal Paper Board sells paper and wood products.", assuming the segmentation method is "Federal Paper Board / sells paper and wood products / .", then after segmentation according to this segmentation method, three text segments "Federal Paper Board", "sells paper and woodproducts" and "." are obtained; finally, predict the dependency syntactic relationship labels between the three text segments obtained by segmentation. It is predicted that "sells" in "sells paper and wood products" has a dependency relationship with "Board" in "Federal Paper Board", and the dependency relationship label is "nsubj". "nsubj" represents the noun subject, among which "sells" is the core word and "Board" is the dependent word. In addition, it is predicted that "sells" also has a dependency relationship with ".", and the dependency relationship label is "punct".
[0096] "Pun" means punctuation.
[0097] Since both "Federal Paper Board" and "sells paper and wood products" obtained by segmenting "Federal Paper Board sells paper and wood products." include multiple words, the text segment "Federal Paper Board" is further parsed as the text to be parsed, and the text segment "sells paper and wood products" is also further parsed as the text to be parsed. Take the parsing of the text segment "sells paper and wood products" as an example:
[0098] First, predict the component label of "sells paper and wood products". It is predicted that the component label of "sellspaper and wood products" is "VP"; then, predict the segmentation method of "sells paper and woodproducts". It is predicted that the segmentation method of "sells paper and wood products" is to segment after "sells", that is, "sells / paper and wood products". According to this segmentation method, two text segments "sells" and "paper and wood products" can be obtained; finally, predict the dependency relationship label of the words in "sells" and "paper and woodproducts". It is predicted that "sells" has a dependency relationship with the word "products" in "paper and wood products", and the dependency relationship label of "sells" and "products" is "obj", and "obj" means the object.
[0099] Since the text segment "paper and wood products" contains multiple words, it is necessary to further parse "paper and wood products" as the text to be parsed:
[0100] First, predict the component label of "paper and wood products". It is predicted that the component label of "paper and woodproducts" is "NP". Then, predict the segmentation method of "paper and wood products". It is predicted that the segmentation method of "paper and wood products" is "paper and wood / products". According to this segmentation method, two text segments "paper and wood" and "products" can be obtained. Finally, predict the dependency relationship label between the words in "paper and wood" and "products". It is predicted that "paper" and "products" have a dependency relationship, and the dependency relationship label between "paper" and "products" is "compound". "Compound" means a compound word.
[0101] Since the text segment "paper and wood" contains multiple words, it is necessary to further parse "paper and wood" as the text to be parsed:
[0102] First, predict the component label of "paper and wood"; then, predict the segmentation method of "paper and wood". It is predicted that the segmentation method of "paper and wood" is "paper / and / wood". According to this segmentation method, three text segments "paper", "and", and "wood" can be obtained; finally, predict the dependency relationship between the words "paper", "and", and "wood". It is predicted that "paper" and "wood" have a dependency relationship, and the dependency label is "conj:and". "conj:and" means a conjunction, and "and" and "wood" have a dependency relationship. The dependency label is "compound", and "compound" means a compound word. Since "paper", "and", and "wood" are all one word, the parsing of "sells paper and woodproducts" is completed. Preferably, if the text segment obtained by segmentation includes only one word, the part-of-speech tag of the word can be used as the component label of the word.
[0103] According to the above process, the sentence "Federal Paper Board sells paper and wood products." is parsed, and the hierarchical grammatical structure information of this sentence is finally obtained ( Figure 3 The hierarchical grammatical structure information shown in Figure 4 The dependency information between words shown in ).
[0104] After predicting the parsing results, a joint parsing tree may be generated according to the parsing results. Optionally, since the parsing is performed layer by layer (or from coarse granularity to fine granularity), the joint parsing tree may be gradually generated according to the continuous generation of parsing results.
[0105] In this embodiment, the joint parse tree that can simultaneously present the hierarchical grammatical structure information and the inter-word dependency information of the target sentence includes a number of leaf nodes and a number of non-leaf nodes, each leaf node represents a word in the target sentence, each non-leaf node represents a phrase in the target sentence, the next level of each non-leaf node is a leaf node and / or a non-leaf node, the information of each node includes the word or phrase represented by the node and the component label of the word or phrase represented by the node, nodes of different levels with a hierarchical relationship are connected by a first connecting line, and nodes of the same level with a dependency relationship are connected by a second connecting line (such as a directed arc), and each second connecting line has a dependency label. The joint parse tree vertically presents the hierarchical grammatical structure information of the target sentence, and the joint parse tree horizontally presents the inter-word dependency information of the target sentence.
[0106] See also Figure 5 , shows a schematic diagram of a joint parse tree obtained by parsing "Federal Paper Board sells paperand wood products." using a grammatical parsing model (dependency labels are not shown). The node marked (1,9) in the figure represents the phrase "Federal Paper Board sells paper and wood products.", and the "S" at the node is the component label of "Federal Paper Board sells paper and wood products.". The node marked (1,3) in the figure and the node marked (4,8) in the figure represent the phrases "Federal Paper Board" and "sells paper and wood products" obtained after segmentation according to the segmentation method "Federal Paper Board / sells paper and wood products.", respectively. The "NP" at the node marked (1,3) is the component label of the phrase "Federal Paper Board", and the "VP" at the node marked (4,8) is the component label of the phrase "Federal Paper Board". The directed arcs between nodes at the same level in the figure represent dependency relationships. For example, there is a directed arc between the node marked (1,3) and the node marked (4,8), indicating that "sells paper and wood products" There is a dependency relationship between "sells" in "products" and "Board" in "Federal Paper Board". The directed arc points from "sells" to "Board", indicating that "sells" is the core word and "Board" is the dependent word. The connecting lines between nodes at different levels represent the hierarchical relationship. For example, the node labeled (5,8) is the subordinate node of the node labeled (4,8), and the phrase represented by the node labeled (5,8) is the phrase obtained by segmenting the phrase represented by the node labeled (4,8).
[0107] The grammatical parsing method provided in the embodiment of the present application first obtains the target sentence, then uses the pre-established grammatical parsing model to parse the hierarchical grammatical structure information and word dependency information of the target sentence, and generates a joint parse tree that can simultaneously present the hierarchical grammatical structure information and word dependency information of the target sentence according to the parsing result. The grammatical parsing method provided in the embodiment of the present application can parse out more detailed grammatical information of the target sentence.
[0108] Second embodiment
[0109] This embodiment introduces the specific implementation process of "Step S202: using the grammatical parsing model to predict the component labels of the text to be parsed, and predicting the segmentation method of the text to be parsed" and "Step S203: using the grammatical parsing model to predict the dependency relationship labels between text segments obtained after segmenting the text to be parsed according to the segmentation method" in the above embodiment.
[0110] See also Figure 6 , shows a flow chart of using a grammar parsing model to predict component labels of a text to be parsed and predicting a segmentation method of the text to be parsed, which may include:
[0111] Step S601: using the grammatical parsing model, predicting the probability that the component labels of the text to be parsed are the set component labels, and determining the component labels of the text to be parsed according to the probability that the component labels of the text to be parsed are the set component labels.
[0112] The process of predicting the probability that the component labels of the text to be parsed are the set component labels may include:
[0113] Step S6011, determine the representation vector of the text to be parsed according to the forward vector of the first word, the forward vector of the backward adjacent word of the second word, the backward vector of the second word and the backward vector of the forward adjacent word of the first word.
[0114] Among them, the first word is the first word of the text to be parsed, the second word is the last word of the text to be parsed, the forward adjacent word of the first word is the word that is located before and adjacent to the first word in the target sentence, and the backward adjacent word of the second word is the word that is located after and adjacent to the second word in the target sentence. It should be noted that the forward vector of a word can represent the semantics of the word when the target sentence is reviewed from front to back, and the backward vector of a word can represent the semantics of the word when the target sentence is reviewed from back to front.
[0115] The forward and backward vectors for each word in the target sentence can be obtained as follows:
[0116] Step a1: For each word x in the target sentence i :Use the grammar parsing model to obtain the word x i The word vector, part-of-speech representation vector and position representation vector of the word x i The part-of-speech representation vector of the word is summed with the position representation vector of the word, and the summed vector is added to the word x i The word vectors of the word are concatenated and the concatenated vector is used as the word x i to obtain the representation vector of each word in the text to be parsed.
[0117] Among them, the word vector of each word in the target sentence can be determined by a pre-trained language model. When determining the word vector of each word in the target sentence, the target sentence is first pre-processed, wherein the pre-processing includes but is not limited to adding spaces before punctuation marks, replacing the negative form of 't with not, unifying upper and lower case, etc., and then the pre-processed sentence is segmented. Finally, each word obtained by the word segmentation is input into the pre-trained language model, and the pre-trained language model outputs the word vector of each word in the target sentence. After obtaining the word vector of each word in the target sentence, the word vector of each word in the target sentence can be input into the pre-trained part-of-speech tag model, and the part-of-speech tag model outputs the part-of-speech tag of each word in the target sentence. Optionally, the part-of-speech tag model can include a bidirectional LSTM (or a neural network structure of any time sequence) and a fully connected layer, such as Figure 7 As shown in the figure, the word vector of each word in the target sentence is sequentially passed through a bidirectional LSTM (or a neural network structure of any time sequence) and a fully connected layer to obtain the part-of-speech tag of each word in the target sentence.
[0118] See also Figure 8 , shows the part-of-speech tags of each word in the target sentence "Federal Paper Boardsells paper and wood products." predicted by the part-of-speech tagging model, Figure 8 The part-of-speech tags in represent:
[0119] NNP:Proper noun, singular (proper noun, singular);
[0120] VBZ:Verb, 3rd person singular present (verb, third person, singular);
[0121] NN:Noun, singular or mass;
[0122] NNS:Noun,plural (noun, plural);
[0123] CC:Coordinating conjunction (coordinating, conjunction).
[0124] Optionally, the grammatical parsing model in this embodiment may include an embedding layer, for each word x in the target sentence i , the embedding layer of the grammar parsing model obtains the word x output by the pre-trained language model i The word vector of the word x is obtained by the part-of-speech tagging model. i The representation vector of the part of speech represented by the part of speech tag of i The position representation vector of word xi The part-of-speech representation vector of word x i The position representation vectors are summed and the summed vector is added to the word x i The word vectors of are concatenated to get the word x i The representation vector of .
[0125] Step a2: For each word x in the target sentence i :Use the grammar parsing model to analyze word x i The representation vector of the target sentence and the representation vectors of other words are used for attention calculation to obtain the word x i The context vector of word x i The context vector of word x is obtained i The forward and backward vectors of .
[0126] In one possible implementation, the word x can be centered based on a single-head self-attention mechanism. i The representation vector of the target sentence and the representation vectors of other words in the target sentence are used for attention calculation. In this way, a context vector can be obtained, and the context vector is split into a forward vector and a backward vector. The forward vector obtained by the splitting is used as the word x i The forward vector of , and the backward vector obtained by segmentation is used as the word x i In another possible implementation, the word x can be centered based on a multi-head self-attention mechanism. i The representation vector of the target sentence and the representation vectors of other words in the target sentence are used for attention calculation. In this way, multiple context vectors can be obtained. Each context vector is divided into a forward vector and a backward vector. All the forward vectors are concatenated and the concatenated vector is used as the word x. i Similarly, all the backward vectors are concatenated and the concatenated vector is used as the word x i The backward vector of .
[0127] Specifically, the process of determining the representation vector of the text to be parsed based on the forward vector of the first word, the forward vector of the backward adjacent word of the second word, the backward vector of the second word and the backward vector of the forward adjacent word of the first word includes: subtracting the forward vector of the first word from the forward vector of the backward adjacent word of the second word to obtain a forward vector difference, and subtracting the backward vector of the second word from the backward vector of the forward adjacent word of the first word to obtain a backward vector difference; splicing the forward vector difference and the backward vector difference, and using the spliced vector as the representation vector of the text to be parsed.
[0128] If the first word is replaced by x i (the first word in the text to be parsed, the i-th word in the target sentence), and the second word is represented by x j(the last word in the text to be parsed, the jth word in the target sentence) means that the first word x i The forward vector of It means that the second word x j The backward vector of Indicates that the first word x i The forward neighboring word x i-1 The backward vector of It means that the second word x j The backward adjacent word x j+1 The forward vector of Represents, then the representation vector S of the text to be parsed ij It can be expressed as:
[0129]
[0130] Step S6012: predict the probability of the component labels of the text to be parsed being the set component labels according to the representation vector of the text to be parsed.
[0131] Specifically, the probability s that the component label of the text to be parsed is the set component label can be determined using the following formula: labels (i, j):
[0132] s labels (i, j) = V l g(W l s ij +b l ) (2)
[0133] Among them, g represents nonlinear transformation, W l and b l are the parameters of the grammar parsing model, which are obtained through training.
[0134] After predicting the probability that the component label of the text to be parsed is the set component label, the component label corresponding to the maximum probability among the predicted probabilities is determined as the component label of the text to be parsed.
[0135] Step S602: using the grammar parsing model, predicting the scores of the candidate segmentation methods of the text to be parsed, and determining the segmentation method of the text to be parsed according to the scores of the candidate segmentation methods of the text to be parsed.
[0136] The candidate segmentation methods of the text to be parsed are all possible segmentation methods of the text to be parsed. The process of predicting the scores of the candidate segmentation methods of the text to be parsed includes:
[0137] For each candidate segmentation method of the text to be parsed, execute:
[0138] Step S6021: predict the probability that each text segment obtained by segmenting the to-be-parsed text according to the candidate segmentation method is a phrase component, so as to obtain the probabilities corresponding to each text segment obtained by segmenting according to the candidate segmentation method.
[0139] Specifically, for each text segment obtained by segmenting the text to be parsed according to the candidate segmentation method: determine the representation vector of the text segment based on the forward vector of the first word of the text segment, the forward vector of the backward adjacent word of the last word of the text segment, the backward vector of the last word of the text segment, and the backward vector of the forward adjacent word of the first word of the text segment, and determine the probability that the text segment is a phrase component based on the representation vector of the text segment. It should be noted that the method of determining the representation vector of a text segment here is similar to the implementation method of determining the representation vector of the text to be parsed mentioned above. For a more specific implementation method of determining the representation vector of a text segment, please refer to the specific implementation method of determining the representation vector of the text to be parsed, which will not be repeated in this embodiment.
[0140] The probability of a text segment being a phrase component can be determined by the following formula:
[0141] s span (m, n) = V s g(W s s mn +b s ) (3)
[0142] Among them, s mn Represents the representation vector of the text segment consisting of the mth to nth words in the text to be parsed, s span (m, n) represents the probability that the text segment consisting of the mth to nth words in the text to be parsed is a phrase component, W s and b s are the parameters of the grammar parsing model, which are obtained through training.
[0143] Step S6022: sum the probabilities corresponding to the text segments obtained by segmenting the candidate segmentation method, and use the summed probability as the score of the candidate segmentation method.
[0144] Assume that the text to be parsed is segmented according to a candidate segmentation method k to obtain multiple text segments x i ~x k1 、x k1+1 ~x k2 , …, x kn ~x j , then the text segment x can be obtained through step S6021 i ~x k1 The corresponding probability s span (i, k1), text segment xk1+1 ~x k2 The corresponding probability s span (k1+1, k2), ..., text segment x kn ~x j The corresponding probability s span (kn, j), after obtaining the probabilities corresponding to each text segment, the probabilities corresponding to each text segment can be summed up, and the summed probability is used as the score of the candidate segmentation method k, that is, the score s of the candidate segmentation method k split (i, k, j) can be expressed as:
[0145] s split (i, k, j) = s span (i,k1)+s span (k1+1,k2)+...+s span (kn, j) (4)
[0146] The scores of the candidate segmentation methods for the text to be parsed can be obtained through the above process. After the scores of the candidate segmentation methods for the text to be parsed are obtained, the candidate segmentation method with the highest score can be determined as the segmentation method for the text to be parsed.
[0147] Optionally, the grammatical parsing model in this embodiment may include a component syntactic analysis unit, and the component syntactic analysis unit of the grammatical parsing model may be used to determine the component labels and segmentation method of the text to be parsed in the above manner.
[0148] Next, the implementation process of "step S203: using the grammatical parsing model to predict dependency relationship labels between text segments obtained after segmenting the text to be parsed according to the segmentation method of the text to be parsed" is introduced.
[0149] See also Fig. 9 , shows a flow chart of using a grammar parsing model to predict dependency labels between text segments obtained after segmenting the text to be parsed according to the segmentation method of the text to be parsed, which may include:
[0150] Step S901: using the grammar parsing model, predicting the scores of the candidate arc drawing methods of the text segment obtained after segmenting the text to be parsed according to the segmentation method of the text to be parsed, and determining the target arc drawing method according to the scores of the candidate arc drawing methods.
[0151] Each arc drawn according to each candidate arc drawing method is a directed arc from a word in one text segment to a word in another text segment. It should be noted that the arc drawing in this embodiment refers to drawing a directed arc for two words that may have a dependency relationship, and the directed arc points from the core word to the dependent word. It should also be noted that the arcs under the same candidate arc drawing method should not cross. Please refer to Fig.10, a schematic diagram showing two candidate arc drawing methods for three text segments.
[0152] Among them, the process of predicting the score of a candidate arc drawing method of a text segment obtained after segmenting the text to be parsed according to the segmentation method of the text to be parsed includes: for each arc drawn according to the candidate arc drawing method, obtaining the characterization vector of the arc, determining the score of the arc according to the characterization vector of the arc, so as to obtain the score of each arc drawn according to the candidate arc drawing method; summing the scores of the arcs drawn according to the candidate arc drawing method, and using the summed score as the score of the candidate arc drawing method. The scores of each candidate arc drawing method can be obtained in the above manner, and after obtaining the scores of each candidate arc drawing method, the candidate arc drawing method with the highest score can be determined as the target arc drawing method.
[0153] Among them, the process of determining the representation vector of an arc may include: obtaining one or more of the following features of the two words connected by the arc: word-level features, distance features, sentence-level features (preferably, these three features are obtained at the same time); determining the representation vector of the arc based on the obtained features, specifically, the obtained features can be input into a fully connected layer, and the output of the fully connected layer is used as the representation vector of the arc.
[0154] In this embodiment, the target vector (the concatenated vector of the forward vector and the backward vector) of each word in the target sentence can be input into BiLSTM to obtain the word-level features of each word in the target sentence. For two words connected by an arc, the word-level features of the two words connected by the arc can be obtained from the word-level features of each word in the target sentence.
[0155] The distance feature of two words connected by an arc can represent the distance between the two words. Optionally, if there is no other word between the two words connected by an arc, the distance between the two words connected by the arc is considered to be "1", and "1" is represented as a vector as the distance feature of the two words connected by the arc. If there is a word between the two words connected by the arc, the distance between the two words connected by the arc is determined to be "2", and "2" is represented as a vector as the distance feature of the two words connected by the arc, and so on.
[0156] The sentence-level features of two words connected by an arc can be obtained in the following way: using the two words connected by the arc as the dividing line, divide the target sentence into three parts, and obtain the representation vector of the first part and the representation vector of the last part obtained by the division according to the target vector of each word in the target sentence (the concatenation vector of the forward vector and the backward vector); subtract the representation vector of the last part from the representation vector of the first part, and the obtained vector is used as the sentence-level feature of the two words connected by the arc. Optionally, the target vector of each word in the target sentence can be first input into BiLSTM, and then the output of BiLSTM can be input into LSTM to obtain the representation vector of the first part and the representation vector of the last part.
[0157] Step S902: For each arc in the target arc drawing mode, the grammatical parsing model is used to predict the probability that the dependency tags of the two words connected by the arc are the set dependency tags, and the dependency tags of the two words connected by the arc are determined according to the probability that the dependency tags of the two words connected by the arc are the set dependency tags.
[0158] The process of predicting the probability that the dependency labels of the two words connected by the arc are the set dependency labels may include: predicting the probability that the dependency labels of the two words connected by the arc are the set dependency labels based on the representation vector of the arc. Specifically, the representation vector of the arc may be passed through a nonlinear layer and a fully connected layer to obtain the probability that the dependency labels of the two words connected by the arc are the set dependency labels.
[0159] After predicting the probability that the dependency labels of the two words connected by the arc are the set dependency labels, the dependency label corresponding to the maximum probability is determined as the dependency label of the two words connected by the arc.
[0160] Optionally, the grammatical parsing model in this embodiment may include a dependency syntactic analysis unit, and the dependency syntactic analysis unit of the grammatical parsing model may be used to predict the dependency relationship labels between text segments obtained after the text to be parsed is segmented according to the segmentation method of the text to be parsed in the above manner.
[0161] Third embodiment
[0162] Through the implementation method provided by the above embodiment, a joint parse tree that can simultaneously present the hierarchical grammatical structure information and the inter-word dependency information of the target sentence can be obtained. Optionally, after obtaining the joint parse tree, the joint parse tree can be directly output, or part of the information presented by the joint parse tree can be output. For example, the hierarchical grammatical structure information presented by the joint parse tree is output, or the inter-word dependency information presented by the joint parse tree is output. Optionally, when outputting the hierarchical grammatical structure information, a hierarchical phrase set and / or tree structure can be output so that the user can more quickly understand the structure and hierarchical relationship of the target sentence. When outputting the inter-word dependency information, the dependency type (i.e., dependency label) involved in the target sentence can be output, and word pairs with dependencies and dependency labels of word pairs with dependencies can also be output.
[0163] In addition to information output, the parsed information can be further processed. For example, for noun phrases obtained through parsing, proper nouns can be determined based on the part-of-speech tags output by the part-of-speech tagging model. For verb phrases, fixed collocations that match the verb phrases can be searched for, etc.
[0164] In addition, the part-of-speech tags output by the part-of-speech tagging model can also be output and interpreted. The possible parts of speech output are:
[0165] Nouns: singular and plural, proper nouns, foreign nouns, personal names, possessive nouns;
[0166] Verbs: singular and plural, past tense, past participle, gerund, modal verbs;
[0167] adjective adverb, prototype, comparative, superlative;
[0168] Others: conjunctions, ordinal numbers, prepositions, possessive pronouns, interjections, EX (existence there), to, special symbols, adverbs beginning with wh, possessive nouns, etc.
[0169] In addition, the verb changes obtained by the part-of-speech tagging model can be marked with the original form of the verb through a large English resource library or a natural language processing toolkit, and the original form and the inflected form in the sentence can be output together.
[0170] Furthermore, based on the word vector of the word in the target sentence, synonyms, similar words, related words, etc. of the word in the target sentence can be obtained in the corpus, so as to use extended knowledge to help users quickly understand unfamiliar and difficult words.
[0171] Fourth embodiment
[0172] It can be seen from the above embodiments that the grammatical parsing of the target sentence is implemented using a pre-established grammatical parsing model, and the grammatical parsing model is trained using training sentences and a joint parse tree corresponding to the training sentences. This embodiment focuses on introducing the training process of the grammatical parsing model.
[0173] See also Fig.11 , shows a schematic diagram of a process of training a grammar parsing model using a training sentence and a joint parse tree corresponding to the training sentence, which may include:
[0174] Step S1101: Obtain training text, and use the training text as the text to be parsed.
[0175] Step S1102: using the grammatical parsing model to predict the probability of the component labels of the text to be parsed being the set component labels and the scores of the candidate segmentation methods of the text to be parsed as the first prediction result.
[0176] It should be noted that the implementation process of using the grammatical parsing model to predict the probability of the component labels of the text to be parsed being the set component labels and the scores of the candidate segmentation methods of the text to be parsed in this embodiment is similar to the implementation process of using the grammatical parsing model to predict the probability of the component labels of the text to be parsed being the set component labels and the scores of the candidate segmentation methods of the text to be parsed in the above-mentioned embodiments. For details, please refer to the relevant parts in the above-mentioned embodiments, and this embodiment will not be elaborated here.
[0177] Step S1103: For each candidate segmentation method of the text to be parsed, predict the scores of each candidate arc drawing method of the text segment obtained by segmenting the text to be parsed according to the candidate segmentation method, and the probability that the dependency labels of the two words connected by each arc under each candidate arc drawing method are the set dependency labels, so as to obtain the prediction results under each candidate segmentation method as the second prediction results.
[0178] It should be noted that the implementation process of predicting the scores of each candidate arc drawing method of the text segment obtained by segmenting the text to be parsed according to a candidate segmentation method in this embodiment is similar to the implementation process of predicting the scores of each candidate arc drawing method of the text segment obtained by segmenting the text to be parsed according to the segmentation method of the text to be parsed in the above embodiment. The implementation process of predicting the probability that the dependency labels of two words connected by each arc under the candidate arc drawing method are the set dependency labels is similar to the implementation process of predicting the probability that the dependency labels of two words connected by each arc under the target arc drawing method are the set dependency labels in the above embodiment, which will not be elaborated in this embodiment.
[0179] Step S1104: update the parameters of the grammatical parsing model according to the first prediction result, the second prediction result and the relevant part of the joint parsing tree corresponding to the training text.
[0180] Specifically, the process of updating the parameters of the grammar parsing model according to the first prediction result, the second prediction result and the relevant part of the joint parsing tree corresponding to the training text includes:
[0181] Step S1104-1: Determine a first prediction loss of a grammatical parsing model according to a first prediction result and a relevant portion of hierarchical grammatical structure information presented by a joint parse tree corresponding to a training text.
[0182] Optionally, a cross entropy loss may be calculated based on the first prediction result and the relevant part of the hierarchical grammatical structure information presented by the joint parse tree corresponding to the training text as the first prediction loss of the grammatical parsing model. The calculation method of the cross entropy loss is a prior art and will not be described in detail in this embodiment.
[0183] Step S1104-2: Determine a second prediction loss of the grammatical parsing model according to the second prediction result and the relevant part of the inter-word dependency information presented by the joint parse tree corresponding to the training text.
[0184] Optionally, a cross entropy loss may be calculated based on a relevant portion of the inter-word dependency information presented by the joint parse tree corresponding to the second prediction result and the training text as the second prediction loss of the grammatical parsing model.
[0185] Step S1104-3: merge the first prediction loss and the second prediction loss, and update the parameters of the grammar parsing model according to the merged loss.
[0186] There are many ways to fuse the first prediction loss with the second prediction loss. In one possible implementation, the first prediction loss and the second prediction loss can be directly summed. In another possible implementation, the first prediction loss and the second prediction loss can be weighted and summed. If the first prediction loss is represented as LOSS1 and the second prediction loss is represented as LOSS2, the fused loss obtained by the first method is LOSS1+LOSS1, and the fused loss obtained by the second method is α*LOSS1+βLOSS2, where α is the weight corresponding to the first prediction loss LOSS1, and β is the weight corresponding to the second prediction loss LOSS2. α and β can be set according to actual conditions.
[0187] Step S1105: For each text segment obtained by segmenting according to each candidate segmentation method, if the text segment includes one word, the processing of the text segment is terminated; if the text segment includes multiple words, the text segment is treated as the text to be parsed and the process proceeds to step S1102; if the text segment includes one word, the processing of the text segment is terminated.
[0188] The grammar parsing model is iteratively trained multiple times according to the above process until the training end condition is met. The model obtained after the training is completed is the established grammar parsing model.
[0189] Fifth embodiment
[0190] The embodiment of the present application further provides a grammatical parsing device. The grammatical parsing device provided by the embodiment of the present application is described below. The grammatical parsing device described below and the grammatical parsing method described above can be referenced to each other.
[0191] See also Fig.12 , shows a schematic diagram of the structure of the grammar parsing device provided in an embodiment of the present application, which may include: a text acquisition module 1201 and a grammar parsing module 1202.
[0192] The text acquisition module 1201 is used to acquire the target sentence.
[0193] The grammar parsing module 1202 is used to parse the hierarchical grammar structure information and the inter-word dependency information of the target sentence using a pre-established grammar parsing model, and generate a joint parse tree that can simultaneously present the hierarchical grammar structure information and the inter-word dependency information of the target sentence according to the parsing result. The grammar parsing model is trained using training sentences and the joint parse tree corresponding to the training sentences.
[0194] Optionally, the grammar parsing module 1202, when parsing the hierarchical grammar structure information and the inter-word dependency information of the target sentence using a pre-established grammar parsing model, is specifically configured to:
[0195] Taking the target sentence as the text to be parsed, using a pre-established grammar parsing model to predict component labels of the text to be parsed, and predicting a segmentation method for the text to be parsed;
[0196] Using a pre-established grammar parsing model, predicting dependency relationship labels between text segments obtained after segmenting the text to be parsed according to the segmentation method;
[0197] For each segmented text segment, if the text segment includes multiple words, the text segment is used as the text to be parsed, and the component labels of the text to be parsed are predicted using the pre-established grammar parsing model and subsequent steps are performed.
[0198] Optionally, the joint parsing tree includes several leaf nodes and several non-leaf nodes, each leaf node represents a word in the target sentence, each non-leaf node represents a phrase in the target sentence, the next level of each non-leaf node is a leaf node and / or a non-leaf node, and the information of each node includes the word or phrase represented by the node and the component label of the word or phrase represented by the node; nodes of different levels with a hierarchical relationship are connected by a first connecting line, and nodes of the same level with a dependency relationship are connected by a second connecting line, and each second connecting line has a dependency relationship label.
[0199] Optionally, when the grammar parsing module 1202 predicts the component labels of the text to be parsed using the grammar parsing model, it is specifically used to:
[0200] The grammatical parsing model is used to predict the probability that the component labels of the text to be parsed are the set component labels, and the component labels of the text to be parsed are determined according to the probability that the component labels of the text to be parsed are the set component labels;
[0201] When the grammar parsing module 1202 predicts the segmentation method of the text to be parsed using the grammar parsing model, it is specifically used to:
[0202] The grammar parsing model is used to predict the scores of each candidate segmentation method of the text to be parsed, and the segmentation method of the text to be parsed is determined according to the scores of each candidate segmentation method of the text to be parsed.
[0203] Optionally, the syntax parsing module 1202 predicts the probability of the component labels of the text to be parsed being the set component labels by using the syntax parsing model, including:
[0204] Determine a representation vector of the text to be parsed by using a grammatical parsing model according to a forward vector of a first word, a forward vector of a backward adjacent word of a second word, a backward vector of the second word, and a backward vector of a forward adjacent word of the first word, wherein the first word is the first word of the text to be parsed, the second word is the last word of the text to be parsed, the forward vector of a word can represent the semantics of the word when the target sentence is examined from front to back, and the backward vector of a word can represent the semantics of the word when the target sentence is examined from back to front;
[0205] The grammatical parsing model is used to predict the probability of the component labels of the text to be parsed being the set component labels based on the representation vector of the text to be parsed.
[0206] Optionally, the grammar parsing module 1202 determines the representation vector of the text to be parsed by using the grammar parsing model according to the forward vector of the first word, the forward vector of the backward adjacent word of the second word, the backward vector of the second word, and the backward vector of the forward adjacent word of the first word, including:
[0207] Using the grammatical parsing model, the forward vector of the first word is subtracted from the forward vector of the backward adjacent word of the second word to obtain a forward vector difference, and the backward vector of the second word is subtracted from the backward vector of the forward adjacent word of the first word to obtain a backward vector difference, and the forward vector difference and the backward vector difference are spliced, and the spliced vector is used as the representation vector of the text to be parsed.
[0208] Optionally, the grammar parsing module 1202 is further used for:
[0209] For each word in the target sentence: using the grammatical parsing model to obtain the word vector, part-of-speech representation vector and position representation vector of the word, summing the part-of-speech representation vector of the word with the position representation vector of the word, and concatenating the summed vector with the word vector of the word, and using the concatenated vector as the representation vector of the word; to obtain the representation vector of each word in the target sentence;
[0210] The grammatical parsing model is used to perform attention calculation on the representation vector of the word and the representation vectors of other words in the target sentence to obtain the context vector of the word, and the forward vector and backward vector of the word are obtained according to the context vector of the word.
[0211] Optionally, when the grammar parsing module 1202 predicts the scores of each candidate segmentation method of the text to be parsed by using the grammar parsing model, it is specifically used to:
[0212] For each candidate split method:
[0213] The grammatical parsing model is used to predict the probability that each text segment obtained by segmenting the text to be parsed according to the candidate segmentation method is a phrase component, so as to obtain the probability corresponding to each text segment, and the probabilities corresponding to each text segment are summed up, and the summed probability is used as the score of the candidate segmentation method;
[0214] To obtain the scores of each candidate segmentation method for the text to be parsed.
[0215] Optionally, when the grammar parsing module 1202 uses the grammar parsing model to predict the dependency relationship labels between the text segments obtained after segmenting the text to be parsed according to the segmentation method, it is specifically used to:
[0216] The grammatical parsing model is used to predict the scores of each candidate arc drawing method of the text segment obtained after segmenting the text to be parsed according to the segmentation method, and the target arc drawing method is determined according to the scores of each candidate arc drawing method, wherein each arc under each candidate arc drawing method is a directed arc from a word in one text segment to a word in another text segment;
[0217] For each arc under the target arc drawing method, the grammatical parsing model is used to predict the probability that the dependency labels of the two words connected by the arc are the set dependency labels, and the dependency labels of the two words connected by the arc are determined according to the probability that the dependency labels of the two words connected by the arc are the set dependency labels.
[0218] Optionally, when the grammar parsing module 1202 uses the grammar parsing model to predict the probability that the dependency labels of the two words connected by the arc are set dependency labels, it is specifically used to:
[0219] Using the grammatical parsing model, one or more of the following features of the two words connected by the arc are obtained: word-level features, distance features, and sentence-level features. The representation vector of the arc is determined based on the obtained features. Based on the representation vector of the arc, the probability that the dependency labels of the two words connected by the arc are the set dependency labels is predicted.
[0220] Optionally, when the grammar parsing module 1202 uses the grammar parsing model to obtain the sentence-level features of the two words connected by the arc, it is specifically used to:
[0221] The grammatical parsing model is used to obtain the representation vector of the first part and the representation vector of the last part of the three parts obtained by dividing the text to be parsed with the two words connected by the arc as the dividing line, and the representation vector of the last part is subtracted from the representation vector of the first part, and the vector obtained by the difference is used as the sentence-level feature of the two words connected by the arc.
[0222] The grammar parsing device provided in the embodiment of the present application may further include: a model training module. The model training module is used to:
[0223] The training text is used as the text to be parsed, and the grammar parsing model is used to predict the probability that the component labels of the text to be parsed are the set component labels and the scores of each candidate segmentation method of the text to be parsed as the first prediction result;
[0224] For each candidate segmentation method of the text to be parsed, predict the scores of each candidate arc drawing method of the text segment obtained by segmenting the text to be parsed according to the candidate segmentation method, and the probability that the dependency labels of two words connected by each arc under each candidate arc drawing method are set dependency labels, so as to obtain the prediction results under each candidate segmentation method as the second prediction results;
[0225] updating parameters of a grammar parsing model according to the first prediction result, the second prediction result, and a relevant part of a joint parse tree corresponding to the training text;
[0226] For each text segment obtained by segmenting according to each candidate segmentation method, if the text segment includes multiple words, the text segment is used as the text to be parsed, and the method of using the grammatical parsing model to predict the component labels of the text to be parsed as the probability of each set component label and the score of each candidate segmentation method of the text to be parsed is executed.
[0227] Optionally, when the model training module updates the parameters of the grammatical parsing model according to the first prediction result, the second prediction result and the relevant part of the joint parse tree corresponding to the training text, it is specifically used to:
[0228] Determining a first prediction loss of a grammatical parsing model according to a relevant portion of the hierarchical grammatical structure information presented by the first prediction result and the joint parse tree corresponding to the training text;
[0229] Determining a second prediction loss of the grammatical parsing model according to a relevant portion of the inter-word dependency information presented by the second prediction result and the joint parse tree corresponding to the training text;
[0230] The first prediction loss and the second prediction loss are fused, and parameters of the grammatical parsing model are updated according to the fused loss.
[0231] The grammar parsing device provided in the embodiment of the present application first obtains the target sentence, and then uses the pre-established grammar parsing model to parse the hierarchical grammar structure information and word dependency information of the target sentence, and generates a joint parsing tree that can simultaneously present the hierarchical grammar structure information and word dependency information of the target sentence according to the parsing result. The grammar parsing device provided in the embodiment of the present application can parse out more detailed grammar information of the target sentence.
[0232] Sixth embodiment
[0233] The present application also provides a grammar parsing device. Fig.13, showing a schematic diagram of the structure of the grammar parsing, the grammar parsing may include: at least one processor 1301, at least one communication interface 1302, at least one memory 1303 and at least one communication bus 1304;
[0234] In the embodiment of the present application, the number of the processor 1301, the communication interface 1302, the memory 1303, and the communication bus 1304 is at least one, and the processor 1301, the communication interface 1302, and the memory 1303 communicate with each other through the communication bus 1304;
[0235] The processor 1301 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention;
[0236] The memory 1303 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory;
[0237] The memory stores a program, and the processor can call the program stored in the memory, wherein the program is used to:
[0238] Get the target sentence;
[0239] Using a pre-established grammatical parsing model, parsing the hierarchical grammatical structure information and the inter-word dependency relationship information of the target sentence, and generating a joint parsing tree that can simultaneously present the hierarchical grammatical structure information and the inter-word dependency relationship information of the target sentence according to the parsing result;
[0240] The grammatical parsing model is obtained by training using training sentences and a joint parsing tree corresponding to the training sentences.
[0241] Optionally, the detailed functions and extended functions of the program may refer to the above description.
[0242] Seventh embodiment
[0243] The embodiment of the present application further provides a readable storage medium, which may store a program suitable for execution by a processor, wherein the program is used to:
[0244] Get the target sentence;
[0245] Using a pre-established grammatical parsing model, parsing the hierarchical grammatical structure information and the inter-word dependency relationship information of the target sentence, and generating a joint parsing tree that can simultaneously present the hierarchical grammatical structure information and the inter-word dependency relationship information of the target sentence according to the parsing result;
[0246] The grammatical parsing model is obtained by training using training sentences and a joint parsing tree corresponding to the training sentences.
[0247] Optionally, the detailed functions and extended functions of the program may refer to the above description.
[0248] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0249] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0250] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A syntax parsing method, characterized in that: include: Get the target sentence; Using a pre-established grammatical parsing model, the target sentence is parsed layer by layer to obtain hierarchical grammatical structure information and inter-word dependency information of the target sentence, and a joint parsing tree capable of simultaneously presenting the hierarchical grammatical structure information and inter-word dependency information of the target sentence is generated according to the parsing result; The parsing object of the first layer is the target sentence, and the parsing result of the first layer includes the component labels of the parsing object of the layer, and the parsing objects of each other layer include the text segments obtained by segmenting the parsing object of the previous layer, and the parsing results of each other layer include the component labels of each text segment contained in the parsing object of the layer and the dependency relationship information between different text segments; The grammatical parsing model is obtained by training using training sentences and a joint parsing tree corresponding to the training sentences.
2. The grammar parsing method according to claim 1, characterized in that: The step of parsing the target sentence layer by layer to obtain hierarchical grammatical structure information and inter-word dependency information of the target sentence includes: Taking the target sentence as the text to be parsed, predicting the component labels of the text to be parsed, and predicting the segmentation method of the text to be parsed; Predicting dependency relationship labels between text segments obtained after segmenting the text to be parsed according to the segmentation method; For each segmented text segment, if the text segment includes multiple words, the text segment is used as the text to be parsed, and the component labels of the text to be parsed and subsequent steps are performed.
3. The grammar parsing method according to claim 2, characterized in that: The joint parse tree includes a plurality of leaf nodes and a plurality of non-leaf nodes, each leaf node represents a word in the target sentence, each non-leaf node represents a phrase in the target sentence, the next level of each non-leaf node is a leaf node and / or a non-leaf node, and the information of each node includes the word or phrase represented by the node and the component label of the word or phrase represented by the node; Nodes at different levels with a hierarchical relationship are connected through a first connection line, and nodes at the same level with a dependency relationship are connected through a second connection line, and each second connection line has a dependency relationship label.
4. The grammar analysis method according to claim 2, characterized in that: The step of predicting the component labels of the text to be parsed includes: Predicting the probability that the component labels of the text to be parsed are the set component labels, and determining the component labels of the text to be parsed according to the probability that the component labels of the text to be parsed are the set component labels; The method of predicting the segmentation of the text to be parsed includes: The scores of the candidate segmentation methods for the text to be parsed are predicted, and the segmentation method for the text to be parsed is determined according to the scores of the candidate segmentation methods for the text to be parsed.
5. The grammar parsing method according to claim 4, characterized in that: The predicted component labels of the text to be parsed are the probabilities of the set component labels, including: Determine a representation vector of the text to be parsed according to a forward vector of a first word, a forward vector of a backward adjacent word of a second word, a backward vector of the second word, and a backward vector of a forward adjacent word of the first word, wherein the first word is the first word of the text to be parsed, the second word is the last word of the text to be parsed, the forward vector of a word can represent the semantics of the word when the target sentence is examined from front to back, and the backward vector of a word can represent the semantics of the word when the target sentence is examined from back to front; According to the representation vector of the text to be parsed, the probability that the component label of the text to be parsed is each set component label is predicted.
6. The grammar analysis method according to claim 5, characterized in that: The step of determining a representation vector of the text to be parsed according to the forward vector of the first word, the forward vector of the backward adjacent word of the second word, the backward vector of the second word, and the backward vector of the forward adjacent word of the first word comprises: Subtracting the forward vector of the first word from the forward vector of the backward adjacent word of the second word to obtain a forward vector difference, and subtracting the backward vector of the second word from the backward vector of the forward adjacent word of the first word to obtain a backward vector difference; The forward vector difference is concatenated with the backward vector difference, and the concatenated vector is used as a representation vector of the text to be parsed.
7. The grammar parsing method according to claim 6, characterized in that: The process of obtaining the forward vector and the backward vector of a word in the target sentence includes: For each word in the target sentence: using the grammatical parsing model to obtain the word vector, part-of-speech representation vector and position representation vector of the word, summing the part-of-speech representation vector of the word with the position representation vector of the word, and concatenating the summed vector with the word vector of the word, and using the concatenated vector as the representation vector of the word; to obtain the representation vector of each word in the target sentence; The grammatical parsing model is used to perform attention calculation on the representation vector of the word and the representation vectors of other words in the target sentence to obtain the context vector of the word, and the forward vector and backward vector of the word are obtained according to the context vector of the word.
8. The grammar parsing method according to claim 3, characterized in that: The predicted scores of the candidate segmentation methods of the text to be parsed include: For each candidate split method: Predict the probability that each text segment obtained by segmenting the text to be parsed according to the candidate segmentation method is a phrase component, so as to obtain the probability corresponding to each text segment; The probabilities corresponding to the text segments are summed up, and the summed probability is used as the score of the candidate segmentation method; To obtain the scores of each candidate segmentation method for the text to be parsed.
9. The grammar parsing method according to claim 2, characterized in that: The predicting of dependency labels between text segments obtained after segmenting the text to be parsed according to the segmentation method includes: Predicting scores of candidate arc drawing methods of a text segment obtained after segmenting the text to be parsed according to the segmentation method, and determining a target arc drawing method according to the scores of the candidate arc drawing methods, wherein each arc under each candidate arc drawing method is a directed arc from a word in one text segment to a word in another text segment; For each arc under the target arc drawing method, the probability that the dependency labels of the two words connected by the arc are the set dependency labels is predicted, and the dependency labels of the two words connected by the arc are determined according to the probability that the dependency labels of the two words connected by the arc are the set dependency labels.
10. The syntax analysis method according to claim 9, characterized in that: The prediction of the dependency labels of the two words connected by the arc as the probability of each set dependency label includes: Obtain one or more of the following features of the two words connected by the arc: word-level features, distance features, and sentence-level features; Determine a characterization vector of the arc according to the acquired features; According to the representation vector of the arc, the probability of the dependency labels of the two words connected by the arc being the set dependency labels is predicted.
11. The grammar analysis method according to claim 10, characterized in that: Get the sentence-level features of the two words connected by the arc, including: Obtain the representation vector of the first part and the representation vector of the last part of the three parts obtained by dividing the text to be parsed using the two words connected by the arc as the dividing line; The representation vector of the last part is subtracted from the representation vector of the first part, and the vector obtained by the subtraction is used as a sentence-level feature of the two words connected by the arc.
12. The grammar parsing method according to claim 1, characterized in that: The process of establishing the grammar parsing model includes: The training text is used as the text to be parsed, and the grammar parsing model is used to predict the probability that the component labels of the text to be parsed are the set component labels and the scores of each candidate segmentation method of the text to be parsed as the first prediction result; For each candidate segmentation method of the text to be parsed, predict the scores of each candidate arc drawing method of the text segment obtained by segmenting the text to be parsed according to the candidate segmentation method, and the probability that the dependency labels of two words connected by each arc under each candidate arc drawing method are set dependency labels, so as to obtain the prediction results under each candidate segmentation method as the second prediction results; updating parameters of a grammar parsing model according to the first prediction result, the second prediction result, and a relevant part of a joint parse tree corresponding to the training text; For each text segment obtained by segmenting according to each candidate segmentation method, if the text segment includes multiple words, the text segment is used as the text to be parsed, and the method of using the grammatical parsing model to predict the component labels of the text to be parsed as the probability of each set component label and the score of each candidate segmentation method of the text to be parsed is executed.
13. The grammar analysis method according to claim 12, characterized in that: The updating of parameters of the grammar parsing model according to the first prediction result, the second prediction result and the relevant part of the joint parse tree corresponding to the training text includes: Determining a first prediction loss of a grammatical parsing model according to a relevant portion of the hierarchical grammatical structure information presented by the first prediction result and the joint parse tree corresponding to the training text; Determining a second prediction loss of the grammatical parsing model according to a relevant portion of the inter-word dependency information presented by the second prediction result and the joint parse tree corresponding to the training text; The first prediction loss and the second prediction loss are fused, and parameters of the grammatical parsing model are updated according to the fused loss.
14. A grammar analysis device, characterized in that: Includes: text acquisition module and grammar parsing module; The text acquisition module is used to acquire the target sentence; The grammar parsing module is used to parse the target sentence layer by layer using a pre-established grammar parsing model to obtain hierarchical grammar structure information and inter-word dependency information of the target sentence, and generate a joint parse tree that can simultaneously present the hierarchical grammar structure information and inter-word dependency information of the target sentence according to the parsing result; The parsing object of the first layer is the target sentence, and the parsing result of the first layer includes the component labels of the parsing object of the layer, and the parsing objects of each other layer include the text segments obtained by segmenting the parsing object of the previous layer, and the parsing results of each other layer include the component labels of each text segment contained in the parsing object of the layer and the dependency relationship information between different text segments; The grammatical parsing model is obtained by training using training sentences and a joint parsing tree corresponding to the training sentences.
15. A grammar parsing device, characterized in that: include: Memory and processor; The memory is used to store programs; The processor is used to execute the program to implement each step of the grammar parsing method according to any one of claims 1 to 13.
16. A readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step of the grammar analysis method according to any one of claims 1 to 13 is implemented.
