Text matching method and device, equipment and storage medium
By constructing a word set to generate a relationship graph and updating the subgraph features, and combining this with the training of a relationship recognition model, the problem of low text matching accuracy in existing technologies is solved, achieving higher text matching accuracy.
Patent Information
- Application Number
- CN202110393267.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-13
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2041-04-13
AI Technical Summary
Existing technologies cannot fully represent the semantic information of text when constructing word relationship graphs, resulting in low text matching accuracy.
By constructing a word set to generate a relationship graph, and using a feature extraction layer to fuse node features and update subgraph features, combined with relationship recognition model training, the accuracy of text matching is improved.
It improves the accuracy of text matching, can more comprehensively represent the semantic information of the text, and improves the accuracy of the matching results.
Smart Images

Figure CN115204138B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a text matching method and device, equipment and storage medium. BACKGROUND
[0002] The task of text matching is widely applied in the field of natural language processing, for example, the text matching is applied to information retrieval, when a user proposes a question, an answer matched with the question is provided for the user. For another example, the text matching is applied to information recommendation, thereby automatically recommending other texts matched with the text interested by the user to the user.
[0003] When performing text matching, the text can be represented by a relationship graph between words in the text, and then the text matching is performed based on the relationship graph. In the related technology, the relationship graph is generally constructed based on the relationship between each two words in the text. However, in the case that the text includes at least three words, the relationship between each two words cannot completely represent the semantic information of the text, so that part of the semantic information of the text is lost, resulting in low accuracy of the text matching based on the relationship graph. SUMMARY
[0004] Embodiments of the present application provide a text matching method, device, equipment and storage medium, which can improve the accuracy of text matching. The technical solution is as follows:
[0005] In one aspect, a text matching method is provided, the method comprising:
[0006] obtaining a first text;
[0007] for each word in the first text, selecting each associated word of the word from the first text, and constructing a word set comprising the word and each selected associated word;
[0008] generating a first relationship graph based on at least one constructed word set, the first relationship graph comprising at least one relationship subgraph, each relationship subgraph corresponding to a word set, each node in each relationship subgraph being used to represent a word in the corresponding word set, and each relationship subgraph being used to represent an associated relationship between each word in the corresponding word set;
[0009] performing text matching based on the first relationship graph.
[0010] In one possible implementation, after the next feature extraction layer is called to fuse the second node features of the nodes in each relationship subgraph in the first relationship graph to obtain the second subgraph features of each relationship subgraph, the method further comprises:
[0011] for each of the second subgraph features of the first relation graph, calling the next feature extraction layer to determine at least one target subgraph feature similar to the second subgraph feature;
[0012] updating the second subgraph feature based on the at least one target subgraph feature to obtain an updated second subgraph feature;
[0013] wherein the target subgraph feature is a second subgraph feature of a relation subgraph in the second relation graph.
[0014] In a possible implementation, the updating the second subgraph feature based on the at least one target subgraph feature to obtain an updated second subgraph feature comprises:
[0015] calling the next feature extraction layer to select a reference number of target subgraph features from the at least one target subgraph feature based on similarity between the second subgraph feature and each of the at least one target subgraph feature, the similarity between the selected target subgraph features and the second subgraph feature being greater than the similarity between the remaining target subgraph features in the at least one target subgraph feature and the second subgraph feature;
[0016] fusing the selected target subgraph features based on similarity between the selected target subgraph features and the first subgraph feature as a weight to obtain a fusion feature, and determining a difference feature between the second subgraph feature and the fusion feature as the updated second subgraph feature.
[0017] In a possible implementation, the training process of the relation recognition model comprises:
[0018] obtaining sample data, the sample data comprising a first sample relation graph, a second sample relation graph, and a sample relation label, the sample relation label being used to represent a relation between the first sample relation graph and the second sample relation graph, the relation being matching or not matching;
[0019] calling the relation recognition model to determine a predicted relation label between the first sample relation graph and the second sample relation graph, the predicted relation label being used to represent a predicted relation between the first sample relation graph and the second sample relation graph;
[0020] training the relation recognition model based on the sample relation label and the predicted relation label.
[0021] In a possible implementation, the training the relation recognition model based on the sample relation label and the predicted relation label comprises:
[0022] determine a loss value of the relation identification model based on the sample relation label and the predicted relation label;
[0023] train the relation identification model based on the loss value, the loss value being used to represent a similarity between the sample relation label and the predicted relation label.
[0024] In a possible implementation, the relation identification model comprises a feature extraction sub-model and a classification sub-model; and the determining, by the relation identification model, the predicted relation label between the first sample relation graph and the second sample relation graph comprises:
[0025] obtaining, by the feature extraction sub-model, a node feature of each node in the first sample relation graph and a node feature of each node in the second sample relation graph, the node feature of the node being a feature of a word represented by the node;
[0026] obtaining, by the classification sub-model, a first sample relation graph feature based on the node feature of each node in the first sample relation graph and a second sample relation graph feature based on the node feature of each node in the second sample relation graph;
[0027] determining, based on the first sample relation graph feature and the second sample relation graph feature, the predicted relation label between the first sample relation graph and the second sample relation graph.
[0028] In a possible implementation, the obtaining, by the classification sub-model, the first sample relation graph feature based on the node feature of each node in the first sample relation graph and the second sample relation graph feature based on the node feature of each node in the second sample relation graph comprises:
[0029] obtaining, by the classification sub-model, an average value of the node features of the plurality of nodes in the first sample relation graph, determining the average value as the first sample relation graph feature, obtaining an average value of the node features of the plurality of nodes in the second sample relation graph, and determining the average value as the second sample relation graph feature.
[0030] In a possible implementation, the feature extraction sub-model comprises a plurality of feature extraction layers; and the obtaining, by the feature extraction sub-model, the node feature of each node in the first sample relation graph comprises:
[0031] obtaining, by a first feature extraction layer, a first node feature of each node in the first sample relation graph;
[0032] calling the first feature extraction layer, fusing the first node features of the nodes in each of the relation subgraphs in the first sample relation graph respectively to obtain first subgraph features of the each of the relation subgraphs, fusing the first subgraph features of the relation subgraphs to which each of the nodes in the first sample relation graph belongs respectively to obtain second node features of the each of the nodes;
[0033] calling a next feature extraction layer, fusing the second node features of the nodes in each of the relation subgraphs in the first sample relation graph respectively to obtain second subgraph features of the each of the relation subgraphs, fusing the second subgraph features of the relation subgraphs to which each of the nodes in the first sample relation graph belongs respectively to obtain third node features of the each of the nodes, until the node features of the each of the nodes output by the last feature extraction layer are obtained, and determining the node features of the each of the nodes output by the last feature extraction layer as the node features of each of the nodes in the first sample relation graph.
[0034] In a possible implementation, the calling the first feature extraction layer, fusing the first node features of the nodes in each of the relation subgraphs in the first sample relation graph respectively to obtain first subgraph features of the each of the relation subgraphs, fusing the first subgraph features of the relation subgraphs to which each of the nodes in the first sample relation graph belongs respectively to obtain second node features of the each of the nodes, includes:
[0035] obtaining first sample relation parameters of the first sample relation graph, the first sample relation parameters representing relations of each of the nodes in the first sample relation graph to each of the relation subgraphs, the relation being that the node belongs to the relation subgraph or the node does not belong to the relation subgraph;
[0036] for each of the relation subgraphs in the first sample relation graph, calling the first feature extraction layer, determining the nodes in the relation subgraph based on the first sample relation parameters, fusing the first node features of the nodes in the relation subgraph to obtain first subgraph features of the relation subgraph;
[0037] for each of the nodes in the first sample relation graph, calling the first feature extraction layer, determining the relation subgraph to which the node belongs based on the first sample relation parameters, fusing the first subgraph features of the relation subgraph to which the node belongs to obtain second node features of the node.
[0038] In a possible implementation, after the fusing the first subgraph features of the relation subgraph to which the node belongs to obtain second node features of the node, the method includes:
[0039] determine, by invoking the first feature extraction layer, a second sample relation parameter based on the first subgraph feature and the second node feature, the second sample relation parameter representing a similarity between the second node feature of each node in the first sample relation graph and the first subgraph feature of each relation subgraph;
[0040] respectively fuse the second node features of the nodes in each relation subgraph in the first sample relation graph to obtain a second subgraph feature of the each relation subgraph, and respectively fuse the second subgraph features of the relation subgraphs to which each node in the first sample relation graph belongs to obtain a third node feature of the each node, including:
[0041] For each relation subgraph in the first sample relation graph, invoke the next feature extraction layer to determine, based on the second sample relation parameter, a similarity between the second node features of the nodes in the relation subgraph and the first subgraph feature of the relation subgraph, fuse the second node features of the nodes in the relation subgraph by taking the similarities corresponding to the nodes in the relation subgraph as weights to obtain a second subgraph feature of the relation subgraph;
[0042] For each node in the first sample relation graph, invoke the next feature extraction layer to determine, based on the second sample relation parameter, a similarity between the first subgraph feature of the relation subgraph to which the node belongs and the second node feature of the node, fuse the second subgraph features of the relation subgraphs to which the node belongs by taking the similarities corresponding to the relation subgraphs to which the node belongs as weights to obtain a third node feature of the node.
[0043] In a possible implementation, the determining, by invoking the first feature extraction layer, a second sample relation parameter based on the first subgraph feature and the second node feature includes:
[0044] obtain a plurality of cosine similarities between the second node features of the nodes in the first sample relation graph and the first subgraph features of the relation subgraphs;
[0045] adjust, as a second reference similarity, a cosine similarity that is less than a first reference similarity in the plurality of cosine similarities, the second reference similarity representing a similarity between dissimilar second node features and first subgraph features;
[0046] generate the second sample relation parameter based on the plurality of adjusted cosine similarities.
[0047] In a possible implementation, after the similarity corresponding to the relation subgraph to which the node belongs is taken as a weight to fuse the second subgraph feature of the relation subgraph to which the node belongs, the third node feature of the node is obtained, the method further includes:
[0048] The next feature extraction layer is called to determine a third sample relation parameter based on the second subgraph feature and the third node feature, the third sample relation parameter representing a similarity between the third node feature of each node in the first sample relation graph and the second subgraph feature of each relation subgraph.
[0049] In a possible implementation, the training of the relation identification model based on the sample relation label and the predicted relation label includes:
[0050] The sample relation parameter representing a similarity between the node feature of each node in the first sample relation graph and the subgraph feature of each relation subgraph is obtained;
[0051] A first loss value is determined based on the sample relation parameter, the first loss value being used to represent a discrete degree of the similarity between the node features of multiple pairs of adjacent nodes belonging to the same relation subgraph;
[0052] A second loss value of the relation identification model is determined based on the sample relation label and the predicted relation label, the second loss value being used to represent a similarity between the sample relation label and the predicted relation label;
[0053] The relation identification model is trained based on a total loss value of the first loss value and the second loss value.
[0054] In a possible implementation, after the first node feature of the node in each relation subgraph in the first sample relation graph is fused to obtain the first subgraph feature of each relation subgraph by calling the first feature extraction layer, the method further includes:
[0055] For the first subgraph feature of each relation subgraph in the first sample relation graph, the first feature extraction layer is called to determine at least one target subgraph feature similar to the first subgraph feature;
[0056] The first subgraph feature is updated based on the at least one target subgraph feature to obtain an updated first subgraph feature;
[0057] The target subgraph feature is the first subgraph feature of the relation subgraph in the second sample relation graph.
[0058] In a possible implementation, the updating, based on the at least one target subgraph feature, of the first subgraph feature to obtain an updated first subgraph feature includes:
[0059] The first feature extraction layer is invoked, and reference quantities of target subgraph features are selected from the at least one target subgraph feature based on similarity between the first subgraph feature and each target subgraph feature in the at least one target subgraph feature, the selected target subgraph features having similarity greater than that between the first subgraph feature and remaining target subgraph features in the at least one target subgraph feature;
[0060] The selected target subgraph features are fused by taking similarity between the selected target subgraph features and the first subgraph feature as a weight to obtain a fusion feature, and a difference feature between the first subgraph feature and the fusion feature is determined as the updated first subgraph feature.
[0061] In a possible implementation, after the invoking of the next feature extraction layer and the fusing of the second node features of nodes in each relationship subgraph in the first sample relationship graph to obtain a second subgraph feature of each relationship subgraph, the method further includes:
[0062] For the second subgraph feature of each relationship subgraph in the first sample relationship graph, the next feature extraction layer is invoked to determine at least one target subgraph feature similar to the second subgraph feature;
[0063] The second subgraph feature is updated based on the at least one target subgraph feature to obtain an updated second subgraph feature;
[0064] The target subgraph feature is a second subgraph feature of a relationship subgraph in the second sample relationship graph.
[0065] In a possible implementation, the updating, based on the at least one target subgraph feature, of the second subgraph feature to obtain an updated second subgraph feature includes:
[0066] The next feature extraction layer is invoked, and reference quantities of target subgraph features are selected from the at least one target subgraph feature based on similarity between the second subgraph feature and each target subgraph feature in the at least one target subgraph feature, the selected target subgraph features having similarity greater than that between the second subgraph feature and remaining target subgraph features in the at least one target subgraph feature;
[0067] The similarity between the selected target subgraph feature and the first subgraph feature is taken as a weight, the selected target subgraph feature is fused to obtain a fusion feature, and a difference feature between the second subgraph feature and the fusion feature is determined as an updated second subgraph feature.
[0068] In another aspect, a text matching apparatus is provided, the apparatus comprising:
[0069] a text obtaining module configured to obtain a first text;
[0070] a set forming module configured to, for each word in the first text, select each associated word of the word from the first text, and form a word set comprising the word and each selected associated word;
[0071] a relation graph generating module configured to generate a first relation graph based on the formed at least one word set, the first relation graph comprising at least one relation subgraph, each relation subgraph corresponding to a word set, each node in the each relation subgraph being configured to represent a word in the corresponding word set, and the each relation subgraph being configured to represent an association relationship between each word in the corresponding word set;
[0072] a text matching module configured to perform text matching based on the first relation graph.
[0073] In a possible implementation, the set forming module is configured to determine a similarity between a first word vector of a first word and a second word vector of each second word, the first word being any word in the first text, and the second word being any word in the first text other than the first word; select a second word corresponding to each second word vector having a similarity less than a reference threshold with the first word vector; and form a word set comprising the first word and each selected second word.
[0074] In a possible implementation, the text matching module comprises:
[0075] a label determining sub-module configured to invoke a relation recognition model to determine a relation label between the first relation graph and a second relation graph corresponding to a second text, the relation label being configured to represent a relation between the first relation graph and the second relation graph, the relation being matching or not matching;
[0076] a text determining sub-module configured to, in response to the relation label representing that the first relation graph matches the second relation graph, determine the second text as a text matching the first text.
[0077] In a possible implementation, the relationship identification model comprises a feature extraction sub-model and a classification sub-model; the label determination sub-module comprises:
[0078] a node feature acquisition unit, configured to invoke the feature extraction sub-model, and acquire node features of each node in the first relationship graph and node features of each node in the second relationship graph, the node feature of the node being a feature of a word represented by the node;
[0079] a graph feature acquisition unit, configured to invoke the classification sub-model, acquire a first relationship graph feature based on the node features of each node in the first relationship graph, and acquire a second relationship graph feature based on the node features of each node in the second relationship graph;
[0080] a label determination unit, configured to determine the relationship label between the first relationship graph and the second relationship graph based on the first relationship graph feature and the second relationship graph feature.
[0081] In a possible implementation, the graph feature acquisition unit is configured to invoke the classification sub-model, acquire an average value of the node features of the plurality of nodes in the first relationship graph, determine the average value as the first relationship graph feature, acquire an average value of the node features of the plurality of nodes in the second relationship graph, and determine the average value as the second relationship graph feature.
[0082] In a possible implementation, the feature extraction sub-model comprises a plurality of feature extraction layers; and the node feature acquisition unit comprises:
[0083] a first feature acquisition sub-unit, configured to invoke a first feature extraction layer, and acquire first node features of each node in the first relationship graph;
[0084] a second feature acquisition sub-unit, configured to invoke the first feature extraction layer, respectively fuse the first node features of the nodes in each relationship sub-graph in the first relationship graph to obtain first sub-graph features of each relationship sub-graph, and respectively fuse the first sub-graph features of the relationship sub-graphs to which each node in the first relationship graph belongs to obtain second node features of each node;
[0085] The third feature acquisition subunit is configured to call a next feature extraction layer, fuse second node features of nodes in each relation subgraph in the first relation graph respectively to obtain second subgraph features of each relation subgraph, fuse second subgraph features of relation subgraphs to which each node in the first relation graph belongs respectively to obtain third node features of each node, and determine node features of each node output by the last feature extraction layer as node features of each node in the first relation graph.
[0086] In a possible implementation, the second feature acquisition subunit is configured to acquire first relation parameters of the first relation graph, the first relation parameters representing relations between each node in the first relation graph and each relation subgraph, the relation being that the node belongs to the relation subgraph or the node does not belong to the relation subgraph, call the first feature extraction layer for each relation subgraph in the first relation graph, determine nodes in the relation subgraph based on the first relation parameters, and fuse first node features of the nodes in the relation subgraph to obtain first subgraph features of the relation subgraph, and call the first feature extraction layer for each node in the first relation graph, determine a relation subgraph to which the node belongs based on the first relation parameters, and fuse first subgraph features of the relation subgraph to which the node belongs to obtain second node features of the node.
[0087] In a possible implementation, the second feature acquisition subunit is further configured to call the first feature extraction layer, determine second relation parameters based on the first subgraph features and the second node features, and the second relation parameters represent similarities between the second node features of each node in the first relation graph and the first subgraph features of each relation subgraph.
[0088] The third feature acquisition subunit is configured to, for each relation subgraph in the first relation graph, call the next feature extraction layer, determine similarities between second node features of nodes in the relation subgraph and the first subgraph features of the relation subgraph based on the second relation parameters, fuse the second node features of the nodes in the relation subgraph by taking the similarities corresponding to the nodes in the relation subgraph as weights to obtain second subgraph features of the relation subgraph, and for each node in the first relation graph, call the next feature extraction layer, determine similarities between the first subgraph features of a relation subgraph to which the node belongs and the second node features of the node based on the second relation parameters, fuse the second subgraph features of the relation subgraph to which the node belongs by taking the similarities corresponding to the relation subgraph to which the node belongs as weights to obtain third node features of the node.
[0089] In a possible implementation, the second feature obtaining subunit is configured to obtain cosine similarity between the second node feature of each node in the first relation graph and the first subgraph feature of each relation subgraph, to obtain a plurality of cosine similarities; adjust the cosine similarity smaller than a first reference similarity in the plurality of cosine similarities to a second reference similarity, the second reference similarity representing the similarity between the second node feature and the first subgraph feature that are not similar; and generate the second relation parameter based on the plurality of adjusted cosine similarities.
[0090] In a possible implementation, the third feature obtaining subunit is further configured to call the next feature extraction layer, determine a third relation parameter based on the second subgraph feature and the third node feature, the third relation parameter representing the similarity between the third node feature of each node in the first relation graph and the second subgraph feature of each relation subgraph.
[0091] In a possible implementation, the second feature obtaining subunit is further configured to, for the first subgraph feature of each relation subgraph in the first relation graph, call the first feature extraction layer, determine at least one target subgraph feature similar to the first subgraph feature; and update the first subgraph feature based on the at least one target subgraph feature, to obtain an updated first subgraph feature; wherein the target subgraph feature is the first subgraph feature of a relation subgraph in the second relation graph.
[0092] In a possible implementation, the second feature obtaining subunit is configured to call the first feature extraction layer, select a reference number of target subgraph features from the at least one target subgraph feature based on the similarity between the first subgraph feature and each target subgraph feature in the at least one target subgraph feature, the similarity between the selected target subgraph feature and the first subgraph feature being greater than the similarity between the remaining target subgraph features in the at least one target subgraph feature and the first subgraph feature; fuse the selected target subgraph features by taking the similarity between the selected target subgraph feature and the first subgraph feature as a weight, to obtain a fusion feature; and determine a difference feature between the first subgraph feature and the fusion feature as the updated first subgraph feature.
[0093] In a possible implementation, the third feature obtaining subunit is further configured to, for the second subgraph feature of each relation subgraph in the first relation graph, call the next feature extraction layer, determine at least one target subgraph feature similar to the second subgraph feature; and update the second subgraph feature based on the at least one target subgraph feature, to obtain an updated second subgraph feature; wherein the target subgraph feature is the second subgraph feature of a relation subgraph in the second relation graph.
[0094] In a possible implementation, the third feature acquisition subunit is configured to invoke the next feature extraction layer, select a reference number of target subgraph features from the at least one target subgraph feature based on similarity between the second subgraph feature and each of the at least one target subgraph feature, the similarity between the selected target subgraph feature and the second subgraph feature being greater than the similarity between the remaining target subgraph features in the at least one target subgraph feature and the second subgraph feature; fuse the selected target subgraph features by taking similarity between the selected target subgraph features and the first subgraph feature as a weight, to obtain a fused feature; and determine a difference feature between the second subgraph feature and the fused feature as an updated second subgraph feature.
[0095] In a possible implementation, the training process of the relationship identification model includes:
[0096] obtaining sample data, the sample data including a first sample relationship graph, a second sample relationship graph, and a sample relationship label, the sample relationship label being used to represent a relationship between the first sample relationship graph and the second sample relationship graph, the relationship being matching or not matching;
[0097] invoking the relationship identification model to determine a predicted relationship label between the first sample relationship graph and the second sample relationship graph, the predicted relationship label being used to represent a predicted relationship between the first sample relationship graph and the second sample relationship graph;
[0098] training the relationship identification model based on the sample relationship label and the predicted relationship label.
[0099] In a possible implementation, the training the relationship identification model based on the sample relationship label and the predicted relationship label includes:
[0100] determining a loss value of the relationship identification model based on the sample relationship label and the predicted relationship label;
[0101] training the relationship identification model based on the loss value, the loss value being used to represent similarity between the sample relationship label and the predicted relationship label.
[0102] In a possible implementation, the relationship identification model includes a feature extraction submodel and a classification submodel; and the invoking the relationship identification model to determine the predicted relationship label between the first sample relationship graph and the second sample relationship graph includes:
[0103] calling the feature extraction sub-model to obtain the node feature of each node in the first sample relation graph and the node feature of each node in the second sample relation graph, the node feature of the node being the feature of the word represented by the node;
[0104] calling the classification sub-model to obtain the first sample relation graph feature based on the node feature of each node in the first sample relation graph and to obtain the second sample relation graph feature based on the node feature of each node in the second sample relation graph;
[0105] determining the predicted relation label between the first sample relation graph and the second sample relation graph based on the first sample relation graph feature and the second sample relation graph feature.
[0106] In a possible implementation, the calling the classification sub-model to obtain the first sample relation graph feature based on the node feature of each node in the first sample relation graph and to obtain the second sample relation graph feature based on the node feature of each node in the second sample relation graph comprises:
[0107] calling the classification sub-model to obtain the average value of the node features of the plurality of nodes in the first sample relation graph, determining the average value as the first sample relation graph feature, obtaining the average value of the node features of the plurality of nodes in the second sample relation graph, and determining the average value as the second sample relation graph feature.
[0108] In a possible implementation, the feature extraction sub-model comprises a plurality of feature extraction layers; and the calling the feature extraction sub-model to obtain the node feature of each node in the first sample relation graph comprises:
[0109] calling a first feature extraction layer to obtain the first node feature of each node in the first sample relation graph;
[0110] calling the first feature extraction layer to respectively fuse the first node features of the nodes in each relation subgraph in the first sample relation graph to obtain the first subgraph feature of each relation subgraph, and to respectively fuse the first subgraph features of the relation subgraphs to which each node in the first sample relation graph belongs to obtain the second node feature of each node;
[0111] The next feature extraction layer is called to respectively fuse the second node features of the nodes in each relation subgraph in the first sample relation graph to obtain second subgraph features of the each relation subgraph, and respectively fuse the second subgraph features of the relation subgraphs to which each node in the first sample relation graph belongs to obtain third node features of the each node, until the node features of the each node output by the last feature extraction layer are obtained. The node features of the each node output by the last feature extraction layer are determined as the node features of the each node in the first sample relation graph.
[0112] In a possible implementation, the calling the first feature extraction layer, respectively fusing the first node features of the nodes in each relation subgraph in the first sample relation graph to obtain first subgraph features of the each relation subgraph, and respectively fusing the first subgraph features of the relation subgraphs to which each node in the first sample relation graph belongs to obtain second node features of the each node includes:
[0113] The first sample relation parameters of the first sample relation graph are obtained, and the first sample relation parameters represent relations of each node in the first sample relation graph to each relation subgraph, and the relation is that the node belongs to the relation subgraph or the node does not belong to the relation subgraph.
[0114] For each relation subgraph in the first sample relation graph, the first feature extraction layer is called to determine the nodes in the relation subgraph based on the first sample relation parameters, fuse the first node features of the nodes in the relation subgraph to obtain first subgraph features of the relation subgraph.
[0115] For each node in the first sample relation graph, the first feature extraction layer is called to determine the relation subgraph to which the node belongs based on the first sample relation parameters, and fuse the first subgraph features of the relation subgraph to which the node belongs to obtain second node features of the node.
[0116] In a possible implementation, after the fusing the first subgraph features of the relation subgraph to which the node belongs to obtain the second node features of the node, the apparatus includes:
[0117] The first feature extraction layer is called to determine second sample relation parameters based on the first subgraph features and the second node features, and the second sample relation parameters represent similarities between the second node features of each node in the first sample relation graph and the first subgraph features of each relation subgraph.
[0118] The next feature extraction layer is called to fuse the second node features of the nodes in each relation subgraph in the first sample relation graph respectively to obtain second subgraph features of each relation subgraph, and to fuse the second subgraph features of the relation subgraphs to which each node in the first sample relation graph belongs respectively to obtain third node features of each node, including:
[0119] For each relation subgraph in the first sample relation graph, the next feature extraction layer is called to determine, based on the second sample relation parameter, a similarity between the second node features of the nodes in the relation subgraph and the first subgraph feature of the relation subgraph, and fuse the second node features of the nodes in the relation subgraph as weights to obtain the second subgraph feature of the relation subgraph;
[0120] For each node in the first sample relation graph, the next feature extraction layer is called to determine, based on the second sample relation parameter, a similarity between the first subgraph feature of the relation subgraph to which the node belongs and the second node feature of the node, and fuse the second subgraph features of the relation subgraph to which the node belongs as weights to obtain the third node feature of the node.
[0121] In a possible implementation, the calling the first feature extraction layer includes determining, based on the first subgraph feature and the second node feature, a second sample relation parameter, including:
[0122] Obtaining a plurality of cosine similarities between the second node features of each node in the first sample relation graph and the first subgraph features of each relation subgraph;
[0123] Adjusting, as a second reference similarity, a cosine similarity smaller than a first reference similarity in the plurality of cosine similarities, the second reference similarity representing a similarity between dissimilar second node features and first subgraph features;
[0124] Generating the second sample relation parameter based on the adjusted plurality of cosine similarities.
[0125] In a possible implementation, after the calling the next feature extraction layer to fuse the second subgraph features of the relation subgraphs to which the node belongs as weights to obtain the third node features of the node, the apparatus further includes:
[0126] The next feature extraction layer is called to determine third sample relationship parameters based on the second subgraph features and the third node features, the third sample relationship parameters representing similarities between the third node features of each node in the first sample relationship graph and the second subgraph features of each relationship subgraph.
[0127] In a possible implementation, the training of the relationship identification model based on the sample relationship labels and the predicted relationship labels comprises:
[0128] The last feature extraction layer outputs sample relationship parameters, the sample relationship parameters representing similarities between node features of each node in the first sample relationship graph and subgraph features of each relationship subgraph;
[0129] A first loss value is determined based on the sample relationship parameters, the first loss value representing a discrete degree of similarities between node features of multiple pairs of adjacent nodes belonging to a same relationship subgraph;
[0130] A second loss value of the relationship identification model is determined based on the sample relationship labels and the predicted relationship labels, the second loss value representing a similarity between the sample relationship labels and the predicted relationship labels;
[0131] The relationship identification model is trained based on a total loss value of the first loss value and the second loss value.
[0132] In a possible implementation, after the first feature extraction layer is called to fuse first node features of nodes in each relationship subgraph in the first sample relationship graph to obtain first subgraph features of the each relationship subgraph, the apparatus further comprises:
[0133] For the first subgraph features of each relationship subgraph in the first sample relationship graph, the first feature extraction layer is called to determine at least one target subgraph feature similar to the first subgraph features;
[0134] The first subgraph features are updated based on the at least one target subgraph feature to obtain updated first subgraph features;
[0135] The target subgraph features are first subgraph features of relationship subgraphs in the second sample relationship graph.
[0136] In a possible implementation, the updating of the first subgraph features based on the at least one target subgraph feature to obtain updated first subgraph features comprises:
[0137] The first feature extraction layer is called to select a reference number of target subgraph features from the at least one target subgraph feature based on similarity between the first subgraph feature and each of the at least one target subgraph feature, and the selected target subgraph features have a similarity greater than that between the first subgraph feature and the remaining target subgraph features in the at least one target subgraph feature;
[0138] The similarity between the selected target subgraph features and the first subgraph feature is taken as a weight to fuse the selected target subgraph features to obtain fused features, and a difference feature between the first subgraph feature and the fused features is determined as an updated first subgraph feature.
[0139] In a possible implementation, after the second node feature of each node in each relational subgraph in the first sample relational graph is fused to obtain a second subgraph feature of each relational subgraph by calling the next feature extraction layer, the apparatus further includes:
[0140] For the second subgraph feature of each relational subgraph in the first sample relational graph, the next feature extraction layer is called to determine at least one target subgraph feature similar to the second subgraph feature;
[0141] The second subgraph feature is updated based on the at least one target subgraph feature to obtain an updated second subgraph feature;
[0142] The target subgraph feature is a second subgraph feature of a relational subgraph in the second sample relational graph.
[0143] In a possible implementation, the second subgraph feature is updated based on the at least one target subgraph feature to obtain an updated second subgraph feature, including:
[0144] The next feature extraction layer is called to select a reference number of target subgraph features from the at least one target subgraph feature based on similarity between the second subgraph feature and each of the at least one target subgraph feature, and the selected target subgraph features have a similarity greater than that between the second subgraph feature and the remaining target subgraph features in the at least one target subgraph feature;
[0145] The similarity between the selected target subgraph features and the first subgraph feature is taken as a weight to fuse the selected target subgraph features to obtain fused features, and a difference feature between the second subgraph feature and the fused features is determined as an updated second subgraph feature.
[0146] In another aspect, a computer device is provided, which includes a processor and a memory, and the memory has stored therein at least one computer program, which is loaded and executed by the processor to implement the operations performed in the text matching method in any of the possible implementation manners described above.
[0147] In another aspect, a computer readable storage medium is provided, which has stored therein at least one computer program, which is loaded and executed by a processor to implement the operations performed in the text matching method in any of the possible implementation manners described above.
[0148] In still another aspect, a computer program product or a computer program is provided, which includes a computer program stored in a computer readable storage medium. A processor of a computer device reads the computer program from the computer readable storage medium, and the processor executes the computer program, so that the computer device performs the operations performed in the text matching method in various optional implementation manners described above.
[0149] The technical scheme provided by the embodiments of the present application has at least the following beneficial effects:
[0150] In the embodiments of the present application, considering that the relationship between each two words in a text cannot completely represent the semantic information of the text, when representing the text by a relationship graph, for each word in the text, each associated word of the word is selected from the text, the word and the selected associated word form a word set, and a relationship graph is generated based on the formed at least one word set. Since the relationship graph represents the text in units of relationship subgraphs, and each relationship subgraph can represent the association relationship between each word in the word set corresponding to the relationship subgraph, rather than being limited to only the association relationship between two words, the relationship graph can completely represent the semantic information of the text, and text matching by using the relationship graph can improve the accuracy of text matching. BRIEF DESCRIPTION OF DRAWINGS
[0151] In order to more clearly illustrate the technical scheme in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced as follows. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor on the basis of these drawings.
[0152] Figure 1 is a schematic diagram of an implementation environment provided by the embodiments of the present application;
[0153] Figure 2is a schematic diagram of a question and answer interface provided by an embodiment of the present application;
[0154] Figure 3 is a flowchart of a text matching method provided by an embodiment of the present application;
[0155] Figure 4 is a flowchart of a text matching method provided by an embodiment of the present application;
[0156] Figure 5 is a schematic diagram of a text relationship graph provided by an embodiment of the present application;
[0157] Figure 6 is a process schematic diagram of extracting node features provided by an embodiment of the present application;
[0158] Figure 7 is a process schematic diagram of determining relationship labels provided by an embodiment of the present application;
[0159] Figure 8 is a schematic diagram of a relationship identification model training process provided by an embodiment of the present application;
[0160] Figure 9 is a block diagram of a text matching device provided by an embodiment of the present application;
[0161] Figure 10 is a block diagram of a text matching device provided by an embodiment of the present application;
[0162] Figure 11 is a schematic diagram of a terminal structure provided by an embodiment of the present application;
[0163] Figure 12 is a schematic diagram of a server structure provided by an embodiment of the present application. DETAILED DESCRIPTION
[0164] To make the purpose, technical solutions and advantages of the present application clearer, the following will further describe the embodiments of the present application in combination with the drawings.
[0165] The terms "first", "second", "third", "fourth" and the like used in the present application can be used herein to describe various concepts, but unless specifically stated, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another. For example, without departing from the scope of the present application, the first relationship graph can be referred to as a relationship graph, and similarly, the second relationship graph can be referred to as the first relationship graph.
[0166] As used herein, the terms “at least one”, “multiple”, “each”, “any”, include one, two, or more, multiple includes two or more, and each refers to each of the corresponding multiple, and any refers to any of the multiple. For example, multiple nodes include 3 nodes, and each refers to each of the 3 nodes, and any refers to any of the 3 nodes, which can be the first, the second, or the third.
[0167] Figure 1 is a schematic diagram of an implementation environment provided by an embodiment of the present application. Referring to Figure 1 , the implementation environment includes a terminal 101 and a server 102. The terminal 101 and the server 102 are connected through a wireless or wired network. Optionally, the terminal 101 is a smartphone, a tablet computer, a notebook computer, a desktop computer, a smart speaker, a smart watch, a vehicle-mounted terminal, a video camera, a camera, or other terminals. Optionally, the server 102 is a standalone physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and basic cloud computing services such as big data and artificial intelligence platforms.
[0168] Optionally, the terminal 101 is installed with a target application provided by the server 102, and the terminal 101 can realize functions such as data transmission and message interaction through the target application. Optionally, the target application is a target application in the operating system of the terminal 101, or a target application provided by a third party. The target application has a function related to a task matched with the text, for example, the target application has an information retrieval function, an information recommendation function, and a question answering function. Of course, the target application can also have other functions, which are not limited by the present application. Optionally, the target application is a content recommendation application, a search application, a question and answer service application, etc.
[0169] In an embodiment of the present application, the terminal 101 is configured to obtain a first text, and send the first text to the server 102. The server 102 is configured to represent the first text as a first relationship graph, perform text matching based on the first relationship graph, obtain other texts matched with the first text, and send the other texts to the terminal 101. It should be noted that the present application only takes an implementation environment including a terminal 101 and a server 102 as an example for description, and in other embodiments, the implementation environment only includes the terminal 101 or the server 102. The terminal 101 or the server 102 is configured to obtain a first text, represent the first text as a first relationship graph, and perform text matching based on the first relationship graph.
[0170] Optionally, the terminal 101 or the server 102 in the embodiments of the present application is a node in a blockchain system, each node in the blockchain system stores a blockchain, and the data stored in the blockchain on different nodes is kept synchronized. The data stored in the blockchain of each node includes: text, a relationship graph corresponding to the text, other text obtained by performing text matching on the text, a relationship identification model, and the like.
[0171] The text matching method in the present application can be applied to various question and answer scenarios, for example, medical insurance policy question and answer, vaccine information question and answer in the field of public health, and the like. Taking the vaccine information question and answer in the field of public health as an example, the user inputs a question “which is more important, nucleic acid detection or CT (Computed Tomography) detection?” in the terminal, the terminal sends the question to the server, the server performs text matching on the question and multiple standard questions in the knowledge base respectively, determines the standard question matched with the question, returns the answer corresponding to the standard question to the terminal, and then the terminal displays the answer. It should be noted that in the case where multiple standard questions matched with the question of the user are obtained, the server returns the answer corresponding to the standard question with the highest matching degree to the terminal, and returns other standard questions to the terminal, and the terminal displays the other standard questions in addition to the answer, so as to determine whether to further ask questions. Figure 2 A schematic diagram of a question and answer interface for a question and answer service. Referring to Figure 2 , the question input by the user is “which is more important, nucleic acid detection or CT detection?”, and the answer corresponding to the question is displayed below the question. In addition, three standard questions related to the question are also displayed below the question and answer interface, for example, “when should you wash your hands?” and “can you quickly detect the disease?”.
[0172] The text matching method in the present application can also be applied to the scene of information search, for example, after the user inputs a search word in the terminal, the terminal sends the search word to the server, the server performs text matching on the search word and the text in the knowledge base, obtains the text matched with the search word, sends the text matched with the search word to the terminal, and then the terminal displays the text.
[0173] The text matching method in the present application can also be applied to the scene of information recommendation, for example, after the user browses the text of interest through the terminal, the terminal sends the text of interest of the user to the server, the server performs text matching based on the text of interest of the user, obtains other text matched with the text of interest of the user, and sends the other text to the terminal, and then the terminal recommends the other text to the user.
[0174] Actually, the text matching method provided in the present application can be applied in any text matching scene, and the embodiments of the present application do not limit this.
[0175] Figure 3 is a flowchart of a text matching method provided by an embodiment of the present application. The embodiment takes a server as an example to illustrate. Referring to Figure 3 , the embodiment includes the following steps.
[0176] 301. The server acquires a first text.
[0177] The first text is any text, and the first text belongs to any language, for example, Chinese, English, etc. The first text is any content, for example, the first text describes vaccine information, health information, sports information, etc. The first text is a sentence or an article, wherein the article is composed of sentences.
[0178] 302. For each word in the first text, the server selects each associated word of the word from the first text, and the word and each selected associated word form a word set.
[0179] For each word in the first text, the server selects each associated word of the word from the first text means that the server selects all the associated words of the word from the other words in the first text except the word, that is, the server traverses each other word in the first text except the word to find all the associated words of the word. Each word set includes at least two words. For example, in the first text, a word A has only one associated word B, and the word set formed includes two words, i.e., the word A and the word B. For example, a word C has two associated words, i.e., a word D and a word E, and the word set formed includes three words, i.e., the word C, the word D, and the word E.
[0180] 303. The server generates a first relationship graph based on the at least one word set formed.
[0181] The first relationship graph includes at least one relationship subgraph, each relationship subgraph corresponds to a word set, each relationship subgraph includes multiple nodes, each node in each relationship subgraph is used to represent a word in the corresponding word set, and each relationship subgraph is used to represent that there is an association relationship between each word in the corresponding word set. For example, a relationship subgraph includes two nodes, and the two nodes represent a word A and a word B in a word set, and the relationship subgraph is used to represent that there is an association relationship between the word A and the word B. For another example, a relationship subgraph includes three nodes, and the three nodes represent a word C, a word D, and a word E in a word set, and the relationship subgraph is used to represent that there is an association relationship between the word C, the word D, and the word E.
[0182] 304、The server performs text matching based on the first relation graph.
[0183] The text matching refers to determining whether two texts match, that is, determining whether there is a semantic relationship or relevance between the two texts. The server performs text matching based on the first relation graph, that is, the server obtains other texts matching the first text based on the first relation graph.
[0184] In the embodiments of the present application, considering that the relationship between each two words in a text cannot completely represent the semantic information of the text, when the text is represented by a relation graph, for each word in the text, each associated word of the word is selected from the text, the word and the selected associated word form a word set, and the relation graph is generated based on the formed at least one word set. Since the relation graph represents the text in units of relation subgraphs, and each relation subgraph can represent the association relationship between each word in the word set corresponding to the relation subgraph, and is not limited to only the association relationship between two words, the relation graph can completely represent the semantic information of the text, and the text matching based on the relation graph can improve the accuracy of text matching.
[0185] Figure 4 is a flowchart of a text matching method provided by an embodiment of the present application. The embodiment describes the process of text matching by a relation recognition model. Referring to Figure 4 , the embodiment includes:
[0186] 401、The server obtains a first text.
[0187] Optionally, the implementation manner of the server obtaining the first text includes that the server obtains the first text from a terminal, or the server obtains the first text from a text database, where the text database is used to store texts.
[0188] 402、For each word in the first text, the server selects each associated word of the word from the first text, and the word and each selected associated word form a word set.
[0189] In a possible implementation, the step is implemented as follows: the server determines the similarity between the first word vector of the first word and the second word vector of each second word; the server selects the second word corresponding to each second word vector having a similarity less than a reference threshold with the first word vector; and the first word and each selected second word form a word set. The first word is any word in the first text, and the second word is any word in the first text except the first word. The second word corresponding to the second word vector having a similarity less than the reference threshold with the first word vector is the associated word of the first word. When selecting the associated word of the first word, the server traverses each second word in the first text, and selects all second words corresponding to the second word vector having a similarity less than the reference threshold with the first word vector, that is, all associated words of the first word in the first text are selected, and then form a word set with the first word. The reference threshold is set to any value as required, and the embodiments of the present application do not limit the reference threshold.
[0190] The word vector of a word is used to represent the semantics of the word. The greater the similarity between the word vectors of two words, the closer the semantics of the two words, and the more likely the two words are associated. In the embodiments of the present application, when determining the associated word of the first word, the similarity between the first word and the second word vector is determined, and the similarity can indicate the closeness of the semantics of the first word and the second word. Therefore, the associated word of the first word can be accurately determined based on the similarity.
[0191] Optionally, for each word in the first text, the server selects each associated word of the word from the first text in the following manner: the server displays a marking interface of the associated word, the marking interface including the first text, detects a marking operation of the user based on the marking interface, and determines all associated words of each word in the first text based on the marking operation of the user. The marking interface of the associated word is used for the user to mark all associated words of each word in the first text. Since the user can obtain the semantics of the first text and the association relationship between the words in the first text by reading the first text, the accuracy of the associated words of each word determined by using the marking interface of the associated word to obtain all associated words of each word marked by the user is high.
[0192] 403. The server generates a first relationship graph based on the at least one word set.
[0193] The first relationship graph includes at least one relationship subgraph, each relationship subgraph corresponding to a word set, each relationship subgraph including a plurality of nodes, each node in each relationship subgraph being used to represent a word in the corresponding word set, and each relationship subgraph being used to represent an association relationship between each word in the corresponding word set.
[0194] Optionally, the relationship subgraph is a relationship chain, and correspondingly, the first relationship graph includes at least one relationship chain, each relationship chain corresponds to a set of words, each relationship chain includes a plurality of nodes, each node in each relationship chain is used to represent a word in the corresponding set of words, and each relationship chain is used to represent that there is an association relationship between each word in the corresponding set of words.
[0195] Figure 5 The figure is a schematic diagram of the relationship graph of the text. Referring to Figure 5 The relationship graph includes a plurality of relationship subgraphs, which are relationship subgraph 501, relationship subgraph 502, and relationship subgraph 503. As can be seen from the relationship graph, each relationship subgraph includes a plurality of nodes, each node is used to represent a word in the set of words corresponding to the relationship subgraph, and one node can belong to multiple relationship subgraphs.
[0196] 404. The server calls the relationship identification model to determine the relationship label between the first relationship graph and the second relationship graph corresponding to the second text.
[0197] The function of the relationship identification model is to determine the relationship between the relationship graphs corresponding to two texts, and the relationship between the relationship graphs is matching or not matching. The relationship label is used to represent the relationship between the relationship graphs corresponding to two texts, and the relationship label between the first relationship graph and the second relationship graph is used to represent the relationship between the first relationship graph and the second relationship graph, which is matching or not matching. The second text is any text different from the first text. For example, in the case that the first text is a text of interest to the user, the second text is a candidate text in the database, and in the case that the text matching is performed on the first text and the second text and it is determined that the second text is the text matching the first text, the second text is recommended to the user as a text that the user may be interested in. The implementation manner of the server for obtaining the second text is the same as that for obtaining the first text, which will not be described herein again.
[0198] In a possible implementation manner, the relationship identification model includes a feature extraction sub-model and a classification sub-model. Correspondingly, the server calls the relationship identification model to determine the relationship label between the first relationship graph and the second relationship graph, including the following steps (1)-(3).
[0199] (1) The server calls the feature extraction sub-model to obtain the node features of each node in the first relationship graph and the node features of each node in the second relationship graph.
[0200] The node features of the node are the features of the word represented by the node. The feature extraction sub-model is used to extract the node features of the nodes in the relationship graph.
[0201] In a possible implementation, the feature extraction sub-model comprises a plurality of feature extraction layers, each of which is configured to extract a node feature of a node, and the node feature output by the last feature extraction layer is determined as the final node feature after feature extraction by the plurality of feature extraction layers. Correspondingly, the server invokes the feature extraction sub-model to obtain the node feature of each node in the first relation graph, including the following steps (A)-(C).
[0202] (A) The server invokes the first feature extraction layer to obtain the first node feature of each node in the first relation graph.
[0203] Optionally, for each node, the server obtains the word vector of the word represented by the node from the word vector database, and determines the word vector as the first node feature of the node. The word vector database is configured to store the word vector of each word.
[0204] (B) The server invokes the first feature extraction layer to fuse the first node features of the nodes in each relation subgraph in the first relation graph respectively, to obtain the first subgraph feature of each relation subgraph, and fuses the first subgraph features of the relation subgraphs to which each node belongs respectively, to obtain the second node feature of each node.
[0205] In a possible implementation, step (B) comprises the following three steps.
[0206] Firstly, the server obtains the first relation parameter of the first relation graph, and the first relation parameter represents the relationship between each node in the first relation graph and each relation subgraph, which is whether the node belongs to the relation subgraph or not.
[0207] The first relation graph directly reflects whether each node belongs to each relation subgraph, and therefore, the server can obtain the first relation parameter based on the first relation graph. Optionally, the first relation parameter is in the form of a matrix, and each element in the matrix represents the relationship between a node and a relation subgraph. For example, the first element in the matrix represents the relationship between the first node and the first relation subgraph, and the second element represents the relationship between the first node and the second relation subgraph. Optionally, the element is 0, indicating that the relationship between the node and the relation subgraph is that the node does not belong to the relation subgraph. The element is 1, indicating that the relationship between the node and the relation subgraph is that the node belongs to the relation subgraph.
[0208] Secondly, for each relation subgraph in the first relation graph, the server invokes the first feature extraction layer to determine the nodes in the relation subgraph based on the first relation parameter, and fuse the first node features of the nodes in the relation subgraph to obtain the first subgraph feature of the relation subgraph. Optionally, this method is implemented by the following formula (1).
[0209]
[0210] wherein X E represents the first subgraph feature of the relationship subgraph, σ represents an activation function, D E represents a diagonal matrix of the degree of the relationship subgraph, A represents the first relationship parameter, D V represents a diagonal matrix of the degree of the node, X V represents the first node feature of the node, W E is a learnable matrix, i.e., a model parameter, and b E is an offset, which is also a model parameter. The diagonal matrix of the degree of the relationship subgraph is a diagonal matrix converted from a vector of the degree of the relationship subgraph, which is used to represent the number of nodes in each relationship subgraph. For example, the first element in the vector of the degree of the relationship subgraph represents the number of nodes in the first relationship subgraph, and the second element represents the number of nodes in the second relationship subgraph. The diagonal matrix of the degree of the node is a diagonal matrix converted from a vector of the degree of the node, which is used to represent the number of relationship subgraphs to which each node belongs. For example, the first element in the vector of the degree of the node represents the number of relationship subgraphs to which the first node belongs, and the second element represents the number of relationship subgraphs to which the second node belongs.
[0211] Thirdly, for each node in the first relationship graph, the server calls the first feature extraction layer to determine the relationship subgraph to which the node belongs based on the first relationship parameter, and fuses the first subgraph feature of the relationship subgraph to which the node belongs to obtain the second node feature of the node. Optionally, the method is implemented through the following formula (2).
[0212]
[0213] wherein X V represents the node feature of the node, σ represents an activation function, D V represents a diagonal matrix of the degree of the node, A represents the first relationship parameter, D E represents a diagonal matrix of the degree of the relationship subgraph, X E represents the first subgraph feature of the relationship subgraph, W V is a learnable matrix, i.e., a model parameter, and b V is an offset, which is also a model parameter.
[0214] In the embodiments of the present application, when the feature extraction layer performs feature extraction, the node feature of the node is obtained by fusing the node features of the nodes in the relationship subgraph to obtain the subgraph feature of the relationship subgraph, and then fusing the subgraph features of the relationship subgraphs to which the node belongs. Through the two processes, the model can fully learn the semantic information of the text, and then obtain accurate node features.
[0215] In a possible implementation, after the server fuses the first node features of the nodes in each relation subgraph in the first relation graph respectively to obtain the first subgraph features of each relation subgraph by invoking the first feature extraction layer, the method further includes: for the first subgraph features of each relation subgraph in the first relation graph, the server invokes the first feature extraction layer to determine at least one target subgraph feature similar to the first subgraph feature; and the server updates the first subgraph feature based on the at least one target subgraph feature to obtain an updated first subgraph feature. The target subgraph feature is a first subgraph feature of a relation subgraph in the second relation graph. The implementation of obtaining the first subgraph features of the relation subgraphs in the second relation graph is the same as that of obtaining the first subgraph features of the relation subgraphs in the first relation graph, and will not be repeated here.
[0216] Optionally, for the first subgraph features of each relation subgraph in the first relation graph, the implementation that the server determines at least one target subgraph feature similar to the first subgraph feature by invoking the first feature extraction layer includes: for the first subgraph features of each relation subgraph in the first relation graph, the server invokes the first feature extraction layer to determine the similarity between the first subgraph feature and the first subgraph features of each relation subgraph in the second relation graph, and determines the first subgraph features of the second relation graph corresponding to the similarity greater than a reference similarity as the target subgraph features. Optionally, the similarity is a cosine similarity, and optionally, the reference similarity is zero, which is not limited in the embodiments of the application.
[0217] In the embodiments of the application, the subgraph features of the relation subgraphs in the second relation graph of the second text are used to update the subgraph features of the first relation graph, which is equivalent to fusing the subgraph features of the second relation graph into the subgraph features of the first relation graph, and is equivalent to learning the semantic information of the first text by combining the semantic information of the second text, so that the model can learn more accurate semantic information, and thus more accurate node features can be obtained.
[0218] In a possible implementation, the server updates the first subgraph feature based on at least one target subgraph feature to obtain an updated first subgraph feature, including: the server invokes the first feature extraction layer, selects a reference number of target subgraph features from the at least one target subgraph feature based on similarity between the first subgraph feature and each target subgraph feature in the at least one target subgraph feature, where the similarity between the selected target subgraph features and the first subgraph feature is greater than the similarity between the remaining target subgraph features in the at least one target subgraph feature and the first subgraph feature. Then, the server fuses the selected target subgraph features by taking the similarity between the selected target subgraph features and the first subgraph feature as a weight, to obtain a fused feature, and determines a difference feature between the first subgraph feature and the fused feature as the updated first subgraph feature. Optionally, the reference number is set to any number as required, and embodiments of the present application do not limit this.
[0219] In embodiments of the present application, since the target subgraph feature is a subgraph feature in the second relationship graph that is similar to the subgraph feature in the first relationship graph, the selected target subgraph is fused according to the similarity between the selected target subgraph and the subgraph feature in the first relationship graph, so that the fused feature can fully reflect the part of the semantic information in the second text that is similar to the semantic information in the first text. Therefore, the difference feature between the subgraph feature in the first relationship graph and the fused feature can fully reflect the difference between the similar part of the semantic information of the two texts, and the difference can truly reflect whether the two texts match. Therefore, the difference feature is determined as the updated subgraph feature, and the relationship between the first text and the second text identified based on the subgraph feature is more accurate, that is, the accuracy of text matching is higher. In addition, when selecting the target subgraph feature similar to the subgraph feature in the first relationship graph, a reference number of target subgraph features with greater similarity are selected, which can reduce the amount of data processed, improve the speed of feature extraction of the model, and further improve the relationship recognition efficiency of the model, and on the other hand, can improve the accuracy of the features extracted by the model, and further ensure the accuracy of text matching.
[0220] (C) The server invokes the next feature extraction layer, respectively fuses the second node features of the nodes in each relationship subgraph in the first relationship graph to obtain the second subgraph feature of each relationship subgraph, respectively fuses the second subgraph features of the relationship subgraphs to which each node in the first relationship graph belongs to obtain the third node feature of each node, and so on, until the node feature of each node output by the last feature extraction layer is obtained. The node feature of each node output by the last feature extraction layer is determined as the node feature of each node in the first relationship graph.
[0221] In the embodiments of the present application, assuming that the number of feature extraction layers is N, the i-th feature extraction layer outputs the (i+1)-th node feature and the i-th subgraph feature, and the N-th feature extraction layer outputs the (N+1)-th node feature and the N-th subgraph feature, where N is any positive integer greater than 1, i is any positive integer, and i is less than N.
[0222] In a possible implementation, after the server fuses the first subgraph feature of the relationship subgraph to which the node belongs to obtain the second node feature of the node, the method further includes: the server calling the first feature extraction layer, determining a second relationship parameter based on the first subgraph feature and the second node feature, the second relationship parameter representing the similarity between the second node feature of each node in the first relationship graph and the first subgraph feature of each relationship subgraph. Correspondingly, in step (C), the server calling the next feature extraction layer, fusing the second node features of the nodes in each relationship subgraph in the first relationship graph to obtain the second subgraph feature of each relationship subgraph, and fusing the second subgraph features of the relationship subgraphs to which each node in the first relationship graph belongs to obtain the third node feature of each node, includes the following two steps:
[0223] First, for each relationship subgraph in the first relationship graph, the server calls the next feature extraction layer, determines the similarity between the second node feature of the node in the relationship subgraph and the first subgraph feature of the relationship subgraph based on the second relationship parameter, and fuses the second node features of the nodes in the relationship subgraph by taking the similarity corresponding to the nodes in the relationship subgraph as the weight to obtain the second subgraph feature of the relationship subgraph.
[0224] Second, for each node in the first relationship graph, the server calls the next feature extraction layer, determines the similarity between the first subgraph feature of the relationship subgraph to which the node belongs and the second node feature of the node based on the second relationship parameter, and fuses the second subgraph features of the relationship subgraphs to which the node belongs by taking the similarity corresponding to the relationship subgraphs to which the node belongs as the weight to obtain the third node feature of the node.
[0225] It should be noted that the implementation of the server calling the next feature extraction layer to determine the second subgraph feature and the third node feature is the same as the implementation of the server calling the first feature extraction layer to determine the first subgraph feature and the second node feature, which will not be repeated here.
[0226] In the embodiment of the present application, when the feature extraction layer performs feature extraction, the node features of the nodes in the relationship subgraph are fused to obtain the subgraph features of the relationship subgraph, and then the subgraph features of the relationship subgraphs to which the nodes belong are fused to obtain the node features of the nodes. Through the two processes, the model can fully learn the semantic information of the text, and then obtain accurate node features. Moreover, in the process of fusing the node features of the nodes in the relationship subgraph to obtain the subgraph features of the relationship subgraph, and fusing the subgraph features of the relationship subgraphs to which the nodes belong to obtain the node features of the nodes, the similarity between the nodes and the relationship subgraphs is combined to further improve the accuracy of the fused subgraph features and node features.
[0227] In a possible implementation, the server calls the first feature extraction layer, and determines the second relationship parameter based on the first subgraph features and the second node features, including: the server obtains the cosine similarity between the second node features of each node in the first relationship graph and the first subgraph features of each relationship subgraph to obtain a plurality of cosine similarities; the server adjusts the cosine similarity smaller than the first reference similarity in the plurality of cosine similarities to a second reference similarity, and the second reference similarity represents the similarity between the second node features and the first subgraph features that are not similar. Then, the server generates the second relationship parameter based on the adjusted plurality of cosine similarities. Wherein, the first reference similarity and the second reference similarity can be set to any value, for example, the first reference similarity and the second reference similarity are 0, or the first reference similarity is 0.3 and the second reference similarity is 0, and the embodiment of the present application does not limit this.
[0228] Optionally, the second relationship parameter is in the form of a matrix, and each element in the matrix represents the similarity between the second node features of a node and the first subgraph features of a relationship subgraph. For example, the first element in the matrix represents the similarity between the node features of the first node and the first subgraph features of the first relationship subgraph, and the second element represents the similarity between the node features of the first node and the first subgraph features of the second relationship subgraph. Optionally, the second relationship parameter is determined by the following formula (3).
[0229]
[0230] Wherein, H ij represents the second relationship parameter, represents the second node features of the i th node, represents the first subgraph features of the j th relationship subgraph.
[0231] In the embodiments of the present application, when the relationship parameters are determined, the similarity between each node feature and each subgraph feature is determined, and the value with smaller similarity is adjusted to a similarity indicating that the node feature and the subgraph feature are not similar. Therefore, when the similarity corresponding to the nodes in the relationship subgraph is used as the weight to fuse the node features of the nodes in the relationship subgraph, the subgraph feature of the relationship subgraph is obtained, not only the accuracy of the subgraph feature can be improved, but also the data amount processed by the model can be reduced. Similarly, when the similarity corresponding to the relationship subgraph to which the node belongs is used as the weight to fuse the subgraph features of the relationship subgraph to which the node belongs, the node feature of the node is obtained, the accuracy of the node feature can be improved, and the data amount processed by the model can be reduced.
[0232] In a possible implementation, after the server fuses the second subgraph features of the relationship subgraph to which the node belongs by using the similarity corresponding to the relationship subgraph to which the node belongs as the weight, to obtain the third node feature of the node, the method further includes: the server invokes the next feature extraction layer, and determines a third relationship parameter based on the second subgraph feature and the third node feature, where the third relationship parameter indicates the similarity between the third node feature of each node in the first relationship graph and the second subgraph feature of each relationship subgraph. The implementation of determining the third relationship parameter is the same as that of determining the second relationship parameter, and details are not repeated here.
[0233] In a possible implementation, after the server invokes the next feature extraction layer to fuse the second node features of the nodes in each relationship subgraph in the first relationship graph respectively to obtain the second subgraph feature of each relationship subgraph, the method further includes: for the second subgraph feature of each relationship subgraph in the first relationship graph, the server invokes the next feature extraction layer to determine at least one target subgraph feature similar to the second subgraph feature; and the server updates the second subgraph feature based on the at least one target subgraph feature to obtain an updated second subgraph feature. The target subgraph feature is the second subgraph feature of the relationship subgraph in the second relationship graph.
[0234] In the embodiments of the present application, the subgraph features of the relationship subgraph in the second relationship graph are used to update the subgraph features of the first relationship graph, which is equivalent to fusing the subgraph features of the second relationship graph into the subgraph features of the first relationship graph, and is equivalent to learning the semantic information of the first text by combining the semantic information of the second text. In this way, the model can learn more accurate semantic information, and thus more accurate node features can be obtained.
[0235] In a possible implementation, the server updates the second subgraph feature based on the at least one target subgraph feature to obtain an updated second subgraph feature, including: the server invokes the next feature extraction layer, selects a reference number of target subgraph features from the at least one target subgraph feature based on the similarity between the second subgraph feature and each target subgraph feature in the at least one target subgraph feature. Wherein, the similarity between the selected target subgraph feature and the second subgraph feature is greater than the similarity between the remaining target subgraph features in the at least one target subgraph feature and the second subgraph feature. Then, the server fuses the selected target subgraph features by taking the similarity between the selected target subgraph features and the first subgraph feature as a weight, obtains a fused feature, and determines the difference feature between the second subgraph feature and the fused feature as the updated second subgraph feature.
[0236] It should be noted that the implementation of the server obtaining the updated second subgraph feature is the same as that of the server obtaining the updated first subgraph feature, which will not be repeated here. In addition, the implementation of the server invoking the feature extraction submodel to obtain the node feature of each node in the second relationship graph is the same as that of the server invoking the feature extraction submodel to obtain the node feature of each node in the first relationship graph, which will not be repeated here.
[0237] Figure 6 A process diagram for the feature extraction layer to extract node features. Referring to Figure 6 , the relationship graph includes multiple relationship subgraphs such as e1, e2 and e3, wherein e1 includes nodes n2, n4 and n8, e2 includes nodes n1, n6 and n7, and e3 includes nodes n3, n5 and n7. When the feature extraction layer performs feature extraction, the node features of nodes n2, n4 and n8 are fused to obtain the subgraph feature of e1, the node features of nodes n1, n6 and n7 are fused to obtain the subgraph feature of e2, and the node features of nodes n3, n5 and n7 are fused to obtain the subgraph feature of e3. In this way, the subgraph features of all relationship subgraphs in the relationship subgraph are obtained. Then, for a node belonging to multiple relationship subgraphs, the subgraph features of the relationship subgraphs to which the node belongs are fused to obtain the node feature of the node. For example, the node features of n7 are obtained by fusing the subgraph features of e2 and e3. For a node belonging to one relationship subgraph, the subgraph feature of the relationship subgraph to which the node belongs is determined as the node feature of the node. In this way, the node features of all nodes are obtained.
[0238] (2) The server invokes the classification submodel, obtains the first relationship graph feature based on the node feature of each node in the first relationship graph, and obtains the second relationship graph feature based on the node feature of each node in the second relationship graph.
[0239] The first relationship graph feature is used to represent semantic information of the first text, and the second relationship graph feature is used to represent semantic information of the second text.
[0240] In a possible implementation, the server invokes the classification sub-model, obtains the first relationship graph feature based on the node features of each node in the first relationship graph, and obtains the second relationship graph feature based on the node features of each node in the second relationship graph, including: the server invokes the classification sub-model, obtains an average value of the node features of the plurality of nodes in the first relationship graph, determines the average value as the first relationship graph feature, obtains an average value of the node features of the plurality of nodes in the second relationship graph, and determines the average value as the second relationship graph feature. Optionally, the relationship graph feature is determined by the following formula (4).
[0241]
[0242] wherein, denotes the relationship graph feature, n denotes the number of nodes in the relationship graph, denotes the node feature of the i th node.
[0243] In the embodiments of the present application, since the node feature of each node in the relationship graph can represent part of the semantic information of the text, by obtaining an average value of the node features of the plurality of nodes in the relationship graph and determining the average value as the relationship graph feature, the semantic information of each node is comprehensively reflected in the relationship graph feature, so that the semantic information of the entire text can be reflected, and the relationship between the texts can be identified based on the relationship graph feature, and the identified relationship is more accurate.
[0244] (3) The server invokes the classification sub-model, and determines the relationship label between the first relationship graph and the second relationship graph based on the first relationship graph feature and the second relationship graph feature.
[0245] The relationship label is used to represent the relationship between the first relationship graph and the second relationship graph, and the relationship is matching or non-matching. Optionally, the relationship label includes a probability that the first relationship graph and the second relationship graph match and a probability that the first relationship graph and the second relationship graph do not match, the sum of the two probabilities is 1, and the probability that the first relationship graph and the second relationship graph match is greater than the probability that the first relationship graph and the second relationship graph do not match, indicating that the relationship between the first relationship graph and the second relationship graph is matching, and the probability that the first relationship graph and the second relationship graph match is less than the probability that the first relationship graph and the second relationship graph do not match, indicating that the relationship between the first relationship graph and the second relationship graph is non-matching. The probability that the first relationship graph and the second relationship graph match is equal to the probability that the first relationship graph and the second relationship graph do not match, which indicates that the relationship between the first relationship graph and the second relationship graph is matching or non-matching, and the embodiments of the present application do not limit this.
[0246] Optionally, the classification sub-model comprises a feature extraction layer and a classification layer, the feature extraction layer is configured to obtain a first relation graph feature based on the node features of each node in the first relation graph, and obtain a second relation graph feature based on the node features of each node in the second relation graph. The classification layer is configured to determine the relationship label between the first relation graph and the second relation graph based on the first relation graph feature and the second relation graph feature. The implementation is as follows: the server calls the classification layer, splices the first relation graph feature and the second relation graph feature, inputs the spliced feature into a full connection layer in the classification layer, and determines the probability that the first relation graph and the second relation graph match and the probability that the first relation graph and the second relation graph do not match based on the output feature of the full connection layer through a softmax function (a kind of mapping function), and obtains the relationship label between the first relation graph and the second relation graph based on the two probabilities. Optionally, the method is implemented through the following formulas (5) and (6).
[0247]
[0248]
[0249] wherein Z represents the probability that the first relation graph and the second relation graph match and the probability that the first relation graph and the second relation graph do not match, represents the first relation graph feature, represents the second relation graph feature, represents the spliced feature of the first relation graph feature and the second relation graph feature, and V i represents the feature output by the full connection layer after the spliced feature is input into the full connection layer, the feature is a 1*2-dimensional vector, the vector comprises two elements, V i represents the i-th element in the vector, V j represents the j-th element in the vector. Softmax(V i ) is a 1*2-dimensional vector, the vector comprises two elements, which respectively represent the probability that the first relation graph and the second relation graph match and the probability that the first relation graph and the second relation graph do not match, and the sum of the two probabilities is 1.
[0250] 405、the server determines the second text as the text matched with the first text in response to the relationship label indicating that the first relation graph and the second relation graph match.
[0251] Figure 7 is a process diagram for determining the relationship label between the first relation graph and the second relation graph through the relation recognition model. Reference Figure 7For example, taking the feature extraction sub-model in the relationship identification model including two feature extraction layers as an example, the first relationship graph and the second relationship graph are respectively input into the first feature extraction layer in the feature extraction sub-model, then, for any relationship graph, the first feature extraction layer obtains the first node feature of each node in the relationship graph and the first relationship parameter of the relationship graph, and for each relationship subgraph in the relationship graph, the first node feature of the node belonging to the relationship subgraph is fused based on the first relationship parameter to obtain the first subgraph feature of the relationship subgraph. Then, for the first subgraph feature of each relationship subgraph in the first relationship graph, the target subgraph feature similar to the first subgraph feature is updated in the second relationship subgraph. For the first subgraph feature of each relationship subgraph in the second relationship graph, the target subgraph feature similar to the first subgraph feature is updated in the first relationship subgraph. Then, for each node in any relationship graph, the first subgraph feature of the relationship subgraph to which the node belongs is fused based on the first relationship parameter to obtain the second node feature of the node. Then, the second relationship parameter is determined based on the second node feature of the node and the first subgraph feature of the relationship subgraph. Then, the second node feature, the first subgraph feature and the second relationship parameter are input into the next feature extraction layer. The next feature extraction layer, for each relationship subgraph in any relationship graph, fuses the second node feature of the node in the relationship subgraph based on the second relationship parameter to obtain the second subgraph feature, and after updating the second subgraph feature by using the subgraph feature of the relationship subgraph in the other relationship graph, for any node, the current second subgraph feature of the relationship subgraph to which the node belongs is fused based on the second relationship parameter to obtain the third node feature. The third node feature is input into the feature extraction layer in the classification sub-model, the classification sub-model determines the first relationship graph feature based on the third node feature of the node in the first relationship graph, and determines the second relationship graph feature based on the third node feature of the node in the second relationship graph, then, the first relationship graph feature and the second relationship graph feature are input into the classification layer in the classification sub-model, and the classification layer determines the relationship label between the first relationship graph and the second relationship graph based on the first relationship graph feature and the second relationship graph feature.
[0252] It should be noted that, in the embodiments of the present application, only the case that the feature extraction sub-model includes multiple feature extraction layers is taken as an example for description, and optionally, the feature extraction sub-model includes one feature extraction layer, and then the feature extraction layer directly inputs the obtained first node feature of the node into the classification sub-model, and the classification sub-model determines the relationship label between the first relationship graph and the second relationship graph based on the first node feature. Such a method is simple and efficient. In addition, the relationship identification model in the embodiments of the present application can adopt any neural network model, which is not limited in the embodiments of the present application.
[0253] It should be noted that in the embodiments of the present application, each feature extraction layer in the feature extraction sub-model determines the current relationship parameter based on the current subgraph feature and node feature of the relationship subgraph after obtaining the subgraph feature and node feature of the relationship subgraph. It is equivalent to constantly updating the relationship parameter through multiple feature extraction layers. The relationship parameter can reflect the relationship between each node in the relationship graph and each relationship subgraph. Therefore, the updating process of the relationship parameter is also the updating and improvement process of the relationship graph. Each feature extraction layer obtains the current node feature based on the relationship parameter output by the previous feature extraction layer, that is, the node feature of the node in the relationship graph is extracted through the constantly updated and improved relationship graph. This can improve the accuracy of the node feature and ensure the accuracy of the text matching.
[0254] It should be noted that the text matching method in the embodiments of the present application can be applied to the matching between texts of various lengths. For example, the matching between short texts (i.e., the matching between sentences), the matching between a short text and a long text (i.e., the matching between a sentence and an article), and the matching between long texts (i.e., the matching between articles).
[0255] In the embodiments of the present application, considering that the relationship between each two words in a text cannot completely represent the semantic information of the text, when representing the text by a relationship graph, for each word in the text, each associated word of the word is selected from the text to form a word set, and the relationship graph is generated based on at least one formed word set. Since the relationship graph represents the text in units of relationship subgraphs, and each relationship subgraph can represent the association relationship between each word in the word set corresponding to the relationship subgraph, but is not limited to only two words, the relationship graph can completely represent the semantic information of the text, and the text matching through the relationship graph can improve the accuracy of the text matching.
[0256] In the embodiments of the present application, since the word vector of a word is used to represent the semantic of the word, the greater the similarity between the word vectors of the words, the closer the semantics of the words, and the more likely the words are associated. Therefore, when determining the associated words of the first word, the similarity between the word vector of the first word and the word vector of each second word is determined. The similarity can indicate the closeness of the semantics of the first word and the second word. Therefore, the associated words of the first word can be accurately determined based on the similarity.
[0257] In the embodiment of the present application, when the feature extraction layer performs feature extraction, the node features of the nodes in the relationship subgraph are first fused to obtain the subgraph feature of the relationship subgraph, and then the subgraph features of the relationship subgraphs to which the nodes belong are fused to obtain the node features of the nodes. Through these two processes, the model can fully learn the semantic information of the text, and then obtain accurate node features. Moreover, in the process of fusing the node features of the nodes in the relationship subgraph to obtain the subgraph feature of the relationship subgraph, and fusing the subgraph features of the relationship subgraphs to which the nodes belong to obtain the node features of the nodes, the similarity between the nodes and the relationship subgraphs is combined to further improve the accuracy of the fused subgraph features and node features.
[0258] In the embodiment of the present application, the subgraph features of the relationship subgraphs in the second relationship graph of the second text are used to update the subgraph features of the first relationship graph, which is equivalent to fusing the subgraph features of the second relationship graph in the subgraph features of the first relationship graph, and is equivalent to learning the semantic information of the first text in combination with the semantic information of the second text. In this way, the model can learn more accurate semantic information, thereby obtaining more accurate node features.
[0259] In the embodiment of the present application, since the target subgraph features are the subgraph features of the second relationship graph that are similar to the subgraph features of the first relationship graph, the selected target subgraphs are fused according to the similarity between the selected target subgraphs and the subgraph features of the first relationship graph. Therefore, the fused features can fully reflect the part of the semantic information in the second text that is similar to the semantic information in the first text. Therefore, the difference features between the subgraph features of the first relationship graph and the fused features can fully reflect the difference between the similar part semantic information of the two texts, and the difference can truly reflect whether the two texts match. Therefore, the difference features are determined as the updated subgraph features, and the relationship between the first text and the second text identified based on the subgraph features is more accurate, that is, the accuracy of text matching is higher. In addition, when selecting the target subgraph features similar to the subgraph features of the first relationship graph, the reference number of target subgraph features with larger similarity is selected. On the one hand, this can reduce the amount of data processed, improve the speed of feature extraction of the model, and further improve the relationship recognition efficiency of the model. On the other hand, this can improve the accuracy of the features extracted by the model, and further ensure the accuracy of text matching.
[0260] In the embodiment of the present application, when determining the relationship parameters, the similarity between each node feature and each subgraph feature is determined, and the value with smaller similarity is adjusted to the similarity indicating that the node feature and the subgraph feature are not similar. Therefore, in the process of fusing the node features of the nodes in the relationship subgraph by taking the similarity corresponding to the nodes in the relationship subgraph as the weight to obtain the subgraph feature of the relationship subgraph, the accuracy of the subgraph feature can be improved, and the data amount processed by the model can be reduced. Similarly, in the process of fusing the subgraph features of the relationship subgraphs to which the nodes belong by taking the similarity corresponding to the relationship subgraphs to which the nodes belong as the weight to obtain the node feature of the node, the accuracy of the node feature can be improved, and the data amount processed by the model can be reduced.
[0261] In the embodiment of the present application, since the node feature of each node in the relationship graph can represent part of the semantic information of the text, by obtaining the average value of the node features of the multiple nodes in the relationship graph and determining the average value as the relationship graph feature, the semantic information of each node is integrated in the relationship graph feature, so that the semantic information of the entire text can be embodied, and the relationship between the texts can be identified based on the relationship graph feature, and the identified relationship is more accurate.
[0262] Figure 8 is a flowchart of a text matching method provided by an embodiment of the present application. The embodiment describes the training process of the relationship identification model. Referring to Figure 8 , the embodiment includes the following steps.
[0263] 801. The server obtains sample data, and the sample data includes a first sample relationship graph, a second sample relationship graph, and a sample relationship label.
[0264] The sample relationship label is used to represent the relationship between the first sample relationship graph and the second sample relationship graph, and the relationship is matching or not matching. The implementation manner of the server obtaining the first sample relationship graph and the second sample relationship graph is the same as that of the server obtaining the first relationship graph and the second relationship graph, and details are not described herein.
[0265] 802. The server calls the relationship identification model to determine a predicted relationship label between the first sample relationship graph and the second sample relationship graph.
[0266] The predicted relationship label is used to represent the relationship between the first sample relationship graph and the second sample relationship graph predicted by the relationship identification model.
[0267] In a possible implementation manner, the relationship identification model includes a feature extraction submodel and a classification submodel. Correspondingly, the server calling the relationship identification model to determine the predicted relationship label between the first sample relationship graph and the second sample relationship graph includes the following steps (1)-(3).
[0268] (1) The server invokes the feature extraction sub-model to obtain the node features of each node in the first sample relation graph and the node features of each node in the second sample relation graph.
[0269] The node feature of the node is a feature of a word represented by the node.
[0270] In a possible implementation, the feature extraction sub-model includes a plurality of feature extraction layers. Correspondingly, the server invokes the feature extraction sub-model to obtain the node features of each node in the first sample relation graph includes the following steps (A)-(C).
[0271] (A) The server invokes the first feature extraction layer to obtain the first node features of each node in the first sample relation graph.
[0272] (B) The server invokes the first feature extraction layer to respectively fuse the first node features of the nodes in each relation subgraph in the first sample relation graph to obtain the first subgraph features of each relation subgraph, and respectively fuse the first subgraph features of the relation subgraphs to which each node belongs in the first sample relation graph to obtain the second node features of each node.
[0273] In a possible implementation, step (B) includes the following three steps.
[0274] First, the server obtains the first sample relation parameters of the first sample relation graph, which represent the relationship between each node and each relation subgraph in the first sample relation graph. The relationship is that the node belongs to the relation subgraph or the node does not belong to the relation subgraph.
[0275] The first sample relation graph directly reflects whether each node belongs to each relation subgraph, and therefore, the server can obtain the first relation parameters based on the first sample relation graph. Optionally, the first relation parameters are in the form of a matrix, and each element in the matrix represents the relationship between a node and a relation subgraph. For example, the first element in the matrix represents the relationship between the first node and the first relation subgraph, and the second element represents the relationship between the first node and the second relation subgraph. Optionally, the element is 0, indicating that the relationship between the node and the relation subgraph is that the node does not belong to the relation subgraph. The element is 1, indicating that the relationship between the node and the relation subgraph is that the node belongs to the relation subgraph.
[0276] Second, for each relation subgraph in the first sample relation graph, the server invokes the first feature extraction layer to determine the nodes in the relation subgraph based on the first sample relation parameters, and fuse the first node features of the nodes in the relation subgraph to obtain the first subgraph features of the relation subgraph.
[0277] Thirdly, for each node in the first sample relation graph, the server calls the first feature extraction layer to determine a relation subgraph to which the node belongs based on the first sample relation parameters, and fuse the first subgraph features of the relation subgraphs to which the node belongs to obtain the second node features of the node.
[0278] In the embodiments of the present application, when the feature extraction layer performs feature extraction, the subgraph features of the relation subgraphs are first obtained by fusing the node features of the nodes in the relation subgraphs, and then the node features of the nodes are obtained by fusing the subgraph features of the relation subgraphs to which the nodes belong. Through the two processes, the model can fully learn the semantic information of the text, and then obtain accurate node features.
[0279] In a possible implementation, after the server calls the first feature extraction layer to fuse the first node features of the nodes in each relation subgraph in the first sample relation graph to obtain the first subgraph features of each relation subgraph, the method further includes: for the first subgraph features of each relation subgraph in the first sample relation graph, the server calls the first feature extraction layer to determine at least one target subgraph feature similar to the first subgraph features; the server updates the first subgraph features based on the at least one target subgraph feature to obtain updated first subgraph features. The target subgraph features are the first subgraph features of the relation subgraphs in the second sample relation graph. The implementation of obtaining the first subgraph features of the relation subgraphs in the second sample relation graph is the same as that of obtaining the first subgraph features of the relation subgraphs in the first sample relation graph, and will not be repeated here.
[0280] In the embodiments of the present application, the subgraph features of the relation subgraphs in the second sample relation graph of the second sample text are used to update the subgraph features of the first sample relation graph, which is equivalent to fusing the subgraph features of the second sample relation graph into the subgraph features of the first sample relation graph, which is equivalent to learning the semantic information of the first sample text in combination with the semantic information of the second sample text. In this way, the model can learn more accurate semantic information, and thus obtain more accurate node features.
[0281] In a possible implementation, the server updates the first subgraph feature based on at least one target subgraph feature to obtain an updated first subgraph feature, including: the server invokes the first feature extraction layer, selects a reference number of target subgraph features from the at least one target subgraph feature based on similarity between the first subgraph feature and each target subgraph feature in the at least one target subgraph feature, and the similarity between the selected target subgraph features and the first subgraph feature is greater than the similarity between the remaining target subgraph features in the at least one target subgraph feature and the first subgraph feature. The server fuses the selected target subgraph features by taking the similarity between the selected target subgraph features and the first subgraph feature as a weight, obtains a fused feature, and determines a difference feature between the first subgraph feature and the fused feature as the updated first subgraph feature.
[0282] In the embodiment of the application, since the target subgraph feature is a subgraph feature of the second sample relationship graph that is similar to the subgraph feature of the first sample relationship graph, the selected target subgraph is fused according to the similarity between the selected target subgraph and the subgraph feature of the first sample relationship graph, so that the fused feature can fully reflect the similar part of the semantic information in the second sample text and the semantic information in the first sample text. Therefore, the difference feature between the subgraph feature of the first sample relationship graph and the fused feature can fully reflect the difference between the similar part of the semantic information of the two sample texts, and the difference can truly reflect whether the two sample texts match. Therefore, the difference feature is determined as the updated subgraph feature, and the relationship between the first sample text and the second sample text identified based on the subgraph feature is more accurate, that is, the accuracy of sample text matching is higher. In addition, when selecting the target subgraph feature similar to the subgraph feature of the first sample relationship graph, a reference number of target subgraph features with greater similarity are selected, which can reduce the amount of data processed, improve the speed of feature extraction of the model, and further improve the relationship recognition efficiency of the model, and on the other hand, can improve the accuracy of the features extracted by the model, and further ensure the accuracy of sample text matching.
[0283] (C) The server invokes the next feature extraction layer, respectively fuses the second node features of the nodes in each relationship subgraph in the first sample relationship graph to obtain the second subgraph feature of each relationship subgraph, respectively fuses the second subgraph features of the relationship subgraphs to which each node in the first sample relationship graph belongs to obtain the third node feature of each node, and obtains the node feature of each node output by the last feature extraction layer. The node feature of each node output by the last feature extraction layer is determined as the node feature of each node in the first sample relationship graph.
[0284] In a possible implementation, after the server fuses the first subgraph features of the relationship subgraph to which the node belongs to obtain the second node features of the node, the method comprises the following steps: the server invokes the first feature extraction layer, and determines the second sample relationship parameters based on the first subgraph features and the second node features, the second sample relationship parameters representing the similarity between the second node features of each node in the first sample relationship graph and the first subgraph features of each relationship subgraph. Correspondingly, in step (C), the server invokes the next feature extraction layer, fuses the second node features of the nodes in each relationship subgraph in the first sample relationship graph to obtain the second subgraph features of each relationship subgraph, and fuses the second subgraph features of the relationship subgraphs to which each node belongs to obtain the third node features of each node, comprising the following two steps:
[0285] First, for each relationship subgraph in the first sample relationship graph, the server invokes the next feature extraction layer, determines the similarity between the second node features of the nodes in the relationship subgraph and the first subgraph features of the relationship subgraph based on the second sample relationship parameters, and fuses the second node features of the nodes in the relationship subgraph by taking the similarity corresponding to the nodes in the relationship subgraph as the weight to obtain the second subgraph features of the relationship subgraph.
[0286] Second, for each node in the first sample relationship graph, the server invokes the next feature extraction layer, determines the similarity between the first subgraph features of the relationship subgraph to which the node belongs and the second node features of the node based on the second sample relationship parameters, and fuses the second subgraph features of the relationship subgraph to which the node belongs by taking the similarity corresponding to the relationship subgraph to which the node belongs as the weight to obtain the third node features of the node.
[0287] In the embodiments of the present application, when the feature extraction layer performs feature extraction, the node features of the nodes in the relationship subgraph are fused to obtain the subgraph features of the relationship subgraph, and then the subgraph features of the relationship subgraph to which the node belongs are fused to obtain the node features of the node. Through the two processes, the model can fully learn the semantic information of the sample text, and then obtain accurate node features. Moreover, in the process of fusing the node features of the nodes in the relationship subgraph to obtain the subgraph features of the relationship subgraph and fusing the subgraph features of the relationship subgraph to which the node belongs to obtain the node features of the node, the similarity between the node and the relationship subgraph is combined, which further improves the accuracy of the subgraph features and the node features obtained by fusion.
[0288] In a possible implementation, the server calls the first feature extraction layer, and determines the second sample relationship parameter based on the first subgraph feature and the second node feature, including: the server obtains a plurality of cosine similarities between the second node feature of each node in the first sample relationship graph and the first subgraph feature of each relationship subgraph; the server adjusts the cosine similarity smaller than the first reference similarity in the plurality of cosine similarities to a second reference similarity, and the second reference similarity represents the similarity between the second node feature and the first subgraph feature that are not similar; and the server generates the second sample relationship parameter based on the adjusted plurality of cosine similarities.
[0289] In the embodiments of the present application, when determining the relationship parameter, the similarity between each node feature and each subgraph feature is determined, and the value with smaller similarity is adjusted to the similarity representing that the node feature and the subgraph feature are not similar. Therefore, in the process of fusing the node features of the nodes in the relationship subgraph by taking the similarity corresponding to the nodes in the relationship subgraph as the weight, the accuracy of the subgraph feature can be improved, and the data amount processed by the model can be reduced. Similarly, in the process of fusing the subgraph features of the relationship subgraph to which the node belongs by taking the similarity corresponding to the relationship subgraph to which the node belongs as the weight, the accuracy of the node feature can be improved, and the data amount processed by the model can be reduced.
[0290] In a possible implementation, after the server fuses the second subgraph feature of the relationship subgraph to which the node belongs by taking the similarity corresponding to the relationship subgraph to which the node belongs as the weight, to obtain the third node feature of the node, the method further includes: the server calls the next feature extraction layer, and determines the third sample relationship parameter based on the second subgraph feature and the third node feature, where the third sample relationship parameter represents the similarity between the third node feature of each node in the first sample relationship graph and the second subgraph feature of each relationship subgraph.
[0291] In a possible implementation, after the server calls the next feature extraction layer and fuses the second node feature of the node in each relationship subgraph in the first sample relationship graph to obtain the second subgraph feature of each relationship subgraph, the method further includes: for the second subgraph feature of each relationship subgraph in the first sample relationship graph, the server calls the next feature extraction layer to determine at least one target subgraph feature similar to the second subgraph feature; and the server updates the second subgraph feature based on the at least one target subgraph feature to obtain an updated second subgraph feature. The target subgraph feature is the second subgraph feature of the relationship subgraph in the second sample relationship graph.
[0292] In the embodiments of the present application, the subgraph features of the relationship subgraph in the second sample relationship graph are used to update the subgraph features of the first sample relationship graph, which is equivalent to fusing the subgraph features of the second sample relationship graph in the subgraph features of the first sample relationship graph, that is, learning the semantic information of the first sample text in combination with the semantic information of the second sample text, so that the model can learn more accurate semantic information, thereby obtaining more accurate node features.
[0293] In a possible implementation, the server updates the second subgraph feature based on the at least one target subgraph feature to obtain an updated second subgraph feature, including: the server invokes the next feature extraction layer, selects a reference number of target subgraph features from the at least one target subgraph feature based on the similarity between the second subgraph feature and each target subgraph feature in the at least one target subgraph feature, and the similarity between the selected target subgraph features and the second subgraph feature is greater than the similarity between the remaining target subgraph features in the at least one target subgraph feature and the second subgraph feature; the server fuses the selected target subgraph features by taking the similarity between the selected target subgraph features and the first subgraph feature as a weight to obtain a fused feature, and determines the difference feature between the second subgraph feature and the fused feature as the updated second subgraph feature.
[0294] It should be noted that the implementation of the server invoking the relationship identification model to determine the predicted relationship label between the first sample relationship graph and the second sample relationship graph is the same as the implementation of the server invoking the relationship identification model to determine the relationship label between the first relationship graph and the second relationship graph, which will not be repeated here.
[0295] (2) The server invokes the classification sub-model to obtain the first sample relationship graph feature based on the node feature of each node in the first sample relationship graph, and obtains the second sample relationship graph feature based on the node feature of each node in the second sample relationship graph.
[0296] The first sample relationship graph feature is used to represent the semantic information of the first sample text, and the second sample relationship graph feature is used to represent the semantic information of the second sample text.
[0297] In a possible implementation, the server invokes the classification sub-model to obtain the first sample relationship graph feature based on the node feature of each node in the first sample relationship graph, and obtains the second sample relationship graph feature based on the node feature of each node in the second sample relationship graph, including: the server invokes the classification sub-model to obtain the average value of the node features of the plurality of nodes in the first sample relationship graph, and determines the average value as the first sample relationship graph feature, and obtains the average value of the node features of the plurality of nodes in the second sample relationship graph, and determines the average value as the second sample relationship graph feature.
[0298] In the embodiment of the present application, since the node features of each node in the sample relation graph can represent part of the semantic information of the sample text, by obtaining the average value of the node features of the plurality of nodes in the sample relation graph, and determining the average value as the sample relation graph feature, the sample relation graph feature integrates the semantic information of each node, thereby being able to reflect the semantic information of the entire sample text, and the relationship between the sample texts is identified based on the sample relation graph feature, and the identified relationship is more accurate.
[0299] (3) The server calls the classification sub-model, and determines a predicted relationship label between the first sample relation graph and the second sample relation graph based on the first sample relation graph feature and the second sample relation graph feature.
[0300] The predicted relationship label is used to represent the predicted relationship between the first sample relation graph and the second sample relation graph, and the relationship is matching or not matching. Optionally, the predicted relationship label includes a probability that the first sample relation graph and the second sample relation graph match and a probability that the first sample relation graph and the second sample relation graph do not match, and the sum of the two probabilities is 1. The probability that the first sample relation graph and the second sample relation graph match is greater than the probability that the first sample relation graph and the second sample relation graph do not match, indicating that the relationship between the first sample relation graph and the second sample relation graph is matching. The probability that the first sample relation graph and the second sample relation graph match is less than the probability that the first sample relation graph and the second sample relation graph do not match, indicating that the relationship between the first sample relation graph and the second sample relation graph is not matching. The probability that the first sample relation graph and the second sample relation graph match is equal to the probability that the first sample relation graph and the second sample relation graph do not match, indicating that the relationship between the first sample relation graph and the second sample relation graph is matching or not matching, which is not limited in the embodiment of the present application.
[0301] 803. The server trains the relationship identification model based on the sample relation label and the predicted relationship label.
[0302] The server trains the relationship identification model based on the sample relation label and the predicted relationship label, so that the similarity between the predicted relationship label predicted by the relationship identification model and the sample relation label is continuously close until a certain threshold is reached.
[0303] In a possible implementation, the server trains the relationship identification model based on the sample relation label and the predicted relationship label, including: the server determines a loss value of the relationship identification model based on the sample relation label and the predicted relationship label; and the server trains the relationship identification model based on the loss value. The loss value is used to represent the similarity between the sample relation label and the predicted relationship label, and the loss value and the similarity between the sample relation label and the predicted relationship label are in a negative correlation relationship, that is, the smaller the loss value, the greater the similarity between the sample relation label and the predicted relationship label. Optionally, the server trains the relationship identification model based on the loss value, and the implementation is that the server adjusts the parameters of the model, so that the loss value obtained based on the adjusted relationship identification model becomes smaller. Optionally, the loss value of the relationship identification model is determined by the following formula (7).
[0304]
[0305] wherein, L c denotes the loss value of the relationship identification model, Z lf denotes the predicted relationship label, the predicted relationship label is a 1*2 dimensional vector, the first element in the vector represents the probability that the first sample relationship graph does not match the second sample relationship graph, and the second element represents the probability that the first sample relationship graph matches the second sample relationship graph, Y lf denotes the sample relationship label, the sample relationship label is a 1*2 dimensional vector, the first element in the vector represents the probability that the first sample relationship graph does not match the second sample relationship graph in reality, for example, 1 or 0, and the second element represents the probability that the first sample relationship graph matches the second sample relationship graph in reality, for example, 1 or 0, and the sum of the two elements is 1. Y L denotes the number of sample data, l denotes the serial number of sample data, F denotes the dimension of the sample relationship label and the predicted relationship label, that is, 2, and f denotes the serial number of the dimension of the sample relationship label and the predicted relationship label.
[0306] In a possible implementation, the server trains the relationship identification model based on the sample relationship label and the predicted relationship label, including the following four steps.
[0307] First, the server obtains the sample relationship parameters output by the last feature extraction layer, and the sample relationship parameters represent the similarity between the node features of each node in the first sample relationship graph and the subgraph features of each relationship subgraph.
[0308] wherein, the sample relationship parameters of the last feature extraction layer are obtained in the same manner as the above-mentioned second sample relationship parameters, which will not be described here.
[0309] Second, the server determines a first loss value based on the sample relationship parameters, and the first loss value is used to represent the discrete degree of the similarity between the node features of multiple pairs of adjacent nodes belonging to the same relationship subgraph.
[0310] The discrete degree of the similarity between the node features of multiple pairs of adjacent nodes belonging to the same relationship subgraph is positively correlated with the first loss value, that is, the smaller the first loss value, the smaller the discrete degree, and the larger the first loss value, the larger the discrete degree. Optionally, the first loss value of the relationship identification model is determined by the following formula (8).
[0311]
[0312] wherein, L g denotes the first loss value of the relationship identification model, I denotes a unit matrix, D Va diagonal matrix representing degrees of nodes, D E a diagonal matrix representing degrees of the subgraph of relations, H is a matrix representing sample relation parameters output by the last feature extraction layer, H T denotes a transpose of the matrix, h is a matrix representing first node features of nodes in the sample relation graph, h T denotes a transpose of the matrix, tr(M) denotes a trace of the matrix M.
[0313] Thirdly, the server determines a second loss value of the relation recognition model based on the sample relation label and the predicted relation label, and the second loss value is used to represent a similarity between the sample relation label and the predicted relation label.
[0314] Optionally, the second loss value of the relation recognition model is determined by the above formula (7).
[0315] Fourthly, the server trains the relation recognition model based on a total loss value of the first loss value and the second loss value.
[0316] Optionally, the server trains the relation recognition model based on the total loss value of the first loss value and the second loss value, and an implementation manner is that the server adjusts parameters of the model, so that the total loss value obtained based on the adjusted relation recognition model becomes smaller. Optionally, the total loss value of the relation recognition model is determined by the following formula (9).
[0317] L = L g + L c (9)
[0318] wherein L represents the total loss value of the relation recognition model, L g represents the first loss value, L c represents the second loss value.
[0319] In the embodiments of the present application, since the first loss value represents a discrete degree of the similarity between the node features of the multiple pairs of adjacent nodes belonging to the same subgraph of relations, the relation recognition model is trained by the first loss value, so that the discrete degree of the similarity between the node features of the multiple pairs of adjacent nodes belonging to the same subgraph of relations becomes smaller, and since the subgraph of relations is used to represent that there is a correlation between each word represented by each node in the subgraph of relations, the smaller the discrete degree is, that is, the more accurate the correlation words determined by the model are, and the more accurate the semantic information represented by the extracted correlation words is, so that the accuracy of the text matching can be improved.
[0320] In the embodiment of the present application, when the feature extraction layer performs feature extraction, the node features of the nodes in the relation subgraph are first fused to obtain the subgraph feature of the relation subgraph, and then the subgraph features of the relation subgraphs to which the nodes belong are fused to obtain the node features of the nodes. Through these two processes, the model can fully learn the semantic information of the sample text, and then obtain accurate node features. Moreover, in the process of fusing the node features of the nodes in the relation subgraph to obtain the subgraph feature of the relation subgraph, and fusing the subgraph features of the relation subgraphs to which the nodes belong to obtain the node features of the nodes, the similarity between the nodes and the relation subgraphs is combined to further improve the accuracy of the fused subgraph features and node features.
[0321] In the embodiment of the present application, the subgraph features of the relation subgraphs in the second sample relation graph are used to update the subgraph features of the first sample relation graph, which is equivalent to fusing the subgraph features of the second sample relation graph in the subgraph features of the first sample relation graph, and is equivalent to learning the semantic information of the first sample text in combination with the semantic information of the second sample text. In this way, the model can learn more accurate semantic information, thereby obtaining more accurate node features.
[0322] In the embodiment of the present application, since the target subgraph features are the subgraph features of the second sample relation graph that are similar to the subgraph features of the first sample relation graph, the selected target subgraphs are fused according to the similarity between the selected target subgraphs and the subgraph features of the first sample relation graph. Therefore, the fused features can fully reflect the part of the semantic information in the second sample text that is similar to the semantic information in the first sample text. Therefore, the difference features between the subgraph features of the first sample relation graph and the fused features can fully reflect the difference between the similar part of the semantic information of the two sample texts, and the difference can truly reflect whether the two sample texts match. Therefore, the difference features are determined as the updated subgraph features, and the relationship between the first sample text and the second sample text identified based on the subgraph features is more accurate, that is, the accuracy of sample text matching is higher. In addition, when selecting the target subgraph features similar to the subgraph features of the first sample relation graph, the reference number of target subgraph features with larger similarity is selected. On the one hand, this can reduce the amount of data processed, improve the speed of feature extraction of the model, and further improve the relationship recognition efficiency of the model. On the other hand, this can improve the accuracy of the features extracted by the model, and further ensure the accuracy of sample text matching.
[0323] In the embodiment of the present application, when determining the relationship parameters, the similarity between each node feature and each subgraph feature is determined, and the value of the smaller similarity is adjusted to the similarity indicating that the node feature and the subgraph feature are not similar. Therefore, in the process of fusing the node features of the nodes in the relationship subgraph by taking the similarity corresponding to the nodes in the relationship subgraph as the weight to obtain the subgraph feature of the relationship subgraph, not only the accuracy of the subgraph feature can be improved, but also the data amount processed by the model can be reduced. Similarly, in the process of fusing the subgraph features of the relationship subgraphs to which the nodes belong by taking the similarity corresponding to the relationship subgraphs to which the nodes belong as the weight to obtain the node feature of the node, the accuracy of the node feature can be improved, and the data amount processed by the model can be reduced.
[0324] In the embodiment of the present application, since the node feature of each node in the sample relationship graph can represent part of the semantic information of the sample text, by obtaining the average value of the node features of the multiple nodes in the sample relationship graph, and determining the average value as the sample relationship graph feature, the sample relationship graph feature integrates the semantic information of each node, so as to reflect the semantic information of the entire sample text. Based on the sample relationship graph feature, the relationship between the sample texts is identified, and the identified relationship is more accurate.
[0325] All the optional technical solutions described above can be combined to form optional embodiments of the present application, which will not be described here again.
[0326] Figure 9 is a block diagram of a text matching device provided by an embodiment of the present application. Referring to Figure 9 , the device comprises:
[0327] The text acquisition module 91 is configured to acquire a first text.
[0328] The set forming module 92 is configured to, for each word in the first text, select each associated word of the word from the first text, and form a word set by using the word and each selected associated word.
[0329] The relationship graph generation module 93 is configured to generate a first relationship graph based on the formed at least one word set. The first relationship graph comprises at least one relationship subgraph. Each relationship subgraph corresponds to a word set. Each node in each relationship subgraph is used to represent a word in the corresponding word set. Each relationship subgraph is used to represent that there is an association relationship between each word in the corresponding word set.
[0330] The text matching module 94 is configured to perform text matching based on the first relationship graph.
[0331] In a possible implementation, the set forming module 92 is configured to determine a similarity between the first word vector of the first word and the second word vector of each second word, the first word being any word in the first text, and the second word being any word in the first text except the first word; select the second word corresponding to each second word vector whose similarity with the first word vector is less than a reference threshold; and form a word set by using the first word and each selected second word.
[0332] In a possible implementation, the reference Figure 10 The text matching module 94 includes:
[0333] The label determining sub-module 941 is configured to invoke the relationship identification model to determine a relationship label between the first relationship graph and the second relationship graph corresponding to the second text, the relationship label being used to represent a relationship between the first relationship graph and the second relationship graph, the relationship being matching or not matching.
[0334] The text determining sub-module 942 is configured to determine the second text as the text matched with the first text in response to the relationship label representing that the first relationship graph and the second relationship graph are matched.
[0335] In a possible implementation, the relationship identification model includes a feature extraction sub-model and a classification sub-model; the reference Figure 10 The label determining sub-module 941 includes:
[0336] The node feature obtaining unit 9411 is configured to invoke the feature extraction sub-model to obtain a node feature of each node in the first relationship graph and a node feature of each node in the second relationship graph, the node feature of the node being a feature of a word represented by the node.
[0337] The graph feature obtaining unit 9412 is configured to invoke the classification sub-model to obtain a first relationship graph feature based on the node feature of each node in the first relationship graph and to obtain a second relationship graph feature based on the node feature of each node in the second relationship graph.
[0338] The label determining unit 9413 is configured to determine the relationship label between the first relationship graph and the second relationship graph based on the first relationship graph feature and the second relationship graph feature.
[0339] In a possible implementation, the graph feature obtaining unit 9412 is configured to invoke the classification sub-model to obtain an average value of the node features of the plurality of nodes in the first relationship graph, determine the average value as the first relationship graph feature, obtain an average value of the node features of the plurality of nodes in the second relationship graph, and determine the average value as the second relationship graph feature.
[0340] In a possible implementation, the feature extraction sub-model includes a plurality of feature extraction layers; the reference Figure 10, a node feature acquisition unit 9411, comprising:
[0341] The first feature acquisition subunit 94111 is configured to call the first feature extraction layer to acquire the first node feature of each node in the first relationship graph.
[0342] The second feature acquisition subunit 94112 is configured to call the first feature extraction layer to respectively fuse the first node features of the nodes in each relationship subgraph in the first relationship graph to obtain the first subgraph feature of each relationship subgraph, and respectively fuse the first subgraph features of the relationship subgraphs to which each node in the first relationship graph belongs to obtain the second node feature of each node.
[0343] The third feature acquisition subunit 94113 is configured to call the next feature extraction layer to respectively fuse the second node features of the nodes in each relationship subgraph in the first relationship graph to obtain the second subgraph feature of each relationship subgraph, and respectively fuse the second subgraph features of the relationship subgraphs to which each node in the first relationship graph belongs to obtain the third node feature of each node, until the node feature of each node output by the last feature extraction layer is obtained, and the node feature of each node output by the last feature extraction layer is determined as the node feature of each node in the first relationship graph.
[0344] In a possible implementation, the second feature acquisition subunit 94112 is configured to acquire the first relationship parameter of the first relationship graph, the first relationship parameter representing the relationship between each node in the first relationship graph and each relationship subgraph, the relationship being that the node belongs to the relationship subgraph or the node does not belong to the relationship subgraph; for each relationship subgraph in the first relationship graph, the first feature extraction layer is called to determine the nodes in the relationship subgraph based on the first relationship parameter, and the first node features of the nodes in the relationship subgraph are fused to obtain the first subgraph feature of the relationship subgraph; for each node in the first relationship graph, the first feature extraction layer is called to determine the relationship subgraph to which the node belongs based on the first relationship parameter, and the first subgraph feature of the relationship subgraph to which the node belongs is fused to obtain the second node feature of the node.
[0345] In a possible implementation, the second feature acquisition subunit 94112 is further configured to call the first feature extraction layer to determine the second relationship parameter based on the first subgraph feature and the second node feature, the second relationship parameter representing the similarity between the second node feature of each node in the first relationship graph and the first subgraph feature of each relationship subgraph.
[0346] The third feature obtaining sub-unit 94113 is configured to, for each relation subgraph in the first relation graph, call the next feature extraction layer, determine the similarity between the second node features of the nodes in the relation subgraph and the first subgraph feature of the relation subgraph based on the second relation parameter, take the similarity corresponding to the nodes in the relation subgraph as the weight, and fuse the second node features of the nodes in the relation subgraph to obtain the second subgraph feature of the relation subgraph; for each node in the first relation graph, call the next feature extraction layer, determine the similarity between the first subgraph feature of the relation subgraph to which the node belongs and the second node feature of the node based on the second relation parameter, take the similarity corresponding to the relation subgraph to which the node belongs as the weight, and fuse the second subgraph feature of the relation subgraph to which the node belongs to obtain the third node feature of the node.
[0347] In a possible implementation, the second feature obtaining sub-unit 94112 is configured to obtain the cosine similarity between the second node feature of each node in the first relation graph and the first subgraph feature of each relation subgraph to obtain a plurality of cosine similarities; adjust the cosine similarity smaller than the first reference similarity in the plurality of cosine similarities to a second reference similarity, and the second reference similarity represents the similarity between the second node feature and the first subgraph feature that are not similar; and generate the second relation parameter based on the adjusted plurality of cosine similarities.
[0348] In a possible implementation, the third feature obtaining sub-unit 94113 is further configured to call the next feature extraction layer, determine the third relation parameter based on the second subgraph feature and the third node feature, and the third relation parameter represents the similarity between the third node feature of each node in the first relation graph and the second subgraph feature of each relation subgraph.
[0349] In a possible implementation, the second feature obtaining sub-unit 94112 is further configured to, for the first subgraph feature of each relation subgraph in the first relation graph, call the first feature extraction layer, determine at least one target subgraph feature similar to the first subgraph feature; update the first subgraph feature based on the at least one target subgraph feature to obtain an updated first subgraph feature; and the target subgraph feature is the first subgraph feature of the relation subgraph in the second relation graph.
[0350] In a possible implementation, the second feature obtaining subunit 94112 is configured to call the first feature extraction layer, select a reference number of target subgraph features from the at least one target subgraph feature based on the similarity between the first subgraph feature and each of the at least one target subgraph feature, the similarity between the selected target subgraph feature and the first subgraph feature being greater than the similarity between the remaining target subgraph features in the at least one target subgraph feature and the first subgraph feature, and fuse the selected target subgraph features by taking the similarity between the selected target subgraph features and the first subgraph feature as a weight to obtain a fused feature, and determine a difference feature between the first subgraph feature and the fused feature as an updated first subgraph feature.
[0351] In a possible implementation, the third feature obtaining subunit 94113 is further configured to, for the second subgraph feature of each relationship subgraph in the first relationship graph, call the next feature extraction layer to determine at least one target subgraph feature similar to the second subgraph feature, and update the second subgraph feature based on the at least one target subgraph feature to obtain an updated second subgraph feature, where the target subgraph feature is a second subgraph feature of a relationship subgraph in the second relationship graph.
[0352] In a possible implementation, the third feature obtaining subunit 94113 is configured to call the next feature extraction layer, select a reference number of target subgraph features from the at least one target subgraph feature based on the similarity between the second subgraph feature and each of the at least one target subgraph feature, the similarity between the selected target subgraph feature and the second subgraph feature being greater than the similarity between the remaining target subgraph features in the at least one target subgraph feature and the second subgraph feature, fuse the selected target subgraph features by taking the similarity between the selected target subgraph features and the second subgraph feature as a weight to obtain a fused feature, and determine a difference feature between the second subgraph feature and the fused feature as an updated second subgraph feature.
[0353] In a possible implementation, the training process of the relationship identification model includes:
[0354] obtaining sample data, the sample data including a first sample relationship graph, a second sample relationship graph, and a sample relationship label, the sample relationship label being used to represent a relationship between the first sample relationship graph and the second sample relationship graph, the relationship being matching or not matching;
[0355] calling the relationship identification model to determine a predicted relationship label between the first sample relationship graph and the second sample relationship graph, the predicted relationship label being used to represent a predicted relationship between the first sample relationship graph and the second sample relationship graph;
[0356] training the relationship identification model based on the sample relationship label and the predicted relationship label.
[0357] In a possible implementation, the relationship identification model is trained based on the sample relationship label and the predicted relationship label, including:
[0358] A loss value of the relationship identification model is determined based on the sample relationship label and the predicted relationship label.
[0359] The relationship identification model is trained based on the loss value, and the loss value is used to represent the similarity between the sample relationship label and the predicted relationship label.
[0360] In a possible implementation, the relationship identification model includes a feature extraction sub-model and a classification sub-model; the relationship identification model is invoked to determine the predicted relationship label between the first sample relationship graph and the second sample relationship graph, including:
[0361] The feature extraction sub-model is invoked to obtain the node feature of each node in the first sample relationship graph and the node feature of each node in the second sample relationship graph, the node feature of the node being the feature of the word represented by the node;
[0362] The classification sub-model is invoked to obtain the first sample relationship graph feature based on the node feature of each node in the first sample relationship graph, and obtain the second sample relationship graph feature based on the node feature of each node in the second sample relationship graph;
[0363] The predicted relationship label between the first sample relationship graph and the second sample relationship graph is determined based on the first sample relationship graph feature and the second sample relationship graph feature.
[0364] In a possible implementation, the classification sub-model is invoked to obtain the first sample relationship graph feature based on the node feature of each node in the first sample relationship graph, and obtain the second sample relationship graph feature based on the node feature of each node in the second sample relationship graph, including:
[0365] The classification sub-model is invoked to obtain the average value of the node features of the plurality of nodes in the first sample relationship graph, and determine the average value as the first sample relationship graph feature, and obtain the average value of the node features of the plurality of nodes in the second sample relationship graph, and determine the average value as the second sample relationship graph feature.
[0366] In a possible implementation, the feature extraction sub-model includes a plurality of feature extraction layers; the feature extraction sub-model is invoked to obtain the node feature of each node in the first sample relationship graph, including:
[0367] The first feature extraction layer is invoked to obtain the first node feature of each node in the first sample relationship graph;
[0368] The first feature extraction layer is called to fuse the first node features of the nodes in each relation subgraph in the first sample relation graph respectively to obtain first subgraph features of each relation subgraph, and the first subgraph features of the relation subgraphs to which each node in the first sample relation graph belongs are fused respectively to obtain second node features of each node.
[0369] The next feature extraction layer is called to fuse the second node features of the nodes in each relation subgraph in the first sample relation graph respectively to obtain second subgraph features of each relation subgraph, and the second subgraph features of the relation subgraphs to which each node in the first sample relation graph belongs are fused respectively to obtain third node features of each node, until the node features of each node output by the last feature extraction layer are obtained, and the node features of each node output by the last feature extraction layer are determined as the node features of each node in the first sample relation graph.
[0370] In a possible implementation, the calling of the first feature extraction layer to fuse the first node features of the nodes in each relation subgraph in the first sample relation graph respectively to obtain first subgraph features of each relation subgraph, and the fusion of the first subgraph features of the relation subgraphs to which each node in the first sample relation graph belongs to obtain second node features of each node include:
[0371] The first sample relation parameters of the first sample relation graph are obtained, which represent the relations between each node in the first sample relation graph and each relation subgraph, and the relation is that the node belongs to the relation subgraph or the node does not belong to the relation subgraph;
[0372] For each relation subgraph in the first sample relation graph, the first feature extraction layer is called to determine the nodes in the relation subgraph based on the first sample relation parameters, and the first node features of the nodes in the relation subgraph are fused to obtain first subgraph features of the relation subgraph;
[0373] For each node in the first sample relation graph, the first feature extraction layer is called to determine the relation subgraph to which the node belongs based on the first sample relation parameters, and the first subgraph features of the relation subgraph to which the node belongs are fused to obtain second node features of the node.
[0374] In a possible implementation, after the fusion of the first subgraph features of the relation subgraph to which the node belongs to obtain the second node features of the node, the apparatus includes:
[0375] The first feature extraction layer is called to determine second sample relation parameters based on the first subgraph features and the second node features, and the second sample relation parameters represent the similarity between the second node features of each node in the first sample relation graph and the first subgraph features of each relation subgraph;
[0376] The next feature extraction layer is called to fuse the second node features of the nodes in each relation subgraph in the first sample relation graph respectively to obtain the second subgraph features of each relation subgraph, and the second subgraph features of the relation subgraph to which each node in the first sample relation graph belongs are fused respectively to obtain the third node features of each node, including:
[0377] For each relation subgraph in the first sample relation graph, the next feature extraction layer is called to determine the similarity between the second node features of the nodes in the relation subgraph and the first subgraph features of the relation subgraph based on the second sample relation parameter, and the second subgraph features of the relation subgraph are obtained by fusing the second node features of the nodes in the relation subgraph as weights corresponding to the similarity of the nodes in the relation subgraph;
[0378] For each node in the first sample relation graph, the next feature extraction layer is called to determine the similarity between the first subgraph features of the relation subgraph to which the node belongs and the second node features of the node based on the second sample relation parameter, and the third node features of the node are obtained by fusing the second subgraph features of the relation subgraph to which the node belongs as weights corresponding to the similarity of the relation subgraph to which the node belongs.
[0379] In a possible implementation, the first feature extraction layer is called to determine the second sample relation parameter based on the first subgraph features and the second node features, including:
[0380] The cosine similarity between the second node features of each node in the first sample relation graph and the first subgraph features of each relation subgraph is obtained to obtain a plurality of cosine similarities;
[0381] The cosine similarity smaller than the first reference similarity in the plurality of cosine similarities is adjusted to a second reference similarity, and the second reference similarity represents the similarity between the second node features and the first subgraph features that are not similar.
[0382] The second sample relation parameter is generated based on the adjusted plurality of cosine similarities.
[0383] In a possible implementation, after the relation subgraph to which the node belongs is fused as weights corresponding to the similarity of the relation subgraph to which the node belongs to obtain the third node features of the node, the device further includes:
[0384] The next feature extraction layer is called to determine the third sample relation parameter based on the second subgraph features and the third node features, and the third sample relation parameter represents the similarity between the third node features of each node in the first sample relation graph and the second subgraph features of each relation subgraph.
[0385] In a possible implementation, the relation recognition model is trained based on the sample relation label and the predicted relation label, including:
[0386] obtain a last feature extraction layer output sample relationship parameter, the sample relationship parameter representing a similarity between a node feature of each node in the first sample relationship graph and a subgraph feature of each relationship subgraph;
[0387] determine a first loss value based on the sample relationship parameter, the first loss value representing a discrete degree of a similarity between node features of multiple pairs of adjacent nodes belonging to a same relationship subgraph;
[0388] determine a second loss value of the relationship identification model based on the sample relationship label and the predicted relationship label, the second loss value representing a similarity between the sample relationship label and the predicted relationship label;
[0389] train the relationship identification model based on a total loss value of the first loss value and the second loss value.
[0390] In a possible implementation, after the first feature extraction layer is invoked to fuse the first node features of the nodes in each relationship subgraph in the first sample relationship graph to obtain the first subgraph feature of each relationship subgraph, the apparatus further includes:
[0391] For the first subgraph feature of each relationship subgraph in the first sample relationship graph, the first feature extraction layer is invoked to determine at least one target subgraph feature similar to the first subgraph feature;
[0392] update the first subgraph feature based on the at least one target subgraph feature to obtain an updated first subgraph feature;
[0393] The target subgraph feature is a first subgraph feature of a relationship subgraph in the second sample relationship graph.
[0394] In a possible implementation, the updating of the first subgraph feature based on the at least one target subgraph feature to obtain the updated first subgraph feature includes:
[0395] The first feature extraction layer is invoked to select, based on a similarity between the first subgraph feature and each target subgraph feature in the at least one target subgraph feature, a reference number of target subgraph features from the at least one target subgraph feature, the similarity between the selected target subgraph features and the first subgraph feature being greater than the similarity between the remaining target subgraph features in the at least one target subgraph feature and the first subgraph feature;
[0396] The similarity between the selected target subgraph features and the first subgraph feature is taken as a weight to fuse the selected target subgraph features to obtain a fused feature, and a difference feature between the first subgraph feature and the fused feature is determined as the updated first subgraph feature.
[0397] In a possible implementation, after calling the next feature extraction layer to fuse the second node features of the nodes in each relation subgraph in the first sample relation graph respectively to obtain the second subgraph features of each relation subgraph, the apparatus further includes:
[0398] For the second subgraph features of each relation subgraph in the first sample relation graph, calling the next feature extraction layer to determine at least one target subgraph feature similar to the second subgraph features;
[0399] Updating the second subgraph features based on the at least one target subgraph feature to obtain updated second subgraph features;
[0400] The target subgraph features are the second subgraph features of the relation subgraphs in the second sample relation graph.
[0401] In a possible implementation, updating the second subgraph features based on the at least one target subgraph feature to obtain updated second subgraph features includes:
[0402] Calling the next feature extraction layer to select, based on the similarity between the second subgraph features and each of the at least one target subgraph feature, a reference number of target subgraph features from the at least one target subgraph feature, the similarity between the selected target subgraph features and the second subgraph features being greater than the similarity between the remaining target subgraph features in the at least one target subgraph feature and the second subgraph features;
[0403] Fusing the selected target subgraph features based on the similarity between the selected target subgraph features and the first subgraph features as weights to obtain fused features, and determining the difference features between the second subgraph features and the fused features as the updated second subgraph features.
[0404] In the embodiments of the present application, considering that the relationship between each two words in a text cannot completely represent the semantic information of the text, when representing the text by using a relation graph, for each word in the text, each associated word of the word is selected from the text, the word and the selected associated word form a word set, and the relation graph is generated based on the at least one formed word set. Since the relation graph represents the text in units of relation subgraphs, and each relation subgraph can represent the association relationship between each word in the word set corresponding to the relation subgraph, rather than being limited to only the association relationship between two words, the relation graph can completely represent the semantic information of the text, and text matching by using the relation graph can improve the accuracy of text matching.
[0405] It should be noted that the text matching apparatus provided in the above embodiments is only used for example to illustrate the division of the above functional modules when performing text matching, and in actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the computer device is divided into different functional modules to complete all or part of the functions described above. In addition, the text matching apparatus and the text matching method provided in the above embodiments belong to the same concept, and the specific implementation process is described in the method embodiments, which will not be repeated here.
[0406] The embodiments of the present application further provide a computer device, which comprises a processor and a memory, and the memory stores at least one computer program, which is loaded and executed by the processor to implement the operations performed in the text matching method of the above embodiments.
[0407] Optionally, the computer device is provided as a terminal. Figure 11 A structural block diagram of a terminal 1100 provided by an example embodiment of the present application is shown. The terminal 1100 can be a smart phone, a tablet computer, an MP3 (Moving Picture Experts Group Audio Layer III) player, an MP4 (Moving Picture Experts Group Audio Layer IV) player, a notebook computer or a desktop computer. The terminal 1100 can also be referred to as a user equipment, a portable terminal, a laptop terminal, a desktop terminal, or other names.
[0408] The terminal 1100 comprises a processor 1101 and a memory 1102.
[0409] The processor 1101 can include one or more processing cores, such as a 4-core processor, an 8-core processor, and the like. The processor 1101 can be implemented in at least one of a hardware form of a DSP (Digital Signal Processing), an FPGA (Field-Programmable Gate Array), a PLA (Programmable Logic Array). The processor 1101 can also include a main processor and a coprocessor, the main processor being a processor for processing data in an awake state, also known as a CPU (Central Processing Unit), and the coprocessor being a low-power processor for processing data in a standby state. In some embodiments, the processor 1101 can be integrated with a GPU (Graphics Processing Unit) for rendering and drawing content required to be displayed by the display screen. In some embodiments, the processor 1101 can also include an AI (Artificial Intelligence) processor for processing machine learning-related computing operations.
[0410] The memory 1102 can include one or more computer-readable storage media that can be non-transitory. The memory 1102 can also include a high-speed random access memory, and a nonvolatile memory such as one or more disk storage devices, flash storage devices. In some embodiments, the non-transitory computer-readable storage medium in the memory 1102 is used to store at least one computer program for being executed by the processor 1101 to implement the text matching method provided by the method embodiments in the present application.
[0411] In some embodiments, the terminal 1100 can also optionally include a peripheral device interface 1103 and at least one peripheral device. The processor 1101, the memory 1102, and the peripheral device interface 1103 can be connected through a bus or a signal line. Each peripheral device can be connected to the peripheral device interface 1103 through a bus, a signal line, or a circuit board. Specifically, the peripheral device includes at least one of a radio frequency circuit 1104, a display screen 1105, and a camera assembly 1106.
[0412] The peripheral interface 1103 can be used to connect at least one peripheral device related to I / O (Input / Output) to the processor 1101 and the memory 1102. In some embodiments, the processor 1101, the memory 1102 and the peripheral interface 1103 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 1101, the memory 1102 and the peripheral interface 1103 can be implemented on a separate chip or circuit board, and the present embodiment is not limited in this regard.
[0413] The radio frequency circuit 1104 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The display screen 1105 is used to display a UI (User Interface). The UI can include graphics, text, icons, video and any combination thereof. When the display screen 1105 is a touch display screen, the display screen 1105 also has the ability to collect touch signals on or above the surface of the display screen 1105. The touch signals can be input as control signals to the processor 1101 for processing. At this time, the display screen 1105 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, the display screen 1105 can be one, arranged on the front panel of the terminal 1100; in other embodiments, the display screen 1105 can be at least two, arranged on different surfaces of the terminal 1100 or in a folding design; in other embodiments, the display screen 1105 can be a flexible display screen, arranged on a curved surface or a folding surface of the terminal 1100. Even, the display screen 1105 can also be arranged in an irregular shape other than a rectangle, i.e. a special-shaped screen. The display screen 1105 can be made of LCD (Liquid Crystal Display), OLED (Organic Light-Emitting Diode) and other materials. The camera assembly 1106 is used to collect images or videos. Optionally, the camera assembly 1106 includes a front camera and a rear camera.
[0414] Those skilled in the art can understand that Figure 11 The structure shown in the figure does not constitute a limitation on the terminal 1100, and can include more or fewer components than shown, or combine certain components, or use different component arrangements.
[0415] Optionally, the computer device is provided as a server. Figure 12is a structural schematic diagram of a server provided by an embodiment of the present application. The server 1200 can have great differences due to different configurations or performances, and can include one or more processors (central processing units, CPUs) 1201 and one or more memories 1202. The memory 1202 stores at least one computer program, which is loaded and executed by the processor 1201 to implement the text matching method provided by each method embodiment described above. Of course, the server can also have a wired or wireless network interface, a keyboard, an input and output interface, and other components for implementing device functions, and the like, so as to perform input and output. The server can also include other components for implementing device functions, which are not described here.
[0416] An embodiment of the present application further provides a computer readable storage medium, which stores at least one computer program. The at least one computer program is loaded and executed by a processor to implement operations performed in the text matching method of the above embodiment.
[0417] An embodiment of the present application further provides a computer program product or a computer program. The computer program product or the computer program includes a computer program stored in a computer readable storage medium. A processor of a computer device reads the computer program from the computer readable storage medium, and the processor executes the computer program, so that the computer device performs operations performed in the text matching method in each optional implementation manner described above.
[0418] Those skilled in the art can understand that all or part of the steps of the above-mentioned embodiments can be completed by hardware, or by a program instructing related hardware to complete, and the program can be stored in a computer readable storage medium. The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk.
[0419] The above is only an optional embodiment of the present application, and is not used to limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method of text matching, characterized by, The method comprises: acquiring a first text; for each word in the first text, selecting each associated word of the word from the first text, and constructing a word set with the word and each selected associated word; generating a first relationship graph based on at least one constructed word set, the first relationship graph comprising at least one relationship subgraph, each relationship subgraph corresponding to a word set, each node in each relationship subgraph being used to represent a word in the corresponding word set, and each relationship subgraph being used to represent an association relationship between each word in the corresponding word set; calling a relationship identification model to determine a relationship label between the first relationship graph and a second relationship graph corresponding to a second text, the relationship label being used to represent a relationship between the first relationship graph and the second relationship graph, the relationship between the first relationship graph and the second relationship graph being matching or not matching; in response to the relationship label indicating that the first relationship graph matches the second relationship graph, determining the second text as a text matching the first text; the relationship identification model comprises a feature extraction submodel and a classification submodel; the feature extraction submodel comprises a plurality of feature extraction layers; the process of acquiring node features of each node in the first relationship graph comprises: calling a first feature extraction layer to acquire first node features of each node in the first relationship graph; calling the first feature extraction layer to respectively fuse first node features of nodes in each relationship subgraph in the first relationship graph to obtain first subgraph features of the each relationship subgraph, and respectively fuse first subgraph features of relationship subgraphs to which each node in the first relationship graph belongs to obtain second node features of the each node; calling a next feature extraction layer to respectively fuse second node features of nodes in each relationship subgraph in the first relationship graph to obtain second subgraph features of the each relationship subgraph, and respectively fuse second subgraph features of relationship subgraphs to which each node in the first relationship graph belongs to obtain third node features of the each node, until the node features of the each node output by a last feature extraction layer are obtained, and the node features of the each node output by the last feature extraction layer are determined as the node features of each node in the first relationship graph; wherein the node features of the node are features of a word represented by the node.
2. The method of claim 1, wherein, The process of, for each word in the first text, selecting each associated word of the word from the first text, and constructing a word set with the word and each selected associated word, comprises: determining a similarity between a first word vector of a first word and second word vectors of each second word, the first word being any word in the first text, and the second word being any word in the first text other than the first word; selecting a second word corresponding to each second word vector having a similarity greater than a reference threshold with the first word vector; constructing a word set with the first word and each selected second word.
3. The method of claim 1, wherein, The call relationship recognition model determines the relationship labels between the first relationship graph and the second relationship graph corresponding to the second text, including: The feature extraction sub-model is invoked to obtain the node features of each node in the first relation graph and the node features of each node in the second relation graph; The classification sub-model is invoked to obtain first relation graph features based on the node features of each node in the first relation graph, and second relation graph features based on the node features of each node in the second relation graph. Based on the features of the first relationship graph and the features of the second relationship graph, the relationship labels between the first relationship graph and the second relationship graph are determined.
4. The method of claim 3, wherein, The step of calling the classification sub-model to obtain first relationship graph features based on the node features of each node in the first relationship graph, and obtaining second relationship graph features based on the node features of each node in the second relationship graph, includes: The classification sub-model is invoked to obtain the average value of the node features of multiple nodes in the first relationship graph, and the average value is determined as the feature of the first relationship graph. The average value of the node features of multiple nodes in the second relationship graph is obtained, and the average value is determined as the feature of the second relationship graph.
5. The method of claim 1, wherein, The first feature extraction layer is invoked to fuse the first node features of each node in each subgraph of the first relation graph to obtain the first subgraph features of each relation graph. Then, the first subgraph features of the relation graph to which each node belongs in the first relation graph are fused to obtain the second node features of each node. Obtain the first relation parameter of the first relation graph. The first relation parameter represents the relationship between each node in the first relation graph and each relation subgraph. The relationship between each node in the first relation graph and each relation subgraph is that the node belongs to the relation subgraph or the node does not belong to the relation subgraph. For each relation subgraph in the first relation graph, the first feature extraction layer is invoked to determine the nodes in the relation subgraph based on the first relation parameters, and the first node features of the nodes in the relation subgraph are fused to obtain the first subgraph features of the relation subgraph. For each node in the first relational graph, the first feature extraction layer is invoked to determine the relational subgraph to which the node belongs based on the first relational parameters. The first subgraph features of the relational subgraph to which the node belongs are fused to obtain the second node features of the node.
6. The method of claim 5, wherein, After fusing the first subgraph features of the relational subgraph to which the node belongs to obtain the second node features, the method includes: The first feature extraction layer is invoked to determine a second relation parameter based on the first subgraph feature and the second node feature. The second relation parameter represents the similarity between the second node feature of each node in the first relation graph and the first subgraph feature of each relation subgraph. The next feature extraction layer is called to fuse the second node features of the nodes in each relation subgraph in the first relation graph respectively to obtain second subgraph features of each relation subgraph, and to fuse the second subgraph features of the relation subgraphs to which each node in the first relation graph belongs respectively to obtain third node features of each node, including: For each relation subgraph in the first relation graph, the next feature extraction layer is called to determine the similarity between the second node features of the nodes in the relation subgraph and the first subgraph features of the relation subgraph based on the second relation parameter, and to fuse the second node features of the nodes in the relation subgraph as weights to obtain the second subgraph features of the relation subgraph; For each node in the first relation graph, the next feature extraction layer is called to determine the similarity between the first subgraph features of the relation subgraph to which the node belongs and the second node features of the node based on the second relation parameter, and to fuse the second subgraph features of the relation subgraph to which the node belongs as weights to obtain the third node features of the node.
7. The method of claim 6, wherein, The first feature extraction layer is called to determine the second relation parameter based on the first subgraph features and the second node features, including: Obtaining the cosine similarity between the second node features of each node in the first relation graph and the first subgraph features of each relation subgraph to obtain a plurality of cosine similarities; Adjusting the cosine similarity smaller than the first reference similarity in the plurality of cosine similarities to a second reference similarity, the second reference similarity representing the similarity between the second node features and the first subgraph features that are not similar; Generating the second relation parameter based on the adjusted plurality of cosine similarities.
8. The method of claim 6, wherein, After the similarity of the relation subgraph to which the node belongs is taken as a weight to fuse the second subgraph features of the relation subgraph to which the node belongs to obtain the third node features of the node, the method further includes: The next feature extraction layer is called to determine the third relation parameter based on the second subgraph features and the third node features, the third relation parameter representing the similarity between the third node features of each node in the first relation graph and the second subgraph features of each relation subgraph.
9. The method of claim 1, wherein, After the next feature extraction layer is called to fuse the first node features of the nodes in each relation subgraph in the first relation graph respectively to obtain the first subgraph features of each relation subgraph, the method further includes: For the first subgraph features of each relation subgraph in the first relation graph, the first feature extraction layer is called to determine at least one target subgraph feature similar to the first subgraph features; Based on the at least one target subgraph feature, the first subgraph features are updated to obtain updated first subgraph features; The target subgraph features are the first subgraph features of the relation subgraphs in the second relation graph.
10. The method of claim 9, wherein, The updating the first subgraph feature based on the at least one target subgraph feature comprises: calling the first feature extraction layer, selecting a reference number of target subgraph features from the at least one target subgraph feature based on similarity between the first subgraph feature and each target subgraph feature in the at least one target subgraph feature, the similarity between the selected target subgraph features and the first subgraph feature being greater than the similarity between the remaining target subgraph features in the at least one target subgraph feature and the first subgraph feature; fusing the selected target subgraph features by taking the similarity between the selected target subgraph features and the first subgraph feature as a weight to obtain a fusion feature, and determining a difference feature between the first subgraph feature and the fusion feature as the updated first subgraph feature.
11. A text matching apparatus, characterized by comprising: The device comprises: a text acquisition module configured to acquire a first text, the first text comprising at least three words; a set formation module configured to, for each word in the first text, select each associated word of the word from the first text, and form a word set comprising the word and each selected associated word; a relationship graph generation module configured to generate a first relationship graph based on the at least one formed word set, the first relationship graph comprising at least one relationship subgraph, each relationship subgraph corresponding to a word set, each node in the each relationship subgraph being configured to represent a word in the corresponding word set, and the each relationship subgraph being configured to represent an association relationship between each word in the corresponding word set; a text matching module configured to perform text matching based on the first relationship graph; the text matching module comprises: a label determination submodule configured to call a relationship identification model to determine a relationship label between the first relationship graph and a second relationship graph corresponding to a second text, the relationship label being configured to represent a relationship between the first relationship graph and the second relationship graph, the relationship between the first relationship graph and the second relationship graph being matching or not matching; a text determination submodule configured to, in response to the relationship label representing that the first relationship graph matches the second relationship graph, determine the second text as a text matching the first text; the relationship identification model comprises a feature extraction submodel and a classification submodel, and the feature extraction submodel comprises a plurality of feature extraction layers; the label determination submodule comprises: a node feature acquisition unit configured to call the feature extraction submodel to acquire a node feature of each node in the first relationship graph and a node feature of each node in the second relationship graph, the node feature of the node being a feature of a word represented by the node; the node feature acquisition unit comprises: a first feature acquisition subunit configured to call a first feature extraction layer to acquire a first node feature of each node in the first relationship graph; a second feature acquisition subunit configured to call a second feature extraction layer to acquire a second node feature of each node in the first relationship graph; and a third feature acquisition subunit configured to call a third feature extraction layer to acquire a third node feature of each node in the first relationship graph. The second feature acquisition subunit is configured to call the first feature extraction layer, fuse the first node features of the nodes in each of the relationship subgraphs in the first relationship graph respectively, obtain first subgraph features of each of the relationship subgraphs, fuse the first subgraph features of the relationship subgraphs to which each of the nodes in the first relationship graph belongs respectively, and obtain second node features of each of the nodes. The third feature acquisition subunit is configured to call the next feature extraction layer, fuse the second node features of the nodes in each of the relationship subgraphs in the first relationship graph respectively, obtain second subgraph features of each of the relationship subgraphs, fuse the second subgraph features of the relationship subgraphs to which each of the nodes in the first relationship graph belongs respectively, obtain third node features of each of the nodes, and determine the node features of each of the nodes output by the last feature extraction layer as the node features of each of the nodes in the first relationship graph.
12. A computer device, comprising: The computer device comprises a processor and a memory, and the memory stores at least one computer program, which is loaded and executed by the processor to implement the operations performed by the text matching method according to any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that, The storage medium stores at least one computer program, which is loaded and executed by the processor to implement the operations performed by the text matching method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Semantic matching method, device and equipment and storage medium
CN111274822A
Text sentiment analysis method based on graph attention network
CN112560432A