Multi-hop reading comprehension method and system based on dual-view contrast learning and graph pruning
Through the deep learning network model of dual-view comparison learning and graph pruning, the problems of multi-grained information integration and noise impact in multi-hop reading comprehension are solved, and the accuracy of answer prediction and the context semantic understanding of the model are improved.
Patent Information
- Application Number
- CN202310398450.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-14
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2043-04-14
AI Technical Summary
The existing multi-hop reading comprehension model has shortcomings in the semantic representation between the fusion text and the problem, it is difficult to effectively integrate multi-grained information, and is susceptible to similarity noise, resulting in low accuracy in answer prediction.
A deep learning network model based on dual-view contrast learning and graph pruning is adopted. By constructing a hierarchical graph, using dual-view contrast learning and graph pruning technology, candidate answers are selected to improve the model's context semantic understanding ability.
It improves the accuracy of multi-hop reading comprehension answer prediction, can more effectively distinguish multi-grained context information and interference information, weakens the impact of similarity noise on the model, and enhances the model's ability to pay attention to the correct answer.
Smart Images

Figure CN116403231B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of natural language processing, and specifically relates to a multi-hop reading comprehension method and system based on dual-view contrast learning and graph pruning. Background Art
[0002] Machine reading comprehension is a crucial component of human-computer question-answering systems, aiming to enable computers to achieve human-like understanding of text. Unlike information retrieval tasks, machine reading comprehension isn't simply about matching a question to the most similar strings in a text database. Instead, it aims to understand natural language questions posed by users. The answers to these questions may be contained within the text itself, perhaps with a "yes" or "no" response, or unanswerable. The machine may even need to generate or compute the correct answer based on its own understanding. Multi-hop reading comprehension involves questions that cannot be answered within a single paragraph or document, requiring a chain of reasoning involving at least two document hops. Compared to traditional reading comprehension problems, this requires a more robust model's reasoning capabilities, requiring greater interpretability and scalability. Accurate understanding of text semantics impacts the performance of various downstream learning tasks within human-computer question-answering systems. Simply matching text with question words ignores the specific semantic information of the text. Therefore, acquiring authentic text semantics is crucial.
[0003] In recent years, with the emergence of pre-trained models such as GPT and BERT, and their significant performance improvements on reading comprehension tasks, a number of excellent pre-trained language models have emerged. While significant breakthroughs have been achieved in simple, single-hop reading comprehension tasks such as SQuAD, TriviaQA, and SearchQA, researchers have gradually shifted their focus to multi-hop and reasoning scenarios, which better test the model's understanding. The multi-hop dataset HotpotQA offers various reasoning strategies, encompassing a variety of question types, each corresponding to multiple documents. Based on the different question types, the model should construct a multi-hop reasoning chain across multiple documents, integrating the information along the chain to arrive at the final answer. Due to the success of single-hop tasks, many methods have been adopted across tasks, such as multi-task methods to assist in answer prediction for the main task. However, most studies still use retrieval to identify passages that may contain the correct answer, followed by single-document answer prediction methods. Because multi-hop reasoning requires the simultaneous application of information at different granularities, a single retrieval approach cannot effectively integrate the collected reasoning evidence. Because graph neural networks can effectively organize dependencies between nodes, many models have proposed entity word graphs, relational graphs, or mixed paragraph and entity word graphs. These graph neural network approaches better integrate fine-grained information, allowing answers to be selected from entity words after the graph network layer. However, the graphs constructed by these methods fail to consider supporting factual information and simply integrate paragraph and entity word information for answer prediction. In response, some research works have constructed multi-granularity heterogeneous graphs using paragraphs, sentences, and entity words. These graphs use graph attention mechanisms to integrate contextual dependencies between information at different granularities, leverage updated node identifiers for different subtasks, and introduce span prediction modules for final answer prediction across various question types. However, multi-level, fine-grained graphs combine all clues into a single graph, making it difficult to explain the model's decisions. The sheer number of multi-granular information makes it challenging to capture key information. Graph neural network approaches rely heavily on adjacency matrices, lacking scalability.
[0004] In summary, while graph attention networks have achieved some success in fusing semantic representations between text and questions, they still have shortcomings in semantic understanding and are easily affected by similarity noise in evidence sentences. Analysis of the human reading comprehension process shows that when reading answers, people typically need to consider the question to identify the key information that the answer should contain, list candidate answers, and then use these candidate answers to determine the correct answer. When reading, humans typically arrive at the correct answer by discerning key information and distracting information in the passage and question. Summary of the Invention
[0005] The purpose of the present invention is to provide a multi-hop reading comprehension method and system based on dual-view contrast learning and graph pruning, which is conducive to improving the accuracy of multi-hop reading comprehension answer prediction.
[0006] To achieve the above objectives, the present invention adopts a technical solution: a multi-hop reading comprehension method based on dual-view contrast learning and graph pruning, comprising the following steps:
[0007] Step A: Collect questions, article context, answers, and supporting factual data to construct a multi-hop reading comprehension training set;
[0008] Step B: Use the training set to train a deep learning network model D based on dual-view contrastive learning and graph pruning for multi-hop reading comprehension;
[0009] Step C: Input the question and article data into the deep learning network model D and output the corresponding answer to the current question.
[0010] Furthermore, the step B specifically includes the following steps:
[0011] Step B1: Use the pre-trained model Roberta to calculate the probability that each paragraph of each sample in the training set contains the golden supporting fact. At the same time, perform text matching on the relationship between the title and paragraph of each sample and the question to obtain N candidate paragraphs p candi ={p1, p2, ..., p N};
[0012] Step B2: The candidate paragraph p obtained in step B1 candi Together with questions, sentences in paragraphs, entity words in paragraphs, and hyperlinks, they are used as nodes to construct a hierarchical graph G, and the adjacency matrix A of the hierarchical graph is constructed through the edge relationships of each node in G. adj ;
[0013] Step B3: Use the pre-trained model Roberta to obtain the initial representation of all graph nodes in the hierarchical graph G obtained in step B2, and obtain the node representations of three types: paragraph, sentence, and entity. And the problem node representation f q , in order to obtain the overall node representation of the hierarchical graph
[0014] Step B4: Add the adjacency matrix A of the hierarchical graph obtained in steps B2 and B3 adj The node representation F is used to damage the hierarchical graph twice by randomly deleting edge relationships and randomly masking node features. The two damaged hierarchical graphs are dual views, thus obtaining the adjacency matrix A of the two views. 1 , A 2 and node representation F 1 , F 2 ; Then the two views are input into the graph attention network respectively to obtain the updated node representation
[0015] Step B5: Use the gated attention mechanism to calculate the initial context embedding E and the updated graph node representation Get the correlation coefficient and context representation E G ; At the same time, the adjacency matrix A of the two damaged views 1 , A 2 and the feature matrix F 1 , F 2 Each pair of samples is used as a positive and negative sample, and the cosine similarity is used to calculate the similarity of each pair of samples to obtain the comparative learning loss of the two graphs. Maximize the overall target loss L for the dual-view positive example pair gra ;
[0016] Step B6: The context representation E obtained in step 5 G Contains candidate answer nodes Combine it with the problem node representation f obtained in step B3 q Generate attention weight sparse matrix using relation filtering method Use it to filter the current candidate answer node;
[0017] Step B7: All nodes of different types obtained in steps B4 and B6 are fed into the multilayer perceptron for subtask prediction. The prediction results for paragraphs, supporting facts, entity words, and answer types are obtained. The cross-entropy function is used to calculate the prediction losses for each type. The corresponding type of answer is then returned based on the answer type prediction results. Based on the target loss function, the gradients of the parameters in the deep learning network model are calculated using the backpropagation method, and the parameters are updated using the stochastic gradient descent method.
[0018] Step B8: When the loss value generated by the deep learning network model is less than the set threshold or reaches the maximum number of iterations, the training of the deep learning network model D is terminated.
[0019] Furthermore, the step B1 specifically includes the following steps:
[0020] Step B11: Traverse the training set and for each sample in the training set, use the Roberta model as the encoder to calculate the probability P of each paragraph in the sample containing the gold supporting fact ranking , use P ranking Sort the paragraphs, P ranking Expressed as:
[0021] P ranking =Roberta ranking (P)
[0022] Where, P=(t i , p i ) is the set of paragraphs in the sample, ti For the title of the paragraph, p i For paragraph text;
[0023] The phrase span in the question (q start ,q end ) and the phrase span in the paragraph title If there are multiple paragraphs that match the paragraph title and question, select P ranking The first two paragraphs; if the title does not match the paragraph, the entity word in the question Match entity words in paragraphs If the entity word matching also fails, then take P ranking The highest paragraph, the selected paragraph P sel Expressed as:
[0024]
[0025] Among them, p sel Indicates the number of paragraphs whose titles match the questions successfully. Indicates the P selected in this case ranking The first two paragraphs; e sel Indicates whether the entity word in the question matches the paragraph successfully, e sel >0 indicates successful matching; P esel Indicates that the problem in this case is matched with the paragraph entity word; P eesl Indicates the matching results between question and paragraph entity words;
[0026] Step B12: The result of step B11, P sel The second-hop paragraph is searched for by the hyperlink in the corresponding data set; the paragraph selected in the first hop is used to build a bidirectional edge (q, p i ), if the second hop paragraph exists, a bidirectional edge (p i , p j ), p i is the paragraph selected in the first jump, p j is the paragraph selected in the second jump; get n candidate paragraphs p candi ={p1, p2, ..., p n}, use P ranking Select the top N paragraphs and get N candidate paragraphs p candi ={p1, p2, ..., p N}.
[0027] Furthermore, the step B2 specifically includes the following steps:
[0028] Step B21: For each sample in the training set, construct a hierarchical graph G with the paragraphs, sentences in each paragraph, entity words in each sentence, and the question matched in step B1. Define four types of nodes and seven types of edge relationships in the hierarchical graph:
[0029] G = {V, E}
[0030] Among them, V is the question node q and the matched paragraph node p candi ={p1, p2, .., p N}、Sentence nodes in each paragraph Entity word nodes in each sentence The set of N, n s , n e Respectively represent the number of paragraphs, sentences, and entity word nodes in the hierarchical graph; E is a set of seven edge relationships;
[0031] Step B22: Construct the adjacency matrix A using the edge relationships of each node in the hierarchical graph G adj :
[0032]
[0033] Among them, A ij Non-zero means that the relationship between the two nodes belongs to a type in set E, and zero means that there is no relationship in set E between the two nodes.
[0034] Furthermore, the step B3 specifically includes the following steps:
[0035] Step B31: Merge the selected paragraphs corresponding to the question in each training sample, concatenate them with the question, and then input Roberta to obtain the initial representation; obtain the question representation through the mutual attention layer and paragraph context representation Among them, m and n are the number of questions and paragraphs respectively, and d represents the dimension of the representation vector;
[0036] Step B32: Process the question and context representation separately. In the context representation, different types of nodes are calculated in the form of spans. The Bi-LSTM network is used to extract the node representations of paragraphs, sentences, and entities.
[0037]
[0038]
[0039]
[0040] in, Indicates the start and end positions of a paragraph node. The representation of a sentence node is similar to that of an entity node. [;] represents the concatenation of two vectors. The left and right sides represent the forward and backward calculations of the Bi-LSTM, respectively.
[0041] Step B33: Pass the problem node through the maximum pooling layer to obtain the node representation f q :
[0042] f q =maxpooling(Q).
[0043] Furthermore, the step B4 specifically includes the following steps:
[0044] Step B41: For a hierarchical graph G = (V, E), V is the set of nodes in the graph, and E is the set of edge relationships in the graph; the adjacency matrix of the graph is The adjacency matrix A adj Convert to a sparse matrix A coo , randomly construct a masking matrix according to the number of nodes As a masking matrix, when A adj When there is an edge relationship in , the masking matrix is assigned a value, which is calculated according to the Bernoulli distribution:
[0045]
[0046] in, is the Bernoulli distribution, p v is the customized masking probability;
[0047] Step B42: Perform Hadamard product on the masking matrix and the original adjacency matrix to obtain the damaged adjacency matrix.
[0048]
[0049] in, is the Hadamard product, which generates two adjacency matrices:
[0050] Step B43: Sample a random vector f mask As a d-dimensional masking vector, the values in the vector are extracted using Bernoulli distribution:
[0051]
[0052] Among them, p f is the customized masking probability;
[0053] Step B44: Node features Expand to And do Hadamard product with the masking vector to generate the damaged node feature
[0054]
[0055] in,[·] T For the transposition operation, the original node features are masked and damaged twice to generate two feature matrices:
[0056] Step B45: Assume that the set of adjacent nodes in the graph is Calculate the correlation coefficient e between node i and neighbor nodes of the two graphs generated in step B42 and step B44 ij , and then normalized to get the attention coefficient α ij :
[0057]
[0058]
[0059] Among them, h i is the representation of the currently calculated node i, h j is the neighbor node j of node i, is the shared parameter matrix;
[0060] Step B46: The attention coefficient α of each damaged node feature matrix ij With neighboring nodes Perform weighted calculation to get updated node representation For the updated node features, the calculation process is as follows:
[0061]
[0062] in, is the shared parameter matrix, h′ i is the updated node representation of node i.
[0063] Furthermore, the step B5 specifically includes the following steps:
[0064] Step B51: Let E = {Q, P} be the initial embedding representation of the context encoding layer after Roberta encoding, and calculate the correlation coefficient between the context embedding and the updated graph node using the attention mechanism. Combined with the gating mechanism to obtain the gated context representation
[0065]
[0066]
[0067] in, is the learnable parameter matrix;
[0068] Step B52: For Figure A 1 Any node on Figure A 2 The corresponding node in is a positive sample, Figure A 2 The remaining nodes in Graph A 1 The rest of the nodes in A are negative samples. 2 For A 1 The same calculation is also used; the loss of two graph samples is calculated using cosine similarity The training target of the positive pair is e pv , the training objective of the negative pairs is The training objective of the negative example pair in the other figure is
[0069]
[0070]
[0071]
[0072]
[0073] in, A 1 Medium The set of other nodes except A 2 Medium The set of other nodes except , τ is the temperature coefficient, cos() is the cosine similarity calculation;
[0074] Step B53: Maximize the overall target loss L for the dual-image positive example pair gra The task loss for this module is:
[0075]
[0076] Furthermore, the step B6 specifically includes the following steps:
[0077] Step B61: Compare the context-encoded question representation fq with the updated candidate answer node Use attention mechanism to generate attention matrix
[0078]
[0079] Step B62: Sort the attention matrix generated in step B61 in descending order of dimension to generate a matrix Then the most closely connected N in the matrix relation Relationships are retained to generate a more accurate attention weight sparse matrix
[0080]
[0081]
[0082] Among them, sort() is a descending sort function, f Pruning () is the pruning function;
[0083] Step B63: Combine the attention weight sparse matrix generated in step B62 with the candidate answer node Multiply to get the filtered candidate answer node
[0084]
[0085] Furthermore, the step B7 specifically includes the following steps:
[0086] Step B71: For paragraph nodes and sentence nodes in the graph, use a binary classification multi-layer perceptron to perform paragraph prediction and sentence prediction; for entity word nodes, use a multi-classification multi-layer perceptron to perform entity word prediction:
[0087]
[0088]
[0089]
[0090] in, represents the probability that the paragraph contains supporting facts, represents the probability that the sentence is selected as supporting fact, Indicates the probability that the correct answer exists in the entity node;
[0091] Step B72: Use MLP to predict the answer type based on the hidden state of the gated attention layer:
[0092] p type =MLP7(E G [0])
[0093] Among them, p type is the probability of answer type;
[0094] Step B73: For yes / no answers, directly return the answer; for entity answers, return the entity word prediction result; for span answers, use the hidden state of the above gated attention layer to calculate the span prediction:
[0095] p start =MLP8(E G )
[0096] p end =MLP9(E G )
[0097] Among them, p start 、p end Predict probabilities for span start and end;
[0098] Step B74: Use cross entropy as the loss function to calculate the loss value, update the learning rate through the gradient optimization algorithm Adam, and use back propagation to iteratively update the model parameters to minimize the loss function to train the model; the total model loss is the weighted sum of the losses of the above predictions:
[0099] L all =L start +L end +μ1L para +μ2(L sent +μ gra L gra )+μ3L ent +μ4L type
[0100] Among them, μ1, μ2, μ3, μ4, μ gra is a hyperparameter, L start , L end is the loss of span prediction, L para , L sent , L ent , L type They are the losses for paragraph prediction, sentence prediction, entity word prediction, and answer type prediction respectively.
[0101] The present invention also provides a multi-jump reading comprehension system using the above method, comprising:
[0102] Build a training set module to collect conversation context and answer data and build a conversation training set;
[0103] A model training module for training a deep learning network model D based on dual-view contrast learning and graph pruning; and
[0104] The multi-hop reading comprehension module will be used in the multi-hop reading comprehension process to input questions and articles into the trained deep network model and output the current predicted answer.
[0105] Compared with the existing technology, the present invention has the following advantages: First, the present invention obtains richer contextual mutual information through a graph-based node-level positive and negative sample comparison learning task. The model after comparative learning has richer contextual semantic information and can effectively distinguish multi-granularity contextual information and interference information, so that the model can pay more attention to the range of correct answers related to the question. In addition, the present invention narrows the range of candidate answers by filtering answer nodes through question guidance, uses question representation to construct an attention weight matrix for answer entity nodes, and then uses a relationship screening algorithm to filter this matrix, retaining only the most strongly correlated partial relationships, thereby reducing the noise caused by similarity representation on the model's prediction of candidate answers. BRIEF DESCRIPTION OF THE DRAWINGS
[0106] Figure 1 is a flowchart of a method implementation of an embodiment of the present invention;
[0107] Figure 2 is an architectural diagram of a deep learning network model in an embodiment of the present invention;
[0108] Figure 3 Schematic diagram of the system structure of an embodiment of the present invention. DETAILED DESCRIPTION
[0109] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0110] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which the present application belongs.
[0111] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprise" and / or "include" are used in this specification, they indicate the presence of features, steps, operations, devices, components and / or combinations thereof.
[0112] like Figure 1 As shown, this embodiment provides a multi-hop reading comprehension method based on dual-view contrast learning and graph pruning, including the following steps:
[0113] Step A: Collect questions, article context, answers, and supporting factual data to construct a multi-hop reading comprehension training set.
[0114] Step B: Use the training set to train a deep learning network model D based on dual-view contrast learning and graph pruning for multi-hop reading comprehension. The structure of the deep learning network model in this embodiment is as follows: Figure 2 shown.
[0115] Step C: Input the question and article data into the deep learning network model D and output the corresponding answer to the current question.
[0116] In this embodiment, step B specifically includes the following steps:
[0117] Step B1: Use the pre-trained model Roberta to calculate the probability that each paragraph of each sample in the training set contains the golden supporting fact. At the same time, perform text matching on the relationship between the title and paragraph of each sample and the question to obtain N candidate paragraphs p candi ={p1, p2, ..., p N The step B1 specifically includes the following steps:
[0118] Step B11: Traverse the training set and for each sample in the training set, use the Roberta model as the encoder to calculate the probability P of each paragraph in the sample containing the gold supporting fact ranking , use P ranking Sort the paragraphs, P ranking Expressed as:
[0119] P ranking =Roberta ranking (P)
[0120] Where, P=(t i , p i ) is the set of paragraphs in the sample, t i For the title of the paragraph, p i For paragraph text.
[0121] The phrase span in the question (q start ,q end ) and the phrase span in the paragraph title Match; Problem span (q start ,q end ) refers to the starting and ending position of the phrase in the question, the title span Refers to the starting and ending positions of the phrase in the paragraph title, that is, each paragraph has a title, and the paragraphs whose title phrases exist in the question are retrieved; if there are multiple paragraphs that match successfully when the paragraph title matches the question, select P ranking The first two paragraphs; if the title does not match the paragraph, the entity word in the question Match entity words in paragraphs If the entity word matching also fails, then take P ranking The highest paragraph, the selected paragraph P sel Expressed as:
[0122]
[0123] Among them, p sel Indicates the number of paragraphs whose titles match the questions successfully. Indicates the P selected in this case ranking The first two paragraphs; e sel Indicates whether the entity word in the question matches the paragraph successfully, e sel >0 indicates a successful match; Indicates the paragraph in which the question in this case matches the paragraph entity word; Indicates the matching result between question and paragraph entity words.
[0124] Step B12: The result of step B11 P sel The second-hop paragraph is searched for by the hyperlink in the corresponding data set; the paragraph selected in the first hop is used to build a bidirectional edge (q, p i ), if the second hop paragraph exists, a bidirectional edge (p i , p j ), p i is the paragraph selected in the first jump, p j is the paragraph selected in the second jump; get n candidate paragraphs p candi ={p1, p2, ..., p n}, use p ranking Select the top N paragraphs and get N candidate paragraphs p candi ={p1, p2, ..., p N}.
[0125] Multi-jump reading comprehension means that the answer to the question must be obtained by combining multiple clues in the paragraph, and the clues cannot be retrieved at once. When a clue is found, the next clue must be searched for in the text. This is the meaning of multi-jump. The first jump is the matching result P between the question and the paragraph in step B11. sel , and continue searching using the result of the previous step, which is the second jump.
[0126] Step B2: The candidate paragraph p obtained in step B1 candi Together with questions, sentences in paragraphs, entity words in paragraphs, and hyperlinks, they are used as nodes to construct a hierarchical graph G, and the adjacency matrix A of the hierarchical graph is constructed through the edge relationships of each node in G. adj The step B2 specifically includes the following steps:
[0127] Step B21: For each sample in the training set, construct a hierarchical graph G with the paragraphs, sentences in each paragraph, entity words in each sentence, and the question matched in step B1. Define four types of nodes and seven types of edge relationships in the hierarchical graph:
[0128] G = {V, E}
[0129] Among them, V is the question node q and the matched paragraph node p candi ={p1, p2, .., p N}、Sentence nodes in each paragraph Entity word nodes in each sentence The set of N, n s , n e They represent the number of paragraphs, sentences, and entity word nodes specified in the hierarchical graph respectively; E is a set of seven edge relationships.
[0130] Step B22: Construct the adjacency matrix A using the edge relationships of each node in the hierarchical graph G adj :
[0131]
[0132] Among them, A ii Non-zero means that the relationship between the two nodes belongs to a type in set E, and zero means that there is no relationship in set E between the two nodes.
[0133] Step B3: Use the pre-trained model Roberta to obtain the initial representation of all graph nodes in the hierarchical graph G obtained in step B2, and obtain the node representations of three types: paragraph, sentence, and entity. And the problem node representation f q , in order to obtain the overall node representation of the hierarchical graph The step B3 specifically includes the following steps:
[0134] Step B31: Merge the selected paragraphs corresponding to the question in each training sample, concatenate them with the question, and then input Roberta to obtain the initial representation; obtain the question representation through the mutual attention layer and paragraph context representation Among them, m and n are the number of questions and paragraphs respectively, and d represents the dimension of the representation vector.
[0135] Step B32: Process the question and context representation separately. In the context representation, different types of nodes are calculated in the form of spans. The Bi-LSTM network is used to extract the node representations of paragraphs, sentences, and entities.
[0136]
[0137]
[0138]
[0139] in, Indicates the starting and ending positions of a paragraph node. The representation of a sentence node is similar to that of an entity node. [;] represents the concatenation of two vectors. The left and right sides represent the forward and backward calculations of the Bi-LSTM, respectively.
[0140] Step B33: Pass the problem node through the maximum pooling layer to obtain the node representation f q :
[0141] f q =maxpooling(Q).
[0142] Step B4: Add the adjacency matrix A of the hierarchical graph obtained in steps B2 and B3 adj The node representation F is used to damage the hierarchical graph twice by randomly deleting edge relationships and randomly masking node features. The two damaged hierarchical graphs are dual views, thus obtaining the adjacency matrix A of the two views. 1 , A 2 and node representation F 1 , F 2 ; Then the two views are input into the graph attention network respectively to obtain the updated node representation The step B4 specifically includes the following steps:
[0143] Step B41: For a hierarchical graph G = (V, E), V is the set of nodes in the graph, and E is the set of edge relationships in the graph; the adjacency matrix of the graph is The adjacency matrix A adj Convert to a sparse matrix A coo , randomly construct a masking matrix according to the number of nodes As a masking matrix, when A adj When there is an edge relationship in , the masking matrix is assigned a value, which is calculated according to the Bernoulli distribution:
[0144]
[0145] in, is the Bernoulli distribution, p v is a custom masking probability.
[0146] Step B42: Perform Hadamard product on the masking matrix and the original adjacency matrix to obtain the damaged adjacency matrix.
[0147]
[0148] in, is the Hadamard product, which generates two adjacency matrices:
[0149] Since the dual views are two damaged hierarchical graphs, and the hierarchical graphs in the model layer calculation are mainly composed of the adjacency matrix and node features constructed by the node-edge relationship, the way this method generates the dual views is to damage the adjacency matrix and node features.
[0150] Step B43: Sample a random vector f mask As a d-dimensional masking vector, the values in the vector are extracted using Bernoulli distribution:
[0151]
[0152] Among them, p f is a custom masking probability.
[0153] Step B44: Node features Expand to And do Hadamard product with the masking vector to generate the damaged node feature
[0154]
[0155] in,[·] T For the transposition operation, the original node features are masked and damaged twice to generate two feature matrices:
[0156] Step B45: Assume that the set of adjacent nodes in the graph is Calculate the correlation coefficient e between node i and neighbor nodes of the two graphs generated in step B42 and step B44 ij , and then normalized to get the attention coefficient α ij :
[0157]
[0158]
[0159] Among them, h i is the representation of the currently calculated node i, h j is the neighbor node j of node i, is the shared parameter matrix.
[0160] Step B46: The attention coefficient α of each damaged node feature matrix ij With neighboring nodes Perform weighted calculation to get updated node representation For the updated node features, the calculation process is as follows:
[0161]
[0162] in, is the shared parameter matrix, h′ i is the updated node representation of node i.
[0163] Here It refers to the characteristic matrix of any damaged node, and the subsequent operations of the two characteristic matrices are the same, so this is used as a substitute. i and It is an inclusion relation, h′ i refers to the representation of node i, and Refers to the representation of all nodes in the graph.
[0164] Step B5: Use the gated attention mechanism to calculate the initial context embedding E and the updated graph node representation Get the correlation coefficient and context representation E G ; At the same time, the adjacency matrix A of the two damaged views 1 , A 2 and the feature matrix F 1 , F 2 Each pair of samples is used as a positive and negative sample, and the cosine similarity is used to calculate the similarity of each pair of samples to obtain the comparative learning loss of the two graphs. Maximize the overall target loss L for the dual-view positive example pair gra The step B5 specifically includes the following steps:
[0165] Step B51: Let E = {Q, P} be the initial embedding representation of the context encoding layer after Roberta encoding, and calculate the correlation coefficient between the context embedding and the updated graph node using the attention mechanism. Combined with the gating mechanism to obtain the gated context representation
[0166]
[0167]
[0168] in, is the learnable parameter matrix.
[0169] Step B52: For Figure A 1 Any node on Figure A 2 The corresponding node in is a positive sample, Figure A 2 The remaining nodes in Graph A 1 The rest of the nodes in A are negative samples. 2 For A 1 The same calculation is also used; the loss of two graph samples is calculated using cosine similarity The training target of the positive pair is e pv , the training objective of the negative pairs is The training objective of the negative example pair in the other figure is
[0170]
[0171]
[0172]
[0173]
[0174] in, A 1 Medium The set of other nodes except A 2 Medium The set of other nodes except , τ is the temperature coefficient, and cos() is the cosine similarity calculation.
[0175] Since both positive and negative pairs are based on two views, the positive pair refers to Figure A. 1 Node i in graph A 2 The node corresponding to node i in the graph, so the positive pairs here refer to all positive pairs in the two views, and the training objectives are the same; the types of negative pairs are in-graph and out-of-graph, so there are 1 and 2.
[0176] Step B53: Maximize the overall target loss L for the dual-image positive example pair gra The task loss for this module is:
[0177]
[0178] Step B6: The context representation E obtained in step 5 G Contains candidate answer nodes Combine it with the problem node representation f obtained in step B3 q Generate attention weight sparse matrix using relation filtering method It is used to screen the current candidate answer node. Step B6 specifically includes the following steps:
[0179] Step B61: Represent the context-encoded question as f q and the updated candidate answer node Use attention mechanism to generate attention matrix
[0180]
[0181] Step B62: Sort the attention matrix generated in step B61 in descending order of dimension to generate a matrix Then the most closely connected N in the matrix relation Relationships are retained to generate a more accurate attention weight sparse matrix
[0182]
[0183]
[0184] Among them, sort() is a descending sort function, f Pruning () is the pruning function.
[0185] Step B63: Combine the attention weight sparse matrix generated in step B62 with the candidate answer node Multiply to get the filtered candidate answer node
[0186]
[0187] Step B7: All nodes of different types obtained in steps B4 and B6 are input into the multi-layer perceptron for subtask prediction, obtaining prediction results for paragraphs, supporting facts, entity words, and answer types. The cross-entropy function is used to calculate the prediction losses for each type. The corresponding type of answer is then returned based on the answer type prediction results. Then, based on the target loss function, the gradients of each parameter in the deep learning network model are calculated using the backpropagation method, and the parameters are updated using the stochastic gradient descent method. Step B7 specifically includes the following steps:
[0188] Step B71: For paragraph nodes and sentence nodes in the graph, use a binary classification multi-layer perceptron to perform paragraph prediction and sentence prediction; for entity word nodes, use a multi-classification multi-layer perceptron to perform entity word prediction:
[0189]
[0190]
[0191]
[0192] in, represents the probability that the paragraph contains supporting facts, represents the probability that the sentence is selected as supporting fact, Indicates the probability that the correct answer exists in the entity node.
[0193] Step B72: Use MLP to predict the answer type based on the hidden state of the gated attention layer:
[0194] ptype =MLP7(E G [0])
[0195] Among them, p type is the probability of the answer type.
[0196] Step B73: For yes / no answers, directly return the answer; for entity answers, return the entity word prediction result; for span answers, use the hidden state of the above gated attention layer to calculate the span prediction:
[0197] p start =MLP8(E G )
[0198] p end =MLP9(E G )
[0199] Among them, p start 、p end Predict the probabilities for the start and end of the span.
[0200] Step B74: Use cross entropy as the loss function to calculate the loss value, update the learning rate through the gradient optimization algorithm Adam, and use back propagation to iteratively update the model parameters to minimize the loss function to train the model; the total model loss is the weighted sum of the losses of the above predictions:
[0201] L all =L start +L end +μ1L para +μ2(L sent +μ gra L gra )+μ3L ent +μ4L type
[0202] Among them, μ1, μ2, μ3, μ4, μ gra is a hyperparameter, L start , L end is the loss of span prediction, L para , L sent , L ent , L type They are the losses for paragraph prediction, sentence prediction, entity word prediction, and answer type prediction respectively.
[0203] Step B8: When the loss value generated by the deep learning network model is less than the set threshold or reaches the maximum number of iterations, the training of the deep learning network model D is terminated.
[0204] like Figure 3As shown, this embodiment also provides a multi-hop reading comprehension system for implementing the above method, including a training set construction module, a model training module and a multi-hop reading comprehension module.
[0205] The training set building module is used to collect conversation context and answer data to build a conversation training set.
[0206] The model training module is used to train a deep learning network model D based on dual-view contrast learning and graph pruning.
[0207] The multi-hop reading comprehension module will be used in the multi-hop reading comprehension process to input questions and articles into the trained deep network model to output the current predicted answer.
[0208] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can 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 can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0209] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0210] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0211] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0212] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any other manner. Any person skilled in the art may utilize the above-disclosed technical content to modify or modify the present invention into equivalent embodiments. However, any simple modifications, equivalent variations, and modifications to the above embodiments that do not depart from the technical content of the present invention and are based on the technical essence of the present invention remain within the scope of protection of the present invention.
Claims
1. A multi-hop reading comprehension method based on dual-view contrast learning and graph pruning, characterized by: The following steps are involved: Step A: Collect questions, article context, answers, and supporting factual data to construct a multi-hop reading comprehension training set; Step B: Use the training set to train a deep learning network model D based on dual-view contrastive learning and graph pruning for multi-hop reading comprehension; Step C: Input the question and article data into the deep learning network model D, and output the corresponding answer to the current question; The step B specifically comprises the following steps: Step B1: Use the pre-trained model Roberta to calculate the probability that each paragraph of each sample in the training set contains the golden supporting fact. At the same time, perform text matching on the relationship between the title and paragraph of each sample and the question to obtain N candidate paragraphs p candi ={p1,p2,...,p N }; Step B2: The candidate paragraph p obtained in step B1 candi Together with questions, sentences in paragraphs, entity words in paragraphs, and hyperlinks, they are used as nodes to construct a hierarchical graph G, and the adjacency matrix A of the hierarchical graph is constructed through the edge relationships of each node in G. adj ; Step B3: Use the pre-trained model Roberta to obtain the initial representation of all graph nodes in the hierarchical graph G obtained in step B2, and obtain the node representations of three types: paragraph, sentence, and entity. And the problem node representation f q , in order to obtain the overall node representation of the hierarchical graph Step B4: Add the adjacency matrix A of the hierarchical graph obtained in steps B2 and B3 adj The node representation F is used to damage the hierarchical graph twice by randomly deleting edge relationships and randomly masking node features. The two damaged hierarchical graphs are dual views, thus obtaining the adjacency matrix A of the two views. 1 ,A 2 and node representation F 1 ,F 2 ; Then the two views are input into the graph attention network respectively to obtain the updated node representation Step B5: Use the gated attention mechanism to calculate the initial context embedding E and the updated graph node representation Get the correlation coefficient and context representation E G ; At the same time, the adjacency matrix A of the two damaged views 1 ,A 2 and the feature matrix F 1 ,F 2 Each pair of samples is used as a positive and negative sample, and the cosine similarity is used to calculate the similarity of each pair of samples to obtain the comparative learning loss of the two graphs. Maximize the overall target loss L for the dual-view positive example pair gra ; Step B6: The context representation E obtained in step 5 G Contains candidate answer nodes where n e represents the number of entity word nodes limited in the hierarchical graph, d represents the dimension of the representation vector; it is combined with the problem node representation f obtained in step B3 q Generate attention weight sparse matrix using relation filtering method Use it to filter the current candidate answer node; Step B7: All nodes of different types obtained in steps B4 and B6 are fed into the multilayer perceptron for subtask prediction. The prediction results for paragraphs, supporting facts, entity words, and answer types are obtained. The cross-entropy function is used to calculate the prediction losses for each type. The corresponding type of answer is then returned based on the answer type prediction results. Based on the target loss function, the gradients of the parameters in the deep learning network model are calculated using the backpropagation method, and the parameters are updated using the stochastic gradient descent method. Step B8: When the loss value generated by the deep learning network model is less than the set threshold or reaches the maximum number of iterations, the training of the deep learning network model D is terminated; The step B5 specifically includes the following steps: Step B51: Let E = {Q, P} be the initial embedding representation of the context encoding layer after Roberta encoding, and calculate the correlation coefficient between the context embedding and the updated graph node using the attention mechanism. Combined with the gating mechanism to obtain the gated context representation in, is the learnable parameter matrix; Step B52: For Figure A 1 Any node on Figure A 2 The corresponding node in is a positive sample, Figure A 2 The remaining nodes in Graph A 1 The rest of the nodes in A are negative samples. 2 For A 1 The same calculation is also used; the loss of two graph samples is calculated using cosine similarity The training target of the positive pair is e pv , the training objective of the negative pairs is The training objective of the negative example pair in the other figure is in, A 1 Medium The set of nodes other than A 2 Medium The set of other nodes except , τ is the temperature coefficient, cos() is the cosine similarity calculation; Step B53: Maximize the overall target loss L for the dual-image positive example pair gra The task loss for this module is: The step B6 specifically includes the following steps: Step B61: Represent the problem node after context encoding as f q and the updated candidate answer node Use attention mechanism to generate attention matrix Step B62: Sort the attention matrix generated in step B61 in descending order of dimension to generate a matrix Then the most closely connected N in the matrix relation Relationships are retained to generate a more accurate attention weight sparse matrix Among them, sort() is a descending sort function, f Pruning () is the pruning function; Step B63: Combine the attention weight sparse matrix generated in step B62 with the candidate answer node Multiply to get the filtered candidate answer node 2. The multi-hop reading comprehension method based on dual-view contrast learning and graph pruning according to claim 1 is characterized in that: The step B1 specifically includes the following steps: Step B11: Traverse the training set and for each sample in the training set, use the Roberta model as the encoder to calculate the probability P of each paragraph in the sample containing the gold supporting fact ranking , use P ranking Sort the paragraphs, P ranking Expressed as: P ranking Roberta ranking (P) Where, P=(t i ,p i ) is the set of paragraphs in the sample, t i For the title of the paragraph, p i For paragraph text; The phrase span in the question (q start ,q end ) and the phrase span in the paragraph title If there are multiple paragraphs that match the paragraph title and question, select P ranking The first two paragraphs; if the title does not match the paragraph, the entity word in the question Match entity words in paragraphs If the entity word matching also fails, then take P ranking The highest paragraph, the selected paragraph P sel Expressed as: Among them, p sel Indicates the number of paragraphs whose titles match the questions successfully. Indicates the P selected in this case ranking The first two paragraphs; e sel Indicates whether the entity word in the question matches the paragraph successfully, e sel >0 indicates a successful match; Indicates the paragraph in which the question in this case matches the paragraph entity word; Step B12: The result of step B11 P sel The second-hop paragraph is searched for by the hyperlink in the corresponding data set; the first-hop selected paragraph and the question construct a bidirectional edge (q, p i ), if the second hop paragraph exists, a bidirectional edge (p i ,p j ), p i is the paragraph selected in the first jump, p j is the paragraph selected in the second jump; get n candidate paragraphs p candi ={p1,p2,...,p n }, use p ranking Select the top N paragraphs and get N candidate paragraphs p candi ={p1,p2,...,p N }.
3. The multi-hop reading comprehension method based on dual-view contrast learning and graph pruning according to claim 2 is characterized in that: The step B2 specifically includes the following steps: Step B21: For each sample in the training set, construct a hierarchical graph G with the paragraphs, sentences in each paragraph, entity words in each sentence, and the question matched in step B1. Define four types of nodes and seven types of edge relationships in the hierarchical graph: G={V,E} Among them, V is the question node q and the matched paragraph node p candi ={p1,p2,..,p N }、Sentence nodes in each paragraph Entity word nodes in each sentence The set of N,n s They represent the number of paragraph and sentence nodes in the hierarchical graph respectively; E is a set of seven edge relationships; Step B22: Construct the adjacency matrix A using the edge relationships of each node in the hierarchical graph G adj : Among them, A ij Non-zero means that the relationship between the two nodes belongs to a type in set E, and zero means that there is no relationship in set E between the two nodes.
4. The multi-hop reading comprehension method based on dual-view contrast learning and graph pruning according to claim 3 is characterized in that: The step B3 specifically includes the following steps: Step B31: Merge the selected paragraphs corresponding to the question in each training sample, concatenate them with the question, and then input Roberta to obtain the initial representation; obtain the question representation through the mutual attention layer and paragraph context representation Where m and n are the number of questions and paragraphs respectively; Step B32: Process the question and context representation separately. In the context representation, different types of nodes are calculated in the form of spans. The Bi-LSTM network is used to extract the node representations of paragraphs, sentences, and entities. in, Indicates the start and end positions of a paragraph node. The representation of a sentence node is similar to that of an entity node. [;] represents the concatenation of two vectors. The left and right sides represent the forward and backward calculations of the Bi-LSTM, respectively. Step B33: Pass the problem node through the maximum pooling layer to obtain the node representation f q : f q =maxpooling(Q)。 5. The multi-hop reading comprehension method based on dual-view contrast learning and graph pruning according to claim 4 is characterized in that: The step B4 specifically includes the following steps: Step B41: For a hierarchical graph G = (V, E), V is the set of nodes in the graph, and E is the set of edge relationships in the graph; the adjacency matrix of the graph is The adjacency matrix A adj Convert to a sparse matrix A coo , randomly construct a masking matrix according to the number of nodes As a masking matrix, when A adj When there is an edge relationship in , the masking matrix is assigned a value, which is calculated according to the Bernoulli distribution: in, is the Bernoulli distribution, p v is the customized masking probability; Step B42: Perform Hadamard product on the masking matrix and the original adjacency matrix to obtain the damaged adjacency matrix. Among them, (°) is the Hadamard product, which generates two adjacency matrices: Step B43: Sample a random vector f mask As a d-dimensional masking vector, the values in the vector are extracted using Bernoulli distribution: Among them, p f is the customized masking probability; Step B44: Node features Expand to And do Hadamard product with the masking vector to generate the damaged node feature in,[·] T For the transposition operation, the original node features are masked and damaged twice to generate two feature matrices: Step B45: Assume that the set of adjacent nodes in the graph is Calculate the correlation coefficient e between node i and neighbor nodes of the two graphs generated in step B42 and step B44 ij , and then normalized to get the attention coefficient α ij : Among them, h i is the representation of the currently calculated node i, h j is the neighbor node j of node i, is the shared parameter matrix; Step B46: The attention coefficient α of each damaged node feature matrix ij With neighboring nodes Perform weighted calculation to get updated node representation For the updated node features, the calculation process is as follows: in, is the shared parameter matrix, h′ i is the updated node representation of node i.
6. The multi-hop reading comprehension method based on dual-view contrast learning and graph pruning according to claim 5, characterized in that: The step B7 specifically includes the following steps: Step B71: For paragraph nodes and sentence nodes in the graph, use a binary classification multi-layer perceptron to perform paragraph prediction and sentence prediction; for entity word nodes, use a multi-classification multi-layer perceptron to perform entity word prediction: in, represents the probability that the paragraph contains supporting facts, represents the probability that the sentence is selected as supporting fact, Indicates the probability that the correct answer exists in the entity node; Step B72: Use MLP to predict the answer type based on the hidden state of the gated attention layer: p type =MLP7(E G [0]) Among them, p type is the probability of answer type; Step B73: For yes / no answers, directly return the answer; for entity answers, return the entity word prediction result; for span answers, use the hidden state of the above gated attention layer to calculate the span prediction: p start =MLP8(E G ) p end =MLP9(E G ) Among them, p start 、p end Predict probabilities for span start and end; Step B74: Use cross entropy as the loss function to calculate the loss value, update the learning rate through the gradient optimization algorithm Adam, and use back propagation to iteratively update the model parameters to minimize the loss function to train the model; the total model loss is the weighted sum of the losses of the above predictions: L all =L start +L end +μ1L para +μ2(L sent +m gra L gra )+μ3L ent +μ4L type Among them, μ1, μ2, μ3, μ4, μ gra is a hyperparameter, L start ,L end is the loss of span prediction, L para ,L sent ,L ent ,L type They are the losses for paragraph prediction, sentence prediction, entity word prediction, and answer type prediction respectively.
7. A multi-jump reading comprehension system using the method according to any one of claims 1 to 6, characterized in that: include: Build a training set module to collect conversation context and answer data and build a conversation training set; Model training module, used to train the deep learning network model D based on dual-view contrast learning and graph pruning; as well as The multi-hop reading comprehension module will be used in the multi-hop reading comprehension process to input questions and articles into the trained deep network model and output the current predicted answer.