Weakly supervised temporal graph question answering method based on deep learning
Through the weakly supervised timing graph question and answer method based on deep learning, using template filling and natural language to database query statement models, interpretable database query statements are generated, which solves the problem of high additional labeling and poor answer interpretability in the existing technology, and realizes the problem of high-quality labeling and poor answer interpretability. Efficient timing chart Q&A.
Patent Information
- Application Number
- CN202311732260.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-16
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2043-12-16
AI Technical Summary
The existing timing chart question and answer methods require high additional annotation requirements and the answers are poorly interpretable.
A weakly supervised timing graph question-and-answer method based on deep learning is used to generate database query statements through template filling and validity verification, and a natural language to database query statement model is used for training and reasoning to generate interpretable database query statements to obtain answers.
While maintaining high interpretability, it significantly reduces the data annotation requirements during model training, and improves the efficiency and accuracy of question-and-answer.
Smart Images

Figure CN117743652B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of natural language processing and artificial intelligence technology, and in particular relates to a weakly supervised temporal graph question answering method based on deep learning. Background Art
[0002] In today's era of information explosion, the Internet is flooded with a large amount of information and data, and the scale of knowledge graphs has also shown explosive growth. How to find the knowledge users need from the massive amount of knowledge is a challenge for graph applications. Knowledge graph question answering is a technology that uses facts in the knowledge graph to answer users' natural language questions. By using information retrieval, semantic analysis and other methods to find the most appropriate answer in the knowledge graph, efficient answers to questions are achieved. Conventional knowledge graph question answering uses static knowledge graphs as knowledge bases to answer natural language questions. The knowledge and information in them are immutable, but in real life, knowledge is often updated dynamically. In the face of this kind of dynamic knowledge question answering, not only does it need to build a dynamic time-series knowledge graph at the knowledge base level, but it also requires the question answering model to have temporal reasoning capabilities at the model level.
[0003] Thanks to the development of deep learning, the performance of knowledge graph question answering has been significantly improved compared to the past. Existing deep learning-based temporal graph question answering can be mainly divided into two categories: information retrieval-based and semantic parsing-based methods.
[0004] The mainstream method based on information retrieval decomposes the entire model into two parts: the knowledge completion model and the question-answering model. The knowledge completion model is used to map all entities in the graph into a feature space, and the relationship and time information between entities are represented by the relative position of the entities in the feature space. After construction, the feature space will learn all the knowledge in the graph. The question-answering model is used to analyze natural language questions, understand user intentions, and extract relational features in questions. Under ideal conditions, after the entities in the question are transformed by the relational features, the answer entity required by the user can be obtained. Although the process design of this type of method is simple, since its answer is obtained by directly calculating the score, it cannot output explicit reasoning logic, resulting in poor interpretability of the answer.
[0005] The mainstream method based on semantic analysis is to first establish a knowledge database based on graph knowledge, then understand and logically analyze each input question and convert it into an executable database query statement, and finally the database obtains the answer directly from the graph by executing the query statement. Although this type of method has higher question-answering accuracy than the previous method and has strong interpretability, the annotation information of its query statement is expensive and requires the annotator to have certain database knowledge, which is difficult to obtain in actual application scenarios.
[0006] Although the above two methods have achieved certain results in the time series knowledge graph question answering task, they require high-cost annotation during the model training process. For information retrieval methods, not only the answer to each question needs to be annotated, but also the entity index, entity position, time index, and time position that appear in the question need to be additionally annotated, and such additional annotations are still required during model reasoning; for semantic parsing methods, although additional annotations are only required during model training, their additional annotations are more expensive query statement annotations, which are more difficult to obtain than entity and time annotation information.
[0007] In summary, information retrieval methods require additional annotations during both training and reasoning. In actual graph question-and-answer application scenarios, some pre-processing is required to obtain the entities and time in the question, which increases the cumulative error and affects the model performance. Semantic parsing methods only require additional annotations during training, which has lower data requirements than information retrieval methods, but still cannot get rid of the need for additional annotations during training. Summary of the invention
[0008] (1) Technical issues to be solved
[0009] The present invention discloses a weakly supervised time series graph question answering method based on deep learning, aiming to solve the problems that the existing time series graph question answering requires high additional annotation requirements and its answers have poor interpretability.
[0010] (2) Technical solution
[0011] A weakly supervised time series graph question answering method based on deep learning, comprising the following steps:
[0012] Step 1, obtain a time series graph dataset;
[0013] Step 2: Generate the corresponding database query statement by using the time series graph dataset through template filling and validity verification;
[0014] Step 3, using the generated database query statements to train a natural language to database query statement model;
[0015] Step 4, obtaining a database query statement through natural language to database query statement model reasoning, and performing a database query based on the database query statement to obtain a final answer;
[0016] The time series graph dataset is obtained by manual annotation, wherein the time series graph dataset is a weakly supervised dataset, which only contains question-answer pairs of natural language questions and corresponding answers, and the question-answer pairs are divided into a training set and a validation set, and one question corresponds to one or more answers.
[0017] Furthermore, the specific method of step 2 includes the following steps:
[0018] Step 201, extracting entities and relations from the training set questions and linking them to the time series graph to obtain corresponding entities and relations;
[0019] Step 202, filling the entities and relationships into a predefined query template to generate multiple candidate query statements;
[0020] Step 203, use the plurality of candidate query statements to perform a database query, calculate the matching score between the query result and the answer corresponding to the question, and take the candidate query statement with the highest score as the database query statement corresponding to the training set question.
[0021] Furthermore, the specific method of step 201 is as follows:
[0022] First, the pre-trained model of the Flair framework is used to extract entities and relations from the question to obtain entities and relations. Then, the entities and relations are linked to the time series graph according to the following formula, and the string similarity between the entities and relations and the entities and relations in the time series graph is calculated:
[0023] e=argmax(Similar(e0,E)), r=argmax(Similar(r0,R))
[0024]
[0025] Among them, e0, r0 are the entities and relationships output by the Flair model respectively, E, R are the entity set and relationship set in the time series graph respectively, e, r are the linked entities and relationships respectively, and the argmax method returns the index of the maximum value; Among them, in the Similar similarity calculation formula, M is the length of the overlapping string of two strings a and b, and T is the sum of the lengths of the two strings a and b before deduplication; In the above process, the entity with the greatest similarity in the time series graph is taken as the linked entity, and the relationship with the greatest similarity is taken as the linked relationship, so as to obtain the corresponding entities and relationships.
[0026] Furthermore, in step 202, the query template is specifically designed as follows:
[0027] Template 1: select FUNC(time)from REL where object=OBJ and subject=SUB
[0028] Template 2: select subject from REL where object=OBJ and time=TIME
[0029] Template 3: select subject from REL where object=OBJ and time> / <(selectFUNC(time)from REL where object=OBJand subject=SUB)
[0030] Among them, the above templates are all database query statement templates, REL is the relationship, fill in the above linked relationship; OBJ and SUB are the object and subject respectively, fill in the above linked entities; TIME is the time, fill in the time extracted from the question, FUNC is the aggregation function, including five categories: sum, max, min, avg, and count. Each query will also swap the subject and object order of object and subject to generate additional queries. Therefore, for one of the above questions, 30 candidate query statements of 3*5*2 will be generated.
[0031] Furthermore, in step 203, the specific calculation method of the matching score is as follows:
[0032] Query the database for multiple candidate query statements respectively to obtain a query result list corresponding to the candidate query statements. When the first result in the query result list is the answer to the question, the first result obtains the highest matching score of 1; if the first result is not the answer to the question, and the second result is the answer to the question, the matching score of the second result is 1 / 2; if the current two results are not the answer to the question, and the third result is the answer to the question, the matching score of the third result is 1 / 3; results that are not the answer to the question are not scored; and so on, the corresponding scores of each result in the list are obtained, and the sum of the scores of the list is the score of the candidate query statement:
[0033]
[0034] Where score is the score, S is the query result list returned when the candidate query statement is executed, i is a result in the query result list S, A is the answer corresponding to the question, and rank i Represents the index of the i-th occurrence in S, and the index starts at 1;
[0035] The matching score can reflect the matching degree of the answer in the query result list. The higher the answer is in the query result list, the higher the matching score is. In addition, the score also sets a threshold θ. When the score < θ, the entity or relationship extraction result may be incorrect. The query will be returned to step 201 to select the entity or relationship extraction with the second largest matching score to generate a database query statement for matching score until the score ≥ θ or a certain number of attempts are reached to terminate the query.
[0036] Furthermore, the specific steps of step 3 are as follows:
[0037] Step 301, inputting the natural language questions in the training set and the corresponding database query statements generated in step 2 into the natural language to database query statement model for training;
[0038] Step 302: The natural language to database query statement model decouples the corresponding database query statement to obtain the skeleton and column information of its syntax tree;
[0039] Step 303, the natural language to database query sentence model obtains prediction skeleton and prediction column information through the natural language question and skeleton;
[0040] Step 304: the natural language to database query statement model combines the prediction skeleton and the prediction column information to obtain a database query statement;
[0041] The specific steps of step 4 are as follows:
[0042] Step 401, using a natural language to database query statement model to infer the natural language questions in the validation set to obtain corresponding database query statements;
[0043] Step 402, perform a database query according to the corresponding database query statement to obtain a final answer.
[0044] Furthermore, the specific method of decoupling in step 302 is as follows:
[0045] For a database query statement, such as select max(time)from A where object=B andtime<(select min(time)from A where subject=C), it is converted into an abstract syntax tree structure, and the corresponding syntax tree skeleton is select max(_)from_where_=_and_<(select min(_)from_where_=_), and the column information is time, A, object, B, time, time, A, subject, C in sequence.
[0046] Furthermore, the specific method of step 303 is as follows:
[0047] First perform skeleton prediction to get the predicted skeleton:
[0048] Natural language question S = (w1, w2, ..., w n ), w nis the word in the question, and its corresponding database query statement is Y. First, the question S is tokenized and converted into a token form T = (t1, t2, ..., t k ), t k is the word after the question S is segmented, and the entity feature of T is enhanced to obtain the enhanced feature T′, T′=(t1′, t2′, ..., t k ′),
[0049]
[0050] t entity =mean(Roberta(entity))
[0051] Among them, entity is the standard form of the entity in the graph, and after word segmentation and feature extraction, entity feature vectors of varying lengths are generated. entity It is the average feature obtained by averaging the semantic features after extracting semantic features of unequal lengths through the language model Roberta, and mean is the operation of finding the vector mean;
[0052] The enhanced feature T′ is passed through the language model LM to extract context information to obtain the semantic feature F of the question. The semantic feature F of the question is decoded by the Transformer Decoder to obtain the skeleton feature F s After that, the syntax tree skeleton of the database query statement is predicted through the fully connected layer Linear:
[0053] F=LM(T′)
[0054] F s = TransformerDecoder(F)
[0055] skeleton=Linear(F s )
[0056] Then perform column prediction to obtain the predicted column information:
[0057] After predicting the skeleton of the syntax tree, F s After being concatenated with the enhanced feature T′, it is sent to the language model LM again to obtain the aggregated semantic features, and then decoded by TransformerDecoder to obtain the column information feature F c , according to the skeleton vacancy position of the syntax tree decoupled in step 302, select the column information feature F at the corresponding position c The vacant position is the underlined part "_" in the skeleton of the syntax tree decoupled in step 302, and the column information feature F cAfter the fully connected layer Linear predicts the syntax tree column information of each skeleton vacancy position:
[0058] F c =TransformerDecoder(LM(concat(F s , T′)))
[0059] Column=Linear(Position_select(F c ))
[0060] It should be noted that the TransformerDecoder for skeleton prediction and column prediction does not share parameters;
[0061] In step 304, the combination method is as follows:
[0062] sql=combine(skeleton,Column)
[0063] Combine the obtained prediction skeleton skeleton and the prediction column information Column to obtain the SQL database query statement.
[0064] Furthermore, the skeleton prediction constrains the output by conditional beam search; for the skeleton prediction probability word vector of each position, the top k word categories with the largest probability are selected for beam search, and the probabilities of the key words "select", "from", and "where" are also added to the search space of each position; when outputting, only the skeleton containing the key words "select", "from", and "where" is output, and for the predicted skeleton skeleton = (p1, p2, ..., p n ), p n is the probability word vector of the nth position in the prediction skeleton, and the first k word categories with the largest probability are taken to obtain the new prediction skeleton skeleton′=(p′1, p′2, ..., p′ n ), the probability word vector corresponding to each position is p′ n , and then add the key words to the search space:
[0065] p′ n =concat(p′ n , p n,select , p n,from , p n,where )
[0066] Among them, concat is splicing, p n,select , p n,from , p n,whereRespectively represent the probabilities of select, from, and where in the nth position of the predicted skeleton.
[0067] At the same time, the database query statement syntax analysis is performed on each path obtained by the conditional intensive search, and the default values are filled in the empty positions of the skeleton to determine whether it is an executable database query statement. If the database query statement is executable, its predicted skeleton is output; if the database query statement is not executable, it is discarded.
[0068] Furthermore, the loss function and specific training method of the skeleton prediction are as follows:
[0069] In the first three rounds of training, only the skeleton prediction loss function is used. After the model has a certain skeleton prediction ability, the skeleton prediction loss function and the column prediction loss function are used for joint training:
[0070] During the first three rounds of training, the loss function is:
[0071] Loss = 1 * Loss ske +0*Loss col
[0072] After three rounds of training, the loss function becomes:
[0073] Loss = 0.5 * Loss ske +0.5*Loss col
[0074] Among them, Loss ske is the skeleton prediction loss function, Loss col Loss function for column prediction.
[0075] Compared with the prior art, the present invention has the following beneficial effects:
[0076] Based on the semantic parsing method, the present invention generates query statements in a weakly supervised manner and trains a deep learning model, and converts natural language questions into database query statements through the model; while maintaining a high level of interpretability, the answer of the present invention greatly reduces the requirements for data labeling during the model training process. BRIEF DESCRIPTION OF THE DRAWINGS
[0077] Figure 1 A schematic flow chart of the implementation method of the present invention is shown. DETAILED DESCRIPTION
[0078] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are 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.
[0079] For the purpose of reference and clarity, the technical terms, abbreviations or acronyms used below are summarized and explained as follows:
[0080] Transformer: A model structure that uses attention mechanism for feature extraction.
[0081] Transformer Decoder: The decoder in the Transformer model structure.
[0082] Linear: A commonly used neural network layer, also known as a fully connected layer or a dense layer.
[0083] Softmax: Normalized exponential function.
[0084] Concat: A vector concatenation operation.
[0085] LM: abbreviation of language model.
[0086] Roberta: A masked language model.
[0087] Bert: An autoencoding language model.
[0088] Flair: Models for entity extraction and relation extraction.
[0089] Sql: A structured query statement used to perform database operations such as querying and modifying the database.
[0090] Similar: Similarity calculation method.
[0091] Argmax: A function that evaluates a function to an argument and returns the index of the maximum value among its inputs.
[0092] Sum: The sum operation in the database query statement will return the sum of the candidate query results.
[0093] Max: The maximum value operation in the database query statement will return the maximum value of the candidate query results.
[0094] Min: The minimum value operation in the database query statement will return the minimum value of the candidate query results.
[0095] Avg: The averaging operation in the database query statement will return the average value of the candidate query results.
[0096] Count: The count operation in the database query statement will return the number of candidate query results.
[0097] Skeleton: The syntax tree skeleton of the database query statement.
[0098] Database: A structured data storage system used to efficiently store, retrieve, update, and manage large amounts of data. In the present invention, it can be understood as a temporal knowledge graph with retrieval capabilities.
[0099] Model training: Use the training set to train the model.
[0100] Model reasoning: Analyze each question in the test set according to the trained model and get the corresponding return result.
[0101] Temporal graph: also known as temporal knowledge graph, is a semantic network containing a large number of entities (people, place names, companies), relationships (certain connections between different entities) and time; its dataset is a weakly supervised dataset, containing a large number of question-answer pairs of natural language questions and their answers. One question corresponds to one or more answers, and these question-answer pairs are divided into training sets and validation sets; questions contain entities, relationships and time.
[0102] Figure 1 A flowchart of an embodiment of the present invention is shown, which is a weakly supervised time series graph question answering method based on deep learning, comprising the following steps:
[0103] Step 1, obtain a time series graph dataset;
[0104] Step 2: Generate the corresponding database query statement by using the time series graph dataset through template filling and validity verification;
[0105] Step 3, using the generated database query statements to train a natural language to database query statement model;
[0106] Step 4: Obtain a database query statement through natural language to database query statement model reasoning, and perform a database query based on the database query statement to obtain a final answer.
[0107] The following example illustrates the weakly supervised time series graph question answering process based on deep learning:
[0108] Execute step 1 to obtain the time series graph dataset:
[0109] The time series graph dataset is obtained by manual annotation, wherein the time series graph dataset is a weakly supervised dataset, which only contains question-answer pairs of natural language questions and answers, and cannot be directly used to train the natural language to database query statement model. The question-answer pairs are divided into a training set and a validation set, and one question corresponds to one or more answers.
[0110] Execute step 2, use the time series graph dataset to generate the corresponding database query statement through template filling and validity verification, the specific method includes the following steps:
[0111] Step 201, extracting entities and relations from the training set questions and linking them to the temporal knowledge graph to obtain corresponding entities and relations;
[0112] Step 202, filling the obtained entities and relationships into a predefined query template to generate multiple candidate query statements;
[0113] Step 203, use multiple candidate query statements to query the database, calculate the matching score between the query result and the answer corresponding to the question, and take the candidate query statement with the highest score as the database query statement corresponding to the training set question.
[0114] Specifically, in step 201, the entity extraction and relationship extraction of the training set are performed and linked to the temporal knowledge graph to obtain the corresponding entities and relationships. The specific method is as follows:
[0115] First, the pre-trained model of the Flair framework is used to extract entities and relations from the question to obtain entities and relations. Since the extracted entities and relations come from the question and may have diverse expressions, it is also necessary to link the extracted entities and relations to specific entity indexes and relationship indexes in the graph. The string similarity between the entities and relations in the time series graph is calculated according to the following formula, and the extracted entities and relations are linked to the graph:
[0116] e=argmax(Similar(e0,E)), r=argmax(Similar(r0,R))
[0117]
[0118] Among them, e0, r0 are the entities and relations output by the Flair model, E, R are the entity set and relationship set in the time series graph, e, r are the linked entities and relations, respectively; in the similarity calculation formula, M is the length of the overlapping string of two strings a and b, and T is the sum of the lengths of the two strings a and b before deduplication. In the above process, the entity with the greatest similarity in the time series graph is taken as the linked entity, and the relationship with the greatest similarity is taken as the linked relationship, so as to obtain the corresponding entities and relationships.
[0119] Specifically, the query template in step 202 is specifically designed as follows:
[0120] Template 1: select FUNC(time)from REL where object=OBJ and subject=SUB
[0121] Template 2: select subject from REL where object=OBJ and time=TIME
[0122] Template 3: select subject from REL where object=OBJ and time> / <(selectFUNC(time)from REL where object=OBJ and subject=SUB)
[0123] Among them, the above templates are all database query statement templates. REL is the relationship, fill in the above linked relationship; OBJ and SUB are the object and subject, respectively, fill in the above linked entities; TIME is the time, fill in the time extracted from the question, FUNC is the aggregation function, including sum, max, min, avg, count. Each query will also swap the subject and object order of object and subject to generate additional queries; therefore, for a natural language question, 30 candidate query statements will be generated, 3*5*2 in total.
[0124] Specifically, the matching score in step 203 is calculated as follows:
[0125] Query the database for multiple candidate query statements respectively to obtain a query result list of the corresponding candidate query statements. When the first result in the query result list is the answer to the question, the first result obtains the highest matching score of 1; if the first result is not the answer to the question, and the second result is the answer to the question, the matching score of the second result is 1 / 2; if the two current results are not the answer to the question, and the third result is the answer to the question, the matching score of the third result is 1 / 3; results that are not the answer to the question are not scored; and so on, the corresponding scores of each result in the list are obtained, and the sum of the scores of the list is the score of the candidate query statement:
[0126]
[0127] Where score is the score, S is the query result list returned when the candidate query statement is executed, i is a result in the query result list S, A is the answer corresponding to the question, and rank i Represents the index of the i-th in S, and the index starts from 1;
[0128] The matching score can reflect the matching degree of the answer in the query result list. The higher the answer is in the query result list, the higher the matching score is. In addition, the score also sets a threshold θ. When the score < θ, the entity or relationship extraction result may be incorrect. The query will be returned to step 201 to select the entity or relationship extraction with the second largest matching score to generate a database query statement for matching score until the score ≥ θ or a certain number of attempts are reached to terminate the query.
[0129] Execute step 3 to train the natural language to database query model using the generated database query. The training steps are as follows:
[0130] Step 301, inputting the natural language questions in the training set and the corresponding database query statements generated in step 2 into the natural language to database query statement model for training;
[0131] Step 302: The natural language to database query statement model decouples the database query statement to obtain the skeleton and column information of its syntax tree;
[0132] Step 303, the natural language to database query sentence model obtains prediction skeleton and prediction column information through the natural language question and skeleton;
[0133] Step 304: The natural language to database query statement model combines the prediction skeleton and the prediction column information to obtain a database query statement.
[0134] Specifically, the decoupling in step 302 is specifically performed as follows:
[0135] For a nested database query statement, such as select max(time)from A where object=B and time<(select min(time)from A where subject=C), it is converted into an abstract syntax tree structure, and the skeleton of the corresponding syntax tree is select max(_)from_where_=_and_<(select min(_)from_where_=_), and the column information is time, A, object, B, time, time, A, subject, C. For a single database query statement, the decoupling process of its skeleton and column information is similar to the above method.
[0136] Specifically, the step 303 of obtaining the prediction skeleton and prediction column information through the natural language question and skeleton is as follows:
[0137] First perform skeleton prediction to get the predicted skeleton:
[0138] Natural language question S = (w1, w2, ..., w n ), w n is the word in the question, and its corresponding database query statement is Y. First, the question S is tokenized and converted into a token form T = (t1, t2, ..., t k ), t k is the word after the question S is segmented, and the entity feature of T is enhanced to obtain the enhanced feature T′, T′=(t1′, t2′, ..., t k ′),
[0139]
[0140] t entity =mean(Roberta(entity))
[0141] Among them, entity is the standard form of the entity in the graph, and after word segmentation and feature extraction, entity feature vectors of varying lengths are generated. entity It is the average feature obtained by averaging the semantic features after extracting semantic features of unequal lengths through the language model Roberta, and mean is the operation of finding the vector mean.
[0142] The enhanced feature T′ is passed through the language model LM to extract context information to obtain the semantic feature F of the question. The semantic feature F of the question is decoded by the Transformer Decoder to obtain the skeleton feature F s After that, the syntax tree skeleton of the database query statement is predicted through the fully connected layer Linear:
[0143] F=LM(T′)
[0144] F s = TransformerDecoder(F)
[0145] skeleton=Linear(F s )
[0146] Then perform column prediction to obtain the predicted column information:
[0147] After predicting the skeleton of the syntax tree, F sAfter being concatenated with the enhanced feature T′, it is sent to the language model LM again to obtain the aggregated semantic features, and then decoded by TransformerDecoder to obtain the column information feature F c , according to the skeleton vacancy position of the syntax tree decoupled in step 302 above, select the column information feature F at the corresponding position c The vacant position is the underlined part "_" in the above skeleton, and the column information feature F c After the fully connected layer Linear predicts the syntax tree column information of each skeleton vacancy position:
[0148] F c =TransformerDecoder(LM(concat(F s , T′)))
[0149] Column=Linear(Position_select(F c ))
[0150] It should be noted that the TransformerDecoder for skeleton prediction and column prediction does not share parameters;
[0151] Specifically, in step 304, the combination method is as follows:
[0152] sql=combine(skeleton,Column)
[0153] Combine the obtained prediction skeleton skeleton and the prediction column information Column to obtain the SQL database query statement.
[0154] Furthermore, the skeleton prediction in step 303 constrains the output by conditional cluster search; for the skeleton prediction probability word vector of each position, the top k word categories with the largest probability are selected for cluster search, and the probabilities of the key words "select", "from", and "where" are also added to the search space of each position. For example, when the predicted skeleton skeleton = (p1, p2, ..., p n ) after that, p n is the word probability vector of the nth position in the skeleton. Assume there are 1000 word categories, p n The dimension of is 1000. When using the traditional beam search with k=3, we only keep p n The word categories p′ with the top three probability values n , p′ n The dimension is 3, in the sequence (p′1, p′2, ..., p′ n) to search for paths; while the conditional beam search is performed at each p′ n On the basis of , the probability value of the mandatory vocabulary is retained. For example, there are three mandatory words "select", "from", and "where", then the corresponding p′ n The dimension of is 6. When outputting, only the skeletons containing the key words "select", "from", and "where" are output. For the predicted skeleton skeleton = (p1, p2, ..., p n ) is the probability word vector p for each position in n , take the top k word categories with the highest probability and get skeleton′=(p′1, p′2, ..., p′ n ), for each position p′ n , add key words to the search space:
[0155] p′ n =concat(p′ n , p n,select , p n,from , p n,where )
[0156] Among them, concat is splicing, p n,select , p n,from , p n,where Respectively represent the probabilities of select, from, and where in the nth position of the predicted skeleton.
[0157] At the same time, SQL syntax analysis is performed on each path obtained by conditional intensive search, and the default values are filled in the empty positions of the skeleton to determine whether it is an executable SQL statement. If it is executable, the predicted skeleton is output; if it is not executable, it is discarded.
[0158] Furthermore, the loss function and specific training method of the skeleton prediction in step 303 are as follows:
[0159] In the first three rounds of training, only the skeleton prediction loss function is used. After the model has a certain skeleton prediction ability, the skeleton prediction loss function and the column prediction loss function are used for joint training:
[0160] During the first three rounds of training, the loss function is:
[0161] Loss = 1 * Loss ske +0*Loss col
[0162] After three rounds of training, the loss function becomes:
[0163] Loss = 0.5 * Loss ske+0.5*Loss col
[0164] Among them, Loss ske is the skeleton prediction loss function, Loss col Loss function for column prediction.
[0165] Execute step 4, obtain the database query statement through natural language to database query statement model inference, and perform database query based on the database query statement to obtain the final answer. The specific steps are as follows:
[0166] Step 401, using a natural language to database query statement model to infer the natural language questions in the validation set to obtain corresponding database query statements;
[0167] Step 402: perform a database query according to the corresponding database query statement to obtain a final answer.
[0168] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0169] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0170] The technical features of the above embodiments can be combined arbitrarily. At the same time, the number of each step is not used to constrain the order of the steps. As long as there is no strict order constraint between the steps, the order is allowed to be adjusted and changed. In order to make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0171] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A weakly supervised time series graph question answering method based on deep learning, characterized in that: The following steps are involved: Step 1, obtain a time series graph dataset; Step 2: Generate the corresponding database query statement by using the time series graph dataset through template filling and validity verification; Step 3, using the generated database query statements to train a natural language to database query statement model; Step 4: Obtain a database query statement through natural language to database query statement model reasoning, and perform a database query based on the database query statement to obtain a final answer; The time series graph dataset is obtained by manual annotation, wherein the time series graph dataset is a weakly supervised dataset, which only contains question-answer pairs of natural language questions and corresponding answers, and the question-answer pairs are divided into a training set and a validation set, and one question corresponds to one or more answers; Wherein, the specific method of step 2 comprises the following steps: Step 201, extracting entities and relations from the training set questions and linking them to the time series graph to obtain corresponding entities and relations; Step 202, filling the entities and relationships into a predefined query template to generate multiple candidate query statements; Step 203, using the plurality of candidate query statements to perform a database query, calculating a matching score between the query result and the answer corresponding to the question, and taking the candidate query statement with the highest score as the database query statement corresponding to the training set question; In step 202, the query template is specifically designed as follows: Template 1: ; Template 2: ; Template 3: ; Among them, the above templates are all database query statement templates. The relationship is filled in after the above link; , The two places are object and subject respectively, fill in the entities after the above links; Where is the time, fill in the time extracted from the question. Aggregate functions include sum, max, min, avg, and count. Each query will also switch and The subject and object sequence of the query is used to generate additional queries, so for one question, multiple candidate query sentences will be generated.
2. According to the method of weakly supervised time series graph question answering based on deep learning in claim 1, it is characterized in that: The specific method of step 201 is as follows: First, the pre-trained model of the Flair framework is used to extract entities and relations from the question to obtain entities and relations. Then, the entities and relations are linked to the time series graph according to the following formula, and the string similarity between the entities and relations and the entities and relations in the time series graph is calculated: ; in, , They are the entities and relations output by the Flair model, , They are the entity set and relationship set in the time series graph, , are the linked entities and relationships respectively, The method returns the index of the maximum value; In the similarity calculation formula, For two strings The length of the overlapping string, T is the length of the two strings The sum of the lengths when deduplication is not performed; in the above process, the entity with the greatest similarity in the time series graph is taken as the linked entity, and the relationship with the greatest similarity is taken as the linked relationship, so as to obtain the corresponding entities and relationships.
3. According to the method of weakly supervised time series graph question answering based on deep learning in claim 1, it is characterized in that: In step 203, the specific method for calculating the matching score is as follows: Perform database queries on the candidate query statements respectively to obtain a query result list corresponding to the candidate query statements, and when the first result in the query result list is the answer corresponding to the question, the first result obtains the highest matching score of 1; If the first result is not the answer to the question, and the second result is the answer to the question, the matching score of the second result is 1 / 2; if neither of the two results is the answer to the question, and the third result is the answer to the question, the matching score of the third result is 1 / 3; Results that are not the answers to the question will not be scored; and so on, the corresponding scores of each result in the list are obtained, and the sum of the scores in the list is the score of the candidate query statement: ; Among them, score is the score, It is the query result list returned when executing the candidate query statement. For the query result list One of the results, is the answer corresponding to the question, Representative Appears in The index in starts from 1; The matching score can reflect the matching degree of the answer in the query result list. The higher the answer is in the query result list, the higher the matching score is. In addition, the score also sets a threshold. ,when If the entity or relationship extraction result is wrong, then return to step 201 to select the entity or relationship with the second largest matching score to generate a database query statement for matching score until Or terminate the query when a certain number of attempts is reached.
4. According to the method of weakly supervised time series graph question answering based on deep learning in claim 1, it is characterized in that: The specific steps of step 3 are as follows: Step 301, inputting the natural language questions in the training set and the corresponding database query statements generated in step 2 into the natural language to database query statement model for training; Step 302: The natural language to database query statement model decouples the corresponding database query statement to obtain the skeleton and column information of its syntax tree; Step 303, the natural language to database query sentence model obtains a predicted skeleton and predicted column information through the natural language question and the skeleton; Step 304: the natural language to database query statement model combines the prediction skeleton and the prediction column information to obtain a database query statement; The specific steps of step 4 are as follows: Step 401, using a natural language to database query statement model to infer the natural language questions in the validation set to obtain corresponding database query statements; Step 402: perform a database query according to the corresponding database query statement to obtain a final answer.
5. According to claim 4, a weakly supervised time series graph question answering method based on deep learning is characterized in that: The specific decoupling method in step 302 is as follows: For database query statements , convert it into an abstract syntax tree structure, and the corresponding syntax tree skeleton is The column information is time, A, object, B, time, time, A, subject, C.
6. According to the method of weakly supervised time series graph question answering based on deep learning in claim 4, it is characterized in that: The specific method of step 303 is as follows: First perform skeleton prediction to get the predicted skeleton: Natural language questions , is the word in the question, and its corresponding database query statement is First, the question Tokenize the words and convert them into token form , For question After word segmentation, Perform entity feature enhancement to obtain enhanced features ; ; Among them, entity is the standard form of the entity in the graph, and after word segmentation and feature extraction, entity feature vectors of varying lengths are generated. It is the average feature obtained by averaging the semantic features after extracting semantic features of unequal lengths through the language model Roberta, and mean is the operation of finding the vector mean; Enhanced features The question semantic features are obtained by extracting context information through the language model LM. , the semantic features of the question Obtain skeleton features after decoding by Transformer Decoder After that, through the fully connected layer Predict the syntax tree skeleton of the database query statement: ; Then perform column prediction to obtain the predicted column information: After predicting the skeleton of the syntax tree, With enhanced features After concatenation, it is sent to the language model LM again to obtain aggregated semantic features. Decode to obtain column information features , according to the skeleton vacancy position of the syntax tree decoupled in step 302, select the column information feature of the corresponding position The vacant position is the underlined part "_" in the skeleton of the syntax tree decoupled in step 302, and the information feature is listed. After the fully connected layer Predict the syntax tree column information for each skeleton vacancy position : ; It should be noted that the skeleton prediction and column prediction No shared parameters; In step 304, the combination method is as follows: ; The predicted skeleton obtained With forecast column information conduct Merge Database query statement.
7. The method for weakly supervised temporal graph question answering based on deep learning according to claim 6, characterized in that: The skeleton prediction constrains the output by conditional beam search; for the skeleton prediction probability word vector of each position, the top k word categories with the largest probability are selected for beam search, and the probabilities of the key words "select", "from", and "where" are also added to the search space of each position; when outputting, only the skeletons containing the key words "select", "from", and "where" are output; for the predicted skeleton , is the probability word vector of the nth position in the prediction skeleton, and the top k word categories with the highest probability are taken to obtain the new prediction skeleton , the probability word vector corresponding to each position is , and then add the key words to the search space: ; in, For splicing, Respectively represent the probabilities of select, from, and where in the nth position of the predicted skeleton. At the same time, the database query statement syntax analysis is performed on each path obtained by the conditional intensive search, and the default values are filled in the empty positions of the skeleton to determine whether it is an executable database query statement. If the database query statement is executable, its predicted skeleton is output; if the database query statement is not executable, it is discarded.
8. The method for weakly supervised temporal graph question answering based on deep learning according to claim 6, characterized in that: The loss function and specific training method of the skeleton prediction are as follows: In the first three rounds of training, only the skeleton prediction loss function is used. After the model has a certain skeleton prediction ability, the skeleton prediction loss function and the column prediction loss function are used for joint training: During the first three rounds of training, the loss function is: ; After three rounds of training, the loss function becomes: ; in, is the skeleton prediction loss function, Loss function for column prediction.
Citation Information
Patent Citations
Chinese language processing method and device based on neural network model
CN114185931A
Military equipment knowledge graph-oriented key information query method
CN114357143A
Complex knowledge base question answering method and system based on deep semantic analysis
CN116186228A