A subgraph retrieval optimized knowledge graph question answering method
By using a subgraph retrieval optimization method, utilizing relationship merging and entity sorting strategies, combining BERT and BiLSTM models for entity recognition and disambiguation, and dynamically expanding subgraphs, the accuracy and efficiency of knowledge graph question answering are improved, and the problems of entity ambiguity and large subgraph size in complex questions are solved.
Patent Information
- Application Number
- CN202311114498.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-31
- Publication Date
- 2025-10-24
- Estimated Expiration
- 2043-08-31
AI Technical Summary
Existing knowledge graph question answering methods face problems of entity ambiguity and large subgraph size when faced with complex questions, which makes it more difficult for the system to identify and understand the questions and reduces the accuracy.
A subgraph retrieval optimization method is adopted to optimize the beam search process through relationship merging and entity sorting strategies. The BERT model and BiLSTM model are used for entity recognition and disambiguation. The entity linking and subgraph retrieval algorithms are combined to dynamically expand question-related subgraphs, and the twin network architecture is used for question-answer matching.
It effectively alleviates the problems of entity ambiguity and large subgraph size, and improves the performance and accuracy of the knowledge graph question answering model.
Smart Images

Figure CN117149974B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to a knowledge graph question answering method, in particular to a knowledge graph question answering method based on subgraph retrieval. BACKGROUND
[0002] In a knowledge graph-based question answering system, questions can be divided into two categories according to their difficulty and complexity: simple questions and complex questions. Simple questions refer to those questions that only involve one entity or attribute, for example, "What is the area of China?", which can usually be answered by querying the entity and attribute information in the knowledge base. Complex questions refer to those questions that require reasoning or combination of multiple entities or attributes to answer, which require the system to have semantic understanding ability and to reason or combine entities and relationships in the knowledge graph to obtain the answer. Based on the development of knowledge graph-based question answering, many research results have been achieved, but in the face of real question answering scenarios, the existing knowledge question answering method still cannot meet the actual needs. The main difficulties are as follows: the diversity of language expression, the same question has multiple different expressions, which increases the difficulty of the system to identify the problem; the ambiguity of language expression, the same word may have multiple meanings and interpretations, which increases the difficulty of the system to understand the problem and is also likely to lead to incorrect answers; the complexity of the problem, in a large-scale knowledge graph, as the difficulty of the problem increases, the search space involved will increase, and the number of candidate answers will increase exponentially, making it much more difficult to select the correct answer.
[0003] The current mainstream knowledge graph question answering methods include semantic parsing-based methods and information retrieval-based methods. The semantic parsing-based method parses the natural language question, converts the question into a logical expression, and then converts the logical expression into a structured query statement supported by the knowledge base, such as SPARQL, Cypher, SQL, Prolog, etc. Finally, the answer is obtained from the knowledge base. According to the richness of the annotated data, the semantic parsing method can be divided into supervised semantic parsing and weakly supervised semantic parsing. Among them, the supervised semantic parsing method uses training data containing question and answer pairs and structured query statements to learn a semantic parser from the question to the logical form. This method can obtain high-quality logical forms and has strong interpretability, but it needs to manually annotate a large amount of training corpus containing logical forms for the model to learn the semantic parser. The annotation of the logical form requires the annotator to be proficient in the syntax rules of the logical form, and the annotation process requires a lot of time and effort, and the logical form annotation of complex problems is more difficult. Therefore, in the scene where the logical form data is scarce, the supervised semantic parsing method has certain limitations. The weakly supervised semantic parsing method only uses question and answer pairs to generate candidate semantic query graphs according to specific rules and processes, and sorts the candidate query graphs through a semantic matching model to obtain the best query graph, which does not rely on the annotation data of the logical form. However, due to the huge search space of complex problems, certain constraints and training strategies are needed, and the training of the model is more difficult, and it is easy to generate noisy candidate query graphs, which leads to misjudgment in the candidate query graph sorting stage and reduces the accuracy of the model.
[0004] The information retrieval-based method retrieves a subgraph related to the question from the knowledge graph according to the information contained in the question, and then finds the answer from the subgraph. This process usually consists of multiple modules such as entity recognition, entity linking, subgraph retrieval and answer selection. The entity recognition module aims to identify entities from the question. The entity linking module is the process of associating question entities with corresponding entities in the knowledge graph. In order to distinguish between question entities and knowledge graph entities, the question entity can be referred to as an entity mention, and the entity corresponding to the entity mention in the knowledge graph can be referred to as a topic entity. The subgraph retrieval module retrieves a subgraph related to the question from the knowledge graph according to the topic entity of the question, so as to narrow down the search space of the answer. The answer selection module selects one or more triples that best match the question from the subgraph related to the question as the basis for the answer. Existing research works improve different modules to improve the performance of the question answering model. In the training of the entity recognition and linking module, the method of identifying entity mentions first and then linking usually needs to train two models, which is easy to cause error accumulation and rely on more labeled data. The direct matching method of the question is easily affected by the noise in the question, and the accuracy is relatively low. Overall, the performance of the former is better than that of the latter. In the training of the subgraph retrieval module, most of the research works use direct retrieval or heuristic rule-based methods when retrieving subgraphs from the knowledge base. These methods are simple and convenient, but the subgraph contains a large number of irrelevant entities, and the search space of the answer selection is large. The method based on dynamic expansion and bundle search pruning selects the most relevant relationship to the question to expand the subgraph in each iteration, which can effectively reduce the size of the subgraph while ensuring a high recall rate of the subgraph. In the training of the answer selection module, the relationship classification-based method is relatively simple, suitable for knowledge bases with fewer relationship categories, and the relationship classification-based method is difficult to model and cannot handle relationships that do not appear in the relationship set. The semantic matching-based method can comprehensively utilize various information of the question and the candidate answer entity, the model implementation ideas are diverse, and the application scope is wide, which can handle unregistered entities and relationships.
[0005] Based on the above research background, the information retrieval-based method of the present application models the knowledge graph question answering task, and improves the entity linking and subgraph retrieval parts based on the existing research work to improve the performance of the knowledge graph question answering model. SUMMARY
[0006] The present application aims to solve the problems of entity ambiguity and complex question subgraph size in knowledge graph question answering, and proposes a knowledge graph question answering method based on subgraph retrieval optimization. The strategy of relationship merging and entity sorting is used to optimize the bundle search process, and the influence of repeated relationships on subgraph retrieval is alleviated, thereby improving the performance of the knowledge graph question answering model.
[0007] The above object is achieved by the following technical solutions:
[0008] A knowledge graph question answering method based on subgraph retrieval optimization, the method comprising the following steps:
[0009] (1) Data preprocessing
[0010] The cleaned knowledge graph data is stored in the database and the query index is established, and the data set required for training the entity recognition and entity linking model is constructed based on the question answering data set;
[0011] (2) Entity recognition
[0012] The entity recognition data set constructed in step (1) is used to fine-tune the pre-trained language model, first the BERT model is used to perform character-level vector representation on the natural question, then the BiLSTM model is used to further encode the context information of the question characters, enhance the vector representation of the characters, and finally the CRF model is used to predict the entity label of each character to identify the entity mention in the question;
[0013] (3) Entity linking
[0014] According to the entity linking data set constructed in step (1), three strategies of mapping dictionary matching, knowledge graph entity exact matching and knowledge graph entity fuzzy matching are used to recall the candidate entity set corresponding to the entity mention from the knowledge graph, and then the pre-trained language model is used to model the text information. For each entity mention and candidate entity pair, the semantic information of the question is used as the context feature of the entity mention, and the entity name, entity description and entity relationship of the candidate entity are used as the context feature of the candidate entity. Finally, the correlation between the context features of the entity mention and the candidate entity is used to disambiguate the candidate entity to obtain the topic entity of the question;
[0015] (4) Subgraph retrieval
[0016] According to the topic entity set obtained in step (3), a subgraph retrieval algorithm based on relationship merging and entity sorting is proposed, and the idea of bundle search is used to dynamically expand the problem-related subgraph of the topic entity. First, the repeated relationships of the retrieval entity are merged based on the relationship merging strategy, then the semantic similarity between the question and the entity relationship, and the semantic similarity between the question and the neighbor entity are used to sort the entity relationship and the neighbor entity respectively, and finally the fixed number of entity relationships and neighbor entities are selected according to the ranking of the entity relationship and the neighbor entity to expand the subgraph;
[0017] (5) Question answering matching
[0018] Using the question subject entity and question-related subgraph information from step (4), the relationship path from the subject entity to the candidate answer is generated. A question-answer matching model is built based on the fine-tuned pre-trained language model and the twin network architecture. The correlation between the question and the candidate answer path is used to score all the candidate answer paths in the question-related subgraph, and the entity set corresponding to the candidate answer path with the highest score is taken as the best answer to the question.
[0019] Furthermore, step (1) includes the following specific steps:
[0020] (1-1) Clean the knowledge graph data. The cleaning work includes converting traditional Chinese characters in entity relationship triples to simplified Chinese, truncating entity names that are too long, removing special characters in relationships, and unifying the case of English characters.
[0021] (1-2) Entity recognition sequence annotation data is constructed based on the questions and SPARQL query statements in the original question-answering dataset. The entities and relationships are obtained by regular expression matching on SPARQL, and the entity mentions in the questions are reversely annotated. Questions that cannot be annotated are annotated manually. Finally, the dependency relationship between each character is annotated using the BIO annotation method based on the annotated information of the questions, where B (Begin) represents the starting position of the entity, I (Inside) represents the internal position of the entity, and O (Outside) represents the non-entity position;
[0022] (1-3) After obtaining the entity mentions of the question, the Mention2entity file and the knowledge graph in the question-answering dataset are retrieved based on the string matching method to obtain a list of candidate entities, thereby constructing an entity link dataset. The Mention2entity file contains entity mentions, the knowledge graph entities corresponding to the entity mentions, and the popularity of the knowledge graph entities. The entity link dataset consists of positive and negative samples. Here, the candidate entities in the SPARQL query statement are used as positive samples, and the other candidate entities in the candidate entity list are used as negative samples.
[0023] Furthermore, step (2) includes the following specific steps:
[0024] (2-1) Entity recognition is modeled as a sequence labeling task, that is, the text is regarded as a sequence, and the label type of each character in the text sequence is predicted by the neural network model to obtain the label sequence of the text, where the input question text sequence X = {x1, x2, ..., x n}, x i Represents the i-th character in the question, and the label sequence of the predicted text is Y={y1,y2,…,y n},y iIndicates the BIO label corresponding to the i-th character in the question;
[0025] (2-2) Use the BERT model to represent the question at the character level. Given a question Q = {q1,q2,…,q n}, n represents the length of the question. The input of the BERT model is the concatenation of [CLS], question text sequence, and [SEP], that is, S = {[CLS],q1,q2,…,q n , [SEP]}, [CLS] and [SEP] are special identifiers. For each input character and special identifier, three embedding vector representations are obtained through the Token embedding layer, Segment embedding layer and Position embedding layer respectively. Their sum is used as the input of the Transformer encoder layer. The output of the model is the hidden vector T encoded by the last layer of Transformer encoder. Entity recognition is a sequence labeling task, so only the hidden vector corresponding to the question character is retained in T as the input of the next layer model. The formal formula of the above process is as follows:
[0026] T=[t1,t2,…,t n ]=BERT(S) (1)
[0027] (2-3) Using BiLSTM as the encoder of the model, the information before and after the current moment is utilized through forward propagation and backward propagation, and the two kinds of information are combined as the model output at the current moment, thereby obtaining more comprehensive semantic information. For the character-level vector representation T of the question, the encoding process of BiLSTM can be formalized as the following formula:
[0028]
[0029]
[0030] J=[h1,h2,…,h n ] (4)
[0031] Among them, H represents the intermediate representation vector after the BiLSTM encoding layer, represents the hidden state of the forward LSTM, represents the hidden state of the backward LSTM, After the BiLSTM encoding layer, a fully connected layer is used to reduce the dimension and map it to the output space where the entity label is located through nonlinear transformation. The final output of the BiLSTM encoding layer is P = [p1, p2, ..., p n ], p i The dimension is the number of entity labels k;
[0032] (2-4) Use the CRF model to obtain the optimal label sequence by learning the constraint relationship between labels, thereby improving the accuracy of entity recognition. Specifically, assuming that there is a transfer score matrix A, the elements in the matrix are Indicates that from label y i Move to label y j The transfer score, the output of the BiLSTM encoding layer Indicates that the i-th character is predicted to be label y i The score of the predicted label sequence Y={y1,y2,…,y n}, its label sequence score is:
[0033]
[0034] Normalize the label sequence score to obtain the probability of predicting the label sequence Y:
[0035]
[0036] in represents the true label sequence, Y X Represents all possible predicted label sequences, and taking the logarithm on both sides of the above formula gives the likelihood function of the predicted label:
[0037]
[0038] During the training phase, the model's goal is to maximize the log-likelihood of predicting the correct label sequence, that is, to minimize the loss function. The gradient of each weight parameter is solved through the backpropagation algorithm, and the parameters are updated using the gradient descent algorithm. The model uses the cross entropy loss function to calculate the loss, which is defined as follows:
[0039]
[0040] Among them, x i Indicates the i-th character in the question, y i Indicates the BIO label corresponding to the i-th character in the question, P(y i |x i ) indicates that the model predicts the i-th character as label y i probability;
[0041] In the testing phase, the following Viterbi algorithm is used to select the label sequence with the highest prediction score as the optimal label sequence.
[0042]
[0043] Furthermore, step (3) includes the following specific steps:
[0044] (3-1) The entity linking module is divided into two tasks: candidate entity generation and entity disambiguation;
[0045] Among them, candidate entity generation adopts two methods based on mapping dictionary and string matching. First, a mapping dictionary is built from entity mentions to knowledge graph entities based on the Mention2entity file. For the problem of entity aliases and abbreviations, the entity's alias, Chinese name, English name and abbreviation attributes are retrieved from the knowledge graph to expand the mapping dictionary. Then, according to the entity mentions in the question, a list of candidate entities is generated. The pre-built mapping dictionary is retrieved first to obtain a set of candidate entities generated based on the mapping dictionary. m1 represents the number of candidate entities obtained through the mapping dictionary; for entity mentions that cannot be mapped, the knowledge graph is searched using two strategies: full match and fuzzy match to obtain a set of candidate entities based on string matching. m2 represents the number of candidate entities obtained through string matching; finally, the candidate entity lists based on the mapping dictionary and string matching are merged to obtain the final candidate entity set
[0046] (3-2) Based on BERT-Softmax, we build an entity disambiguation model that integrates multiple features, modeling entity disambiguation as a binary classification task, and classifying candidate entities using the correlation between the question and the candidate entity context; specifically, given a natural language question Q = [q1,q2,…,q n ], n represents the length of the question; the candidate entity set C = [c1, c2, ..., c m ], m represents the number of candidate entities; candidate entity c i A collection of contextual information Among them D ci is the entity description, R ci =[r1,r2,…,r p ] is the entity relationship set, p represents the number of entity relationships, and the maximum value is k. and R Ci According to the candidate entity c i Retrieved from the knowledge graph, in the process of retrieving entity relations, k different relations are randomly selected as the entity relation set. The input of the entity disambiguation model is [CLS], question Q, [SEP], candidate entity c ithe concatenation of the context information set I of the question Q and the context information set I of the candidate entity, the question Q and the context information set I of the candidate entity are regarded as two independent sentences, text encoding is performed on the two sentences by using a BERT model, and then the hidden layer vector of the [CLS] identifier is taken as the correlation feature between the question and the context of the candidate entity, which is input into a Softmax layer for classification. The process is formalized as formulas 10-12:
[0047]
[0048] H [CLS] = BERT (Input) (11)
[0049] P = Softmax (W * H [ClS] +b) (12)
[0050] The output of the model is wherein, P represents the probability of predicting the best candidate entity, P represents the probability of predicting a non-best candidate entity, and the loss function is a cross entropy loss function (Cross Entropy Loss), as shown in formula 13:
[0051]
[0052] wherein, N is the number of samples, y i represents the true label of the i-th sample, represents the predicted label of the i-th sample.
[0053] Further, the step (4) comprises the following specific steps:
[0054] (4-1) In the expansion subgraph process, first, the subject entity is taken as the initial retrieval entity, the one-hop relationship thereof is retrieved from the knowledge graph, and then the semantic similarity between the question and each relationship is calculated. The semantic similarity is taken as the candidate score, the top k triples corresponding to the relationships with the highest scores are selected and added to the problem-related subgraph, and the tail entities corresponding to the top k relationships are taken as the retrieval entities for the next hop. The above process is iterated until the end exit condition is met. When calculating the semantic similarity between the question and the candidate relationship, the BERT model is first used to perform text encoding on the question and the relationship, respectively, and then the average of the output hidden layer vectors is taken as the vector representation of the question and the relationship. Finally, the cosine similarity of the vector representations of the question and the relationship is calculated. The process is formalized as formulas 14-18:
[0055] H Q = BERT ([[CLS], q1, q2, …, q n , [SEP]) (14)
[0056] Q emb = MeanPooling(H Q ) (15)
[0057] H r = BERT([[CLS], e, r, [SEP]]) (16)
[0058] r emb = MeanPooling(H r ) (17)
[0059]
[0060] (4-2)First, the same relationship of the retrieved entity is merged by adopting the relationship merging strategy, and the entity set after relationship merging is all used as the retrieval entity of the next hop. Then, the entity set after relationship merging is sorted by adopting the entity sorting strategy, and the top m entities corresponding to the triplets are added to the question-related subgraph. The entity sorting strategy is similar to the process of entity disambiguation, which aims to select entities more relevant to the semantic of the question to join the question-related subgraph. The entity and its one-hop relationship are used as the context information of the entity, and the entities in the entity set are sorted by calculating the semantic similarity between the question and the context of the entity. The process of calculating the semantic similarity between the question and the context of the entity is shown in formulas 19-23.
[0061] H Q = BERT([[CLS], q1, q2,..., q n , [SEP]]) (19)
[0062] Q emb = MeanPooling(H Q ) (20)
[0063] H context = BERT([[CLS], e, r1, r2,..., r m [SEP]]) (21)
[0064] context emb = MeanPooling(H context ) (22)
[0065]
[0066] Further, step (5) comprises the following specific steps:
[0067] (5-1) The question-related subgraph G QIn the knowledge graph, the entity relationship chain from the topic entity to other non-topic entities through one or more hops is taken as a candidate answer path, and considering the directionality of the relationship in the knowledge graph, the path from the non-topic entity to the topic entity through one or more hops is also taken as a candidate answer path;
[0068] (5-2) Classify the candidate answer paths according to the number of hops and the number of entities. First, according to the number of hops between the start entity and the end entity in the candidate answer path, it can be divided into single-hop paths and multi-hop paths. Secondly, according to the number of topic entities in the candidate answer path, it can be divided into single-entity paths and multi-entity paths.
[0069] (5-3) Different candidate answer path generation strategies are adopted for different types of questions. Given a question Q, a set of topic entities T, and a problem-related subgraph G O For a question containing only one topic entity, generate a single-entity single-hop path Path single_hop and a single-entity multi-hop path Path multi_hop from the topic entity as the start or end point according to the problem-related subgraph, and merge the two paths to obtain the candidate answer path set Path as shown in equation 24:
[0070]
[0071] For a question containing multiple topic entities, in addition to generating a single-entity single-hop path Path single_hop and a single-entity multi-hop path Path multi_hop for each entity, a multi-entity single-hop path Path multi_entity is also generated, and the above paths are merged to obtain the candidate answer path set Path as shown in equation 25.
[0072]
[0073] (5-4) Construct training data for fine-tuning the question and answer matching model. For each question, generate positive sample paths by processing SPARQL query statements in the data set, and generate single-entity single-hop paths, single-entity multi-hop paths, and multi-entity single-hop paths by randomly sampling the relationships of the topic entities as negative sample paths. This sampling method can increase the diversity of relationships in the training data. The candidate answer paths generated in this way are composed of one or more triples, while the question is a natural language that expresses natural fluency. Therefore, in order to avoid the interference of different expressions between the question and the candidate answer path on the model training, the candidate answer path is converted into a natural language form.
[0074] (5-5) Build a question and answer matching model based on a pre-trained language model and a twin network architecture. The input of the model is a question Q = [q1, q2,..., q n] and candidate answer path P = [p1, p2,..., p m ], where P e Path, first encode the question Q and candidate answer path P respectively using the twin network constructed based on the BERT model, then input the hidden layer vectors output by the BERT layer into the MeanPooling layer to calculate the average of each Token hidden layer vector, and then reduce the dimension of the output of the MeanPooling layer through the fully connected layer to obtain the vector representation H Q and H P of the question and the candidate answer path respectively, and finally calculate the cosine similarity between the vector representation of the question and the vector representation of the candidate path as the output of the model, the above process can be formalized as formulas 26-30, where W Q , b Q , W P , b P are parameters to be learned;
[0075] H Q = BERT([[CLS], q1, q2,..., q n , [SEP]]) (26)
[0076] H P = BERT([[CLS], p1, p2,..., p m , [SEP]]) (27)
[0077] Q emb = (W Q *MeanPooling(H Q )+b Q ) (28)
[0078] P emb = (W P *MeanPooling(H P )+b P ) (29)
[0079]
[0080] In the training stage, the Mean Squared Error Loss is used as the loss function of the model, as shown in formula 31, and the model minimizes the loss function by reducing the difference between the predicted value and the true value. In the test stage, the candidate answer path with the highest cosine similarity output by the model is taken as the best path, and the answer set of the question is obtained by searching the best path in the problem-related subgraph;
[0081]
[0082] where N is the number of samples, yi represents a true value of the i-th sample, represents a predicted value of the i-th sample.
[0083] The application also provides a domain knowledge question answering system running the above knowledge graph question answering method based on subgraph retrieval optimization, which comprises user login, domain knowledge question answering, domain entity and relationship retrieval, question and answer history record and other functional modules, and the overall architecture of the system comprises an offline part and an online part, wherein the offline part completes tasks such as preprocessing and storage of the knowledge graph and training of the knowledge question answering model, and the online part realizes real-time interaction with the user through knowledge graph retrieval and question answering model calling, so as to ensure that the system can respond to the user's request in time and quickly.
[0084] Specifically, the offline part is responsible for providing data and model support for the online part, comprising a data acquisition module and a model training module, wherein the data acquisition module cleans the existing domain knowledge graph and stores it in the Neo4j graph database, and adopts a rule template-based method to construct a domain question and answer data set; the model training module migrates the proposed knowledge graph-based question answering model to the domain, trains each sub-module in the knowledge question answering model by using the domain question and answer data set, and saves the best model for real-time calling by the online module.
[0085] The online part is responsible for interaction with the user, responds to the request issued by the user and renders the result to the user interface, comprising a web interaction module, a question and answer service module, a question and answer record management module, a knowledge retrieval module and a permission management module, wherein the web interaction module provides an interface for the user to interact with the system, is responsible for forwarding the request issued by the user on the front-end page, and returns the data responded by other modules to the user; the question and answer service module receives the question and answer request issued by the user from the front end, calls the knowledge question answering model to analyze the question and returns the answer to the user; the question and answer record management module manages the user's question record, provides question and answer history record updating and query interface; the knowledge retrieval module retrieves and returns related knowledge from the Neo4j graph database according to the user's retrieval demand; and the permission management module is responsible for authenticating the user's identity and access permission, so as to ensure that the system normally operates according to the safety rules and safety strategies set by the administrator.
[0086] Advantages: Compared with the prior art, the application has the following advantages by adopting the above technical scheme:
[0087] (1) For the entity ambiguity problem existing in the knowledge graph question answering, the application designs an entity disambiguation model fusing multiple entity features, fully utilizes the entity name, entity description and entity relationship of the candidate entity to enrich the context information of the candidate entity, and realizes candidate entity disambiguation.
[0088] (2) In view of the problem of large scale of complex question sentence subgraph, the application provides a subgraph retrieval algorithm based on relation merging and entity sorting, on the basis of the bundle search algorithm, the relation merging strategy and the entity sorting strategy are adopted to screen the relations and entities added to the subgraph, so that the scale of the subgraph is effectively reduced. BRIEF DESCRIPTION OF DRAWINGS
[0089] Figure 1 is the overall framework diagram of the application;
[0090] Figure 2 is the entity recognition model schematic diagram;
[0091] Figure 3 is the entity disambiguation model schematic diagram;
[0092] Figure 4 is the question and answer matching model diagram;
[0093] Figure 5 is the system architecture diagram of the application. DETAILED DESCRIPTION
[0094] The technical solutions of the application will be described in detail below.
[0095] The following is only one embodiment of the application, and the application has other various implementation manners, and those skilled in the art can make various corresponding changes and modifications according to the application without departing from the spirit and essence of the application, and these corresponding changes and modifications should all belong to the protection scope of the claims attached to the application.
[0096] The application provides a knowledge graph question and answer method based on subgraph retrieval optimization, and the method comprises the following steps:
[0097] 1. Data preprocessing
[0098] The cleaned knowledge graph data is stored in the database and the query index is established, and the data set required for training the entity recognition and entity linking model is constructed based on the question and answer data set:
[0099] (1-1) The knowledge graph data is cleaned, and the cleaning work includes converting traditional Chinese in the entity relation triplets into simplified Chinese, truncating the entity name with too long length, removing special characters in the relation, unifying the case of English characters, etc.
[0100] (1-2) Entity recognition sequence annotation data is constructed based on the questions and SPARQL query statements in the original question-answering dataset. The entities and relationships are obtained by regular expression matching on SPARQL, and the entity mentions in the questions are reversely annotated. Questions that cannot be annotated are annotated manually. Finally, the dependency relationship between each character is annotated using the BIO annotation method based on the annotated information of the questions, where B (Begin) represents the starting position of the entity, I (Inside) represents the internal position of the entity, and O (Outside) represents the non-entity position;
[0101] (1-3) After obtaining the entity mentions of the question, the Mention2entity file and the knowledge graph in the question-answering dataset are retrieved based on the string matching method to obtain a list of candidate entities, thereby constructing an entity link dataset. The Mention2entity file contains entity mentions, the knowledge graph entities corresponding to the entity mentions, and the popularity of the knowledge graph entities. The entity link dataset consists of positive and negative samples. Here, the candidate entities in the SPARQL query statement are used as positive samples, and the other candidate entities in the candidate entity list are used as negative samples.
[0102] 2. Entity Recognition
[0103] The pre-trained language model is fine-tuned using the entity recognition dataset constructed in step (1). First, the BERT model is used to represent natural questions at the character level. Then, the BiLSTM model is used to further encode the contextual information of the question characters and enhance the vector representation of the characters. Finally, the CRF model is used to predict the entity label of each character to identify entity mentions in the question. The specific steps include:
[0104] (2-1) Entity recognition is modeled as a sequence labeling task, that is, the text is regarded as a sequence, and the label type of each character in the text sequence is predicted by the neural network model to obtain the label sequence of the text; for each character in the question, the dependency relationship between each character is annotated by the BIO labeling method, and the task of the model is transformed into multi-classification of each character in the question, that is, the input question text sequence X = {x1, x2, ..., x n}, x i Represents the i-th character in the question, and the label sequence of the predicted text is Y = {y1, y2, ..., y n},y i Indicates the BIO label corresponding to the i-th character in the question;
[0105] (2-2) Use the BERT model to represent the question at the character level. The BERT model is a dynamic vector representation model. Bidirectional training enables the model to learn contextual information more deeply, thereby dynamically generating character-level or word-level vector representations based on contextual semantics, which can effectively solve the polysemy problem. Here, given a question Q = {q1, q2, ..., q n}, n represents the length of the question. The input of the BERT model is the concatenation of [CLS], question text sequence, and [SEP], that is, S = {[CLS], q1, q2, ..., q n , [SEP]}, [CLS] and [SEP] are special identifiers. For each input character and special identifier, three embedding vector representations are obtained through the Token embedding layer, Segment embedding layer and Position embedding layer respectively. Their sum is used as the input of the Transformer encoder layer. The output of the model is the hidden vector T encoded by the last layer of Transformer encoder. Entity recognition is a sequence labeling task, so only the hidden vector corresponding to the question character is retained in T as the input of the next layer model. The formal formula of the above process is as follows:
[0106] T=[t1,t2,…,t n ]=BERT(S) (1)
[0107] (2-3) Using BiLSTM as the encoder of the model, the information before and after the current moment is utilized through forward propagation and backward propagation, and the two kinds of information are combined as the model output at the current moment, thereby obtaining more comprehensive semantic information. For the character-level vector representation T of the question, the encoding process of BiLSTM can be formalized as the following formula:
[0108]
[0109]
[0110] H=[h1,h2,…,h n ] (4)
[0111] Among them, H represents the intermediate representation vector after the BiLSTM encoding layer, represents the hidden state of the forward LSTM, represents the hidden state of the backward LSTM, After the BiLSTM encoding layer, a fully connected layer is used to reduce the dimension and map it to the output space where the entity label is located through nonlinear transformation. The final output of the BiLSTM encoding layer is P = [p1, p2, ..., p n ], p i The dimension is the number of entity labels k;
[0112] (2-4) Using the CRF model, the constraint relationship between the labels is learned to obtain the optimal label sequence, thereby improving the accuracy of entity recognition. Specifically, it is assumed that there is a transition score matrix A, and the elements in the matrix represent the transition score from label y i to label y j . The output of the BiLSTM encoding layer represents the score of the i-th character being predicted as label y i . For the predicted label sequence Y = {y1, y2, …, y h}, the label sequence score is:
[0113]
[0114] The label sequence score is normalized to obtain the probability of the predicted label sequence Y:
[0115]
[0116] wherein represents the true label sequence, and Y X represents all possible predicted label sequences. Taking the logarithm of both sides of the above formula, the likelihood function of the predicted label is obtained:
[0117]
[0118] In the training phase, the goal of the model is to maximize the logarithmic likelihood function of the correctly predicted label sequence, that is, to minimize the loss function. Through the back propagation algorithm, the gradient of each weight parameter is solved, and the gradient descent algorithm is used for parameter update. The model uses the cross entropy loss function (Cross Entropy Loss) to calculate the loss, and the loss function is defined as follows:
[0119]
[0120] wherein x i represents the i-th character in the question, y i represents the BIO label corresponding to the i-th character in the question, and P(y i | x i ) represents the probability that the model predicts the i-th character as label y i .
[0121] In the test phase, the following Viterbi algorithm is used to obtain the label sequence with the highest prediction score as the optimal label sequence:
[0122]
[0123] The Viterbi algorithm is a dynamic programming algorithm that finds the globally optimal solution by computing the locally optimal solution at each position, i.e., starting from the last position, choosing the label with the maximum probability value as the optimal label, and backtracking to the first position, repeating the process until the optimal label path for the entire sequence is found.
[0124] 3. Entity linking
[0125] According to the entity linking dataset constructed in step (1), three strategies of mapping dictionary matching, knowledge graph entity accurate matching and knowledge graph entity fuzzy matching are used to recall the candidate entity set corresponding to the entity mention from the knowledge graph, and then the pre-trained language model is used to model the text information. For each entity mention and candidate entity pair, the semantic information of the question is used as the context feature of the entity mention, and the entity name, entity description and entity relationship of the candidate entity are used as the context feature of the candidate entity. Finally, the correlation between the context features of the entity mention and the candidate entity is used to disambiguate the candidate entity to obtain the topic entity of the question:
[0126] (3-1) Two methods based on mapping dictionary and string matching are used to complete the candidate entity generation task. First, based on the Mention2entity file, a mapping dictionary of entity mention to knowledge graph entity is constructed, and to solve the problem of entity alias, abbreviation, etc., the alias, Chinese name, English name and abbreviation of the entity are retrieved from the knowledge graph to expand the mapping dictionary. Then, the candidate entity list of the entity mention in the question is generated. First, the pre-constructed mapping dictionary is retrieved to obtain the candidate entity set generated based on the mapping dictionary m1 represents the number of candidate entities obtained by mapping dictionary; for the entity mention that cannot be mapped, two strategies of exact matching and fuzzy matching are used to retrieve the knowledge graph to obtain the candidate entity set based on string matching m2 represents the number of candidate entities obtained by string matching; finally, the candidate entity lists based on mapping dictionary and string matching are combined to obtain the final candidate entity set
[0127] (3-2) Building an entity disambiguation model based on BERT-Softmax to fuse multiple features; the essence of entity disambiguation is to calculate the relevance between entity mention and candidate entity, and select the candidate entity with the highest relevance as the best candidate entity; considering that the triples in the knowledge graph usually represent <entity, relationship, entity> or <entity, attribute, attribute value>, therefore, the different entities can be distinguished according to the relationship and attribute of the entity, and the semantic information of the question and the context information of the candidate entity are taken as the disambiguation features of the entity mention and the candidate entity respectively, so as to select the best candidate entity according to the relevance between the question semantic and the candidate entity context; specifically, given a natural language question Q = [q1, q2, …, qn], n represents the length of the question; candidate entity set C = [c1, c2, …, cm], m represents the number of candidate entities; the context information set I of candidate entity c n m i The entity relationship set is obtained by retrieving the candidate entity c i from the knowledge graph, and k different relationships are randomly selected as the entity relationship set in the process of retrieving the entity relationship; the input of the entity disambiguation model is the concatenation of [CLS], question Q, [SEP], context information set I of candidate entity c i , and [SEP], the question Q and the context information set I of the candidate entity are regarded as two independent sentences, and the text is encoded by the BERT model, and then the hidden layer vector of the [CLS] identifier is taken as the relevance feature between the question and the context of the candidate entity, which is input into the Softmax layer for classification, which is formalized as formulas 10-12:
[0128]
[0129] H [CLS] = BERT (Input) (11)
[0130] P = Softmax (W*H [CLS] +b) (12)
[0131] The output of the model is wherein, P represents the probability of predicting the best candidate entity, P represents the probability of predicting the non-best candidate entity, and the loss function is the cross entropy loss function (Cross Entropy Loss), as shown in formula 13:
[0132]
[0133] where N is the number of samples, y i denotes the true label of the i-th sample, denotes the predicted label of the i-th sample.
[0134] 4. Subgraph retrieval
[0135] Based on the set of theme entities obtained in step (3), a subgraph retrieval algorithm based on relation merging and entity ranking is proposed, and the idea of bundle search is used to dynamically expand the problem-related subgraph of theme entities. First, the repeated relations of retrieval entities are merged based on the relation merging strategy, and then the semantic similarity between the question and the entity relation and the semantic similarity between the question and the neighbor entity are used to rank the entity relation and the neighbor entity respectively. Finally, a fixed number of entity relations and neighbor entities are selected according to the ranking of the entity relations and the neighbor entities to expand the subgraph. The specific steps include:
[0136] (4-1) In the process of expanding the subgraph, first, the theme entity is taken as the initial retrieval entity, and its one-hop relation is retrieved from the knowledge graph. Then, the semantic similarity between the question and each relation is calculated, and the semantic similarity is taken as the candidate item score. The top k triples corresponding to the relations with the highest scores are added to the problem-related subgraph, and the tail entities corresponding to the top k relations are taken as the retrieval entities for the next hop. The above process is iterated until the end exit condition is met. In calculating the semantic similarity between the question and the candidate relation, the BERT model is first used to encode the question and the relation respectively, and then the average of the output hidden layer vectors is taken as the vector representation of the question and the relation. Finally, the cosine similarity of the question vector representation and the relation vector representation is calculated. The formula of this process is 14-18:
[0137] H Q = BERT([[CLS], q1, q2, …, q n , [SEP]]) (14)
[0138] Q emb = MeanPooling(H Q ) (15)
[0139] Hr = BERT([[CLS], e, r, [SEP]]) (16)
[0140] r emb = MeanPooling(H r ) (17)
[0141]
[0142] (4-2) Considering that in large-scale knowledge graphs, the same entity can have the same relationship with multiple different entities, first, the relationship merging strategy is adopted to merge the same relationship of the retrieved entity, and the entity set after relationship merging is all taken as the retrieval entity of the next hop, which can reduce the semantic similarity calculation of the question and the candidate relationship while increasing the diversity of the candidate relationship; However, this also leads to the increase of the size of the subgraph. In order to alleviate the introduced noise entity and relationship, the entity sorting strategy is adopted to sort the entity set after relationship merging, and the top m entities corresponding to the triple are added to the problem-related subgraph. The entity sorting strategy is similar to the process of entity disambiguation, which aims to select the entity more related to the semantic of the question to join the problem-related subgraph. The entity and its one-hop relationship are used as the context information of the entity, and the semantic similarity between the question and the context of the entity is calculated to sort the entities in the entity set. The semantic similarity calculation process of the question and the context of the entity is shown in formulas 19-23:
[0143] H Q = BERT([[CLS], q1, q2,..., q n , [SEP]]) (19)
[0144] Q emb = MeanPooling(H Q ) (20)
[0145] H context = BERT([[CLS], e, r1, r2,..., r m [SEP]]) (21)
[0146] context emb = MeanPooling(H context ) (22)
[0147]
[0148] The subgraph retrieval algorithm based on relationship merging and entity sorting is as follows:
[0149]
[0150]
[0151]
[0152] 5、Question and answer matching
[0153] The question topic entity and question related subgraph information of step (4) are used to generate a relationship path of the topic entity to the candidate answer. A question and answer matching model is built based on a fine-tuned pre-trained language model and a twin network architecture. The relevance between the question and the candidate answer path is used to score all candidate answer paths in the question related subgraph. The entity set corresponding to the candidate answer path with the highest score is taken as the best answer to the question. The specific steps include the following:
[0154] (5-1) The entity relationship chain from the topic entity to other non-topic entities in the question related subgraph G Q is taken as a candidate answer path. Considering the directionality of the relationship in the knowledge graph, the path from the non-topic entity to the topic entity is also regarded as a candidate answer path.
[0155] (5-2) The candidate answer paths are classified according to the number of hops and the number of entities. First, according to the number of hops between the start entity and the end entity in the candidate answer path, it can be divided into single-hop paths and multi-hop paths. Second, according to the number of topic entities in the candidate answer path, it can be divided into single-entity paths and multi-entity paths.
[0156] (5-3) Different candidate answer path generation strategies are adopted for different types of questions. Given a question Q, a topic entity set T, and a question related subgraph G Q , for a question containing only one topic entity, single-entity single-hop paths Path single_hop and single-entity multi-hop paths Path multi_hop are generated according to the question related subgraph, with the topic entity as the start or end point. The candidate answer path set Path is obtained by merging the two paths, as shown in equation 24:
[0157]
[0158] For a question containing multiple topic entities, in addition to generating single-entity single-hop paths Path single_hop and single-entity multi-hop paths Path multi_hop for each entity, multi-entity single-hop paths Path multi_entity are also generated. The candidate answer path set Path is obtained by merging the above paths, as shown in equation 25.
[0159]
[0160] (5-4) Constructing training data for fine-tuning the question-answer matching model; for each question, the positive sample path is obtained by processing the SPARQL query statements in the data set, and the single entity single hop path, single entity multi-hop path and multi-entity single hop path generated by random sampling of the relationship of the subject entity are used as negative sample paths. This sampling method can increase the diversity of relationships in the training data. The candidate answer path generated in this way consists of one or more triples, while the question is a natural language that expresses natural and fluent natural language. Therefore, in order to avoid the interference of different expressions between the question and the candidate answer path on the model training, the candidate answer path is converted into a natural language form;
[0161] (5-5) Building a question-answer matching model based on a pre-trained language model and a twin network architecture; the input of the model is a question Q = [q1, q2,..., q n ] and a candidate answer path P = [p1, p2,..., p m ], wherein P ∈ Path, first using a twin network based on the BERT model to encode the question Q and the candidate answer path P respectively, then inputting the hidden layer vectors output by the BERT layer into the MeanPooling layer to calculate the average value of each Token hidden layer vector, and then reducing the dimension of the output of the MeanPooling layer through the fully connected layer to obtain the vector representation H Q and H P of the question and the candidate answer path respectively, and finally calculating the cosine similarity of the question vector representation and the candidate path vector representation as the output of the model. The above process can be formalized as formulas 26-30, wherein W Q , b Q , W P , b P are parameters to be learned;
[0162] H Q = BERT([[CLS], q1, q2,..., q n , [SEP]]) (26)
[0163] H P = BERT([[CLS], p1, p2,..., p m , [SEP]]) (27)
[0164] Q emb = (W Q *MeanPooling(H Q )+b Q ) (28)
[0165] P emb = (W P *MeanPooling(HP )+b P ) (29)
[0166]
[0167] In the training stage, the Mean Squared Error Loss is used as the loss function of the model, as shown in formula 31, the model minimizes the loss function by reducing the gap between the predicted value and the true value, in the test stage, the candidate answer path with the highest cosine similarity output by the model is taken as the best path, and the answer set of the question is obtained by searching the best path in the question related subgraph, wherein N is the number of samples, y i represents the true value of the i th sample, represents the predicted value of the i th sample.
[0168]
[0169] In the test stage, the candidate answer path with the highest cosine similarity output by the model is taken as the best path, and the answer set of the question is obtained by searching the best path in the question related subgraph.
Claims
1.A knowledge graph question answering method based on subgraph retrieval optimization, characterized in that, The method comprises the following steps: (1) data preprocessing The cleaned knowledge graph data is stored in the database and the query index is established, and the data set required for training the entity recognition and entity linking model is constructed based on the question and answer data set; (2) entity recognition The pre-trained language model is fine-tuned using the entity recognition data set constructed in step (1). First, the BERT model is used to perform character-level vector representation on the natural question, then the BiLSTM model is used to further encode the context information of the question characters, enhance the vector representation of the characters, and finally use the CRF model to predict the entity label of each character to identify the entity in the question; (3) entity linking Using the entities identified in step (2), three strategies of mapping dictionary matching, knowledge graph entity exact matching and knowledge graph entity fuzzy matching are used to recall the entity mention corresponding candidate entity set from the knowledge graph, and then the pre-trained language model is used to model the text information. For each entity mention and candidate entity pair, the semantic information of the question is used as the context feature of the entity mention, and the entity name, entity description and entity relationship of the candidate entity are used as the context feature of the candidate entity. Finally, the correlation between the context features of the entity mention and the candidate entity is used to disambiguate the candidate entity to obtain the topic entity of the question; (4) subgraph retrieval According to the topic entity obtained in step (3), a subgraph retrieval algorithm based on relationship merging and entity sorting is proposed, and a set of search ideas is used to dynamically expand the problem-related subgraph of the topic entity. First, the repeated relationships of the retrieval entity are merged based on the relationship merging strategy, then the semantic similarity between the question and the entity relationship, and the semantic similarity between the question and the neighbor entity are used to sort the entity relationship and the neighbor entity respectively, and finally the multiple subgraphs are selected according to the ranking of the entity relationship and the neighbor entity; (5) question and answer matching Using the multiple subgraphs retrieved in step (4), the relationship path from the topic entity to the candidate answer is generated, and a question and answer matching model is built based on the fine-tuned pre-trained language model and the twin network architecture. The correlation between the question and the candidate answer path is used to score all candidate answer paths of multiple subgraphs, and the entity set corresponding to the candidate answer path with the highest score is taken as the best answer to the question; Step (3) comprises the following specific steps: (3-1) The entity linking module is divided into two tasks, candidate entity generation and entity disambiguation; Among them, the candidate entity generation adopts two methods based on mapping dictionary and string matching. Firstly, based on the Mention2entity file, a mapping dictionary of entity mention to knowledge graph entity is constructed. In view of the problem of entity alias and abbreviation, the alias, Chinese name, English name and abbreviation of the entity are retrieved from the knowledge graph to expand the mapping dictionary. Then, according to the entity mention in the question, a candidate entity list is generated. The mapping dictionary is retrieved first to obtain the candidate entity set generated based on the mapping dictionary m1 represents the number of candidate entities obtained by mapping dictionary; for the entity mention that cannot be mapped, two strategies of complete matching and fuzzy matching are adopted to retrieve the knowledge graph to obtain the candidate entity set based on string matching m2 represents the number of candidate entities obtained by string matching; finally, the candidate entity lists based on the mapping dictionary and string matching are combined to obtain the final candidate entity set (3-2) Based on BERT-Softmax to build an entity disambiguation model that integrates multiple features, modeling entity disambiguation as a binary classification task, and using the relevance between the question and the context of the candidate entity to classify the candidate entity; Specifically, given a natural language question Q = [q1, q2, …, qn], n represents the length of the question; Candidate entity set C = [c1, c2, …, cm], m represents the number of candidate entities; The context information set I of the candidate entity c n ] is as follows: m i Wherein is the entity description, is the entity relationship set, p represents the number of entity relationships, and the maximum value is k, and According to the candidate entity c i , the entity relationship set is obtained by searching the knowledge graph, and k different relationships are randomly selected as the entity relationship set during the retrieval of the entity relationship. The input of the entity disambiguation model is the concatenation of [CLS], the question Q, [SEP], the context information set I of the candidate entity c i , and [SEP]. The question Q and the context information set I of the candidate entity are regarded as two independent sentences, and the BERT model is used for text encoding. Then the hidden layer vector of the [CLS] identifier is taken as the relevance feature between the question and the context of the candidate entity, which is input into the Softmax layer for classification. This process is formalized as formulas 10-12: H [CLS] = BERT(Input) (11) P=Softmax(W*H [CLS] +b) (12) The output of the model is wherein, represents the probability of being predicted as the best candidate entity, represents the probability of being predicted as a non-best candidate entity, and the loss function is a Cross Entropy Loss, as shown in Equation 13: where N is the number of samples, y i represents the true label of the i-th sample, represents the predicted label of the i-th sample. 2.The method of claim 1, wherein, Step (1) comprises the following specific steps: (1-1) Clean the knowledge graph data, and the cleaning work includes converting traditional Chinese in entity relationship triples to simplified Chinese, truncating entity names with excessive length, removing special characters in relationships, and unifying the case of English characters; (1-2) According to the question sentence in the original question and answer data set, the entity recognition sequence labeling data is constructed, the entity and relationship in the SPARQL are obtained by regular expression matching, so as to inversely label the entity mention in the question, and the question which cannot be labeled is labeled by artificial labeling, and finally the dependency relationship between each character is labeled according to the labeling information of the question sentence by using BIO labeling method, wherein B (Begin) represents the start position of the entity, I (Inside) represents the internal position of the entity, and O (outside) represents the non-entity position; (1-3) After obtaining the entity mention of the question, the candidate entity list is obtained by searching the Mention2entity file and knowledge graph in the question and answer data set based on the string matching method, so as to construct the entity linking data set, wherein the Mention2entity file contains entity mention, knowledge graph entity corresponding to the entity mention and popularity of the knowledge graph entity, and the entity linking data set is composed of positive and negative samples, wherein the candidate entity in the SPARQL query statement is taken as the positive sample, and the other candidate entities in the candidate entity list are taken as the negative sample. 3.The method of claim 1, wherein, Step (2) includes the following specific steps: (2-1) Entity recognition is modeled as a sequence labeling task, that is, the text is regarded as a sequence, and the label type of each character in the text sequence is predicted by the neural network model to obtain the label sequence of the text, where the input question text sequence X = {x1, x2, ..., x n }, x i Represents the i-th character in the question, and the label sequence of the predicted text is Y={y1,y2,…,y n },y i Indicates the BIO label corresponding to the i-th character in the question; (2-2) Use the BERT model to represent the question at the character level. Given a question Q = {q1,q2,…,q n }, n represents the length of the question. The input of the BERT model is the concatenation of [CLS], question text sequence, and [SEP], that is, S = {[CLS],q1,q2,…,q n , [SEP]}, [CLS] and [SEP] are special identifiers. For each input character and special identifier, three embedding vector representations are obtained through the Token embedding layer, Segment embedding layer and Position embedding layer respectively. Their sum is used as the input of the Transformer encoder layer. The output of the model is the hidden vector T encoded by the last layer of Transformer encoder. Entity recognition is a sequence labeling task, so only the hidden vector corresponding to the question character is retained in T as the input of the next layer model. The formal formula of the above process is as follows: T = [t1, t2,..., t n ] = BERT(S) (1) (2-3) BiLSTM is used as the encoder of the model, the information before and after the current time is used by forward propagation and backward propagation, and the two kinds of information are combined as the model output of the current time, so as to obtain more comprehensive semantic information, and for the character level vector representation T of the question, the encoding process of BiLSTM can be formalized as the following formula: H = [hi, h2,..., h n ] (4) wherein H represents an intermediate representation vector through a BiLSTM encoding layer, denotes a hidden state of a forward LSTM, denotes a hidden state of a backward LSTM, A fully connected layer is used for dimension reduction after the BiLSTM encoding layer, which is mapped to an output space where entity labels are located through a nonlinear transformation, and the final output of the BiLSTM encoding layer is P = [p1, p2, …, p n ], the dimension of p i is the number of entity labels k; (2-4) Using the CRF model to obtain the optimal label sequence by learning the constraint relationship between labels, so as to improve the accuracy of entity recognition. Specifically, assuming that there is a transition score matrix A, the elements in the matrix represent the transition score from label y i to label y j , the output of the BiLSTM encoding layer represents the score of the i-th character predicted as label y i , and for the predicted label sequence Y={y1,y2,…,y n}, the label sequence score is: The label sequence score is normalized to obtain the probability of the predicted label sequence Y: where Y represents the true label sequence, Y X represents all possible predicted label sequences, and taking the logarithm of both sides of the above equation gives the likelihood function of the predicted label: In the training stage, the goal of the model is to maximize the log likelihood function of the correctly predicted label sequence, that is, to minimize the loss function, the gradient of each weight parameter is solved by the back propagation algorithm, and the parameter is updated by using the gradient descent algorithm, the model uses the cross entropy loss function (Cross Entropy Loss) to calculate the loss, and the loss function is defined as follows: where x i represents the i-th character in the question, y i represents the BIO tag corresponding to the i-th character in the question, P(y i | x i ) represents the probability that the model predicts the i-th character as the tag y i ; In the test stage, the label sequence with the highest prediction score is taken as the optimal label sequence by using the following Viterbi algorithm, 4.The method of claim 1, wherein, Step (4) includes the following specific steps: (4-1) In the process of expanding the subgraph, first, the theme entity is taken as the initial retrieval entity, the one-hop relationship thereof is retrieved from the knowledge graph, then the semantic similarity between the question and each relationship is calculated, the semantic similarity is taken as the candidate score, the top k relationships corresponding to the triplets with the highest score are selected and added to the problem related subgraph, and the tail entities corresponding to the top k relationships are taken as the retrieval entities of the next hop, the above process is iterated until the end exit condition is met; wherein when calculating the semantic similarity between the question and the candidate relationship, the BERT model is used to encode the text of the question and the relationship respectively, then the average of the hidden layer vector representations is taken as the vector representation of the question and the relationship, and finally the cosine similarity of the question vector representation and the relationship vector representation is calculated, and the process is formalized as 14-18: H Q = BERT([[CLS], q1, q2,..., q n , [SEP]]) (14) Q emb = MeanPooling(H Q ) (15) H r = BERT([[CLS], e, r, [SEP]]) (16) r emb = MeanPooling(H r ) (17) (4-2) Firstly, the same relations of the search entities are merged by using the relation merging strategy, and the entity set after the relation merging is all taken as the search entity of the next hop. Then, the entity set after the relation merging is sorted by using the entity sorting strategy, and the first m entities corresponding to the triples are added to the question-related subgraph. The entity sorting strategy is similar to the process of entity disambiguation. The semantic similarity calculation process of the question and the entity context is shown in formulas 19-23. H Q = BERT([[CLS], q1, q2,..., q n , [SEP]]) (19) Q emb = MeanPooling(H Q ) (20) H context = BERT([[CLS], e, r1, r2,..., r m [SEP]]) (21) context emb = MeanPooling(H context ) (22) 5.The method of claim 1, wherein, Step (5) includes the following specific steps: (5-1) The problem-related subgraph G Q In the above-mentioned entity relationship chain, the entity relationship chain from the theme entity to other non-theme entities is regarded as a candidate answer path. Considering the directionality of the relationship in the knowledge graph, the path from the non-theme entity to the theme entity is also regarded as a candidate answer path. (5-2) The candidate answer paths are classified according to the number of hops and the number of entities. Firstly, according to the number of hops between the start entity and the end entity in the candidate answer path, the candidate answer paths are divided into single-hop paths and multi-hop paths. Secondly, according to the number of theme entities in the candidate answer path, the candidate answer paths are divided into single-entity paths and multi-entity paths. (5-3) Different candidate answer path generation strategies are taken for different types of questions, given a question Q, a set of topic entities T and a question-related subgraph G Q For a question containing only one topic entity, a single-entity single-hop path Path starting or ending with the topic entity is generated according to the question-related subgraph single_hop and a single-entity multi-hop path Path multi_hop The two paths are merged to obtain a set of candidate answer paths Path, as shown in equation 24: For the question sentence containing multiple topic entities, in addition to generating single-entity single-hop path Path single_hop and single-entity multi-hop path Path multi_hop , the multi-entity single-hop path Path multi_entity is also generated simultaneously, and the candidate answer path set Path is obtained by merging the above paths, as shown in formula 25; (5-4) Training data is constructed for fine-tuning the question and answer matching model. For each question, the positive sample paths are obtained by processing the SPARQL query statements in the data set. The single-entity single-hop path, the single-entity multi-hop path and the multi-entity single-hop path generated by randomly sampling the relations of the theme entities are taken as the negative sample paths. The candidate answer paths generated in this way are composed of one or more triples, and the candidate answer paths are converted into natural language form. (5-5) Building a question and answer matching model based on a pre-trained language model and a twin network architecture, the input of the model is a question Q = [q1, q2, …, q n ] and a candidate answer path P = [p1, p2, …, p m ], where P e Path, first using a twin network based on BERT model to encode the question Q and the candidate answer path P respectively, then input the hidden layer vector output by the BERT layer into the MeanPooling layer, calculate the average value of each Token hidden layer vector, and then reduce the dimension of the output of the MeanPooling layer through the full connection layer to obtain the vector representation H Q and H P of the question and the candidate answer path respectively, finally calculate the cosine similarity of the question vector representation and the candidate path vector representation as the output of the model, the above process can be formalized as formulas 26-30, wherein W Q , b Q , W P , b P are parameters to be learned; H Q = BERT([[CLS], q1, q2,..., q n , [SEP]]) (26) H P = BERT([[CLS], p1, p2, …, p m , [SEP]]) (27) Q emb = (W Q *MeanPooling(H Q )+b Q ) (28) P emb = (W P *MeanPooling(H P )+b P ) (29) In the training stage, the mean squared error loss (Mean Squared Error Loss) is used as the loss function of the model, as shown in formula 31. The model minimizes the loss function by reducing the gap between the predicted value and the true value. In the test stage, the candidate answer path with the highest cosine similarity output by the model is taken as the best path, and the answer set of the question is obtained by searching the best path in the question-related subgraph. where N is the number of samples, y i represents the true value of the i-th sample, represents the predicted value of the i-th sample.
Citation Information
Patent Citations
Knowledge graph question-answering method and device
CN111639171A
Intelligent question and answer system based on knowledge graph subgraph retrieval
CN113297369A