A training sample generation method and device, a storage medium, and an electronic device
By constructing a binary tree and performing random number queries during graph neural network training to generate training samples, the problem of low sampling efficiency in existing technologies is solved, and efficient training sample generation and network training are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-25
- Publication Date
- 2026-04-14
AI Technical Summary
How to efficiently generate subgraphs as training samples, especially in graph neural network training, is a challenge where existing techniques struggle to effectively utilize node and edge information in graphs for efficient sampling.
A binary tree is constructed using a preset partitioning strategy. Random numbers are generated based on the weights of the edges. The matched leaf nodes are queried in the binary tree, and the sampled edges are deleted. The binary tree is then updated until the sampling termination condition is met. The subgraph consisting of the sampled nodes, sampled edges, and connected nodes is used as training samples.
It improves sampling efficiency, avoids duplicate sampling, and can quickly generate training samples, thus improving the efficiency of graph neural network training.
Smart Images

Figure CN115840910B_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of computer technology, and in particular to a method, apparatus, storage medium, and electronic device for generating training samples. Background Technology
[0002] With the development of technology, machine learning has been widely applied. As machine learning has progressed, machine learning models have become increasingly prevalent, especially graph neural networks.
[0003] There are many types of samples for training graph neural networks. One such sample is a subgraph consisting of some nodes and the edges between them. Currently, many applications and scenarios can be transformed into graphs. Depending on the application and scenario, graphs can be of various types, such as static graphs and time-series graphs. Nodes in a graph contain information about the actual application, and edges contain information about the relationships between nodes. When it is necessary to obtain information about an unknown node in the graph, the information of that node can be predicted based on its relationships with other nodes.
[0004] For example, in a citation network, each paper can be viewed as a node in a graph, and citation relationships exist between these papers. These citation relationships are represented by the edges connecting the nodes in the graph. To determine the category of a paper in a citation network, its category can be predicted based on the other papers it cites.
[0005] Therefore, how to efficiently generate subgraphs as training samples is an urgent problem to be solved. Summary of the Invention
[0006] This specification provides a method, apparatus, storage medium, and electronic device for generating training samples, in order to partially solve the aforementioned problems existing in the prior art.
[0007] The following technical solution is adopted in this specification:
[0008] This specification provides a method for generating training samples, including:
[0009] Obtain the nodes in the graph as sampling nodes, determine the edges connected to the sampling nodes, and determine the set of edges to be sampled composed of the edges.
[0010] A binary tree is constructed using a preset partitioning strategy, with the set of edges to be sampled as the root node and each edge in the set of edges to be sampled as a leaf node.
[0011] Based on the weights of each edge, a random number is generated. Based on the weights of the edges contained in each node of the binary tree and the random number, the leaf node hit by the random number is determined, and the edges contained in the leaf node are used as sampling edges.
[0012] The sampling edge is deleted from the binary tree to update the binary tree, and a new random number is generated. The sampling edge is determined based on the updated binary tree and the new random number until the first sampling end condition is met. The subgraph formed by the sampling node, the sampling edge and the node connected to the sampling edge in the graph is used as the generated training sample. The training sample is used to input the graph neural network to be trained to train the graph neural network.
[0013] Optionally, a preset partitioning strategy is adopted to construct a binary tree with the set of edges to be sampled as the root node and each edge in the set of edges to be sampled as a leaf node, specifically including:
[0014] The set of edges to be sampled is taken as the parent node;
[0015] According to the preset partitioning strategy, the edge set to be sampled is divided into two sub-edge sets, which serve as the two child nodes of the parent node;
[0016] For each child node, the child node is re-established as the parent node, and the newly determined parent node is further divided until each divided child node contains only one edge.
[0017] Optionally, generating random numbers includes:
[0018] Determine the minimum weight of the edges in the set of edges to be sampled, and the sum of the weights of the edges in the set of edges to be sampled;
[0019] Random numbers are generated within the range from the minimum weight to the sum of the weights.
[0020] Optionally, the leaf node hit by the random number is determined based on the weight of the edges contained in each node of the binary tree and the random number, specifically including:
[0021] The root node in the binary tree is taken as the node to be sampled.
[0022] For each child node of the node to be sampled, the sum of the weights of the edges contained in that child node is determined as the node weight of that child node;
[0023] Determine the smaller weight among the node weights of each child node of the node to be sampled;
[0024] Determine whether the random number is not greater than the smaller weight;
[0025] If so, the child node corresponding to the smaller weight is determined as the child node hit by the random number; otherwise, the child node corresponding to the larger weight is determined as the child node hit by the random number, and the difference between the random number and the smaller weight is re-determined as the random number.
[0026] The child node hit by the random number is re-selected as the node to be sampled until the random number hits a leaf node.
[0027] Optionally, the sampling edge is deleted from the binary tree to update the binary tree, specifically including:
[0028] Nodes in the binary tree that contain the sampled edge are identified as update nodes;
[0029] The sampled edges contained in the updated node are deleted to update the binary tree.
[0030] Optionally, before deleting the sampling edge in the binary tree, the method further includes:
[0031] It is determined that the currently obtained sampling edge does not satisfy the second sampling termination condition;
[0032] If the currently obtained sampling edge satisfies the second sampling termination condition, then the method further includes:
[0033] For each sampling edge, the node connected to the sampling edge is determined in the graph, and the node is re-used as a sampling node. Sampling edges are then determined based on the re-determined sampling node until the first sampling termination condition is met.
[0034] Optionally, before obtaining the nodes in the graph, the method further includes:
[0035] Generate a graph using each sample user as a node and the relationships between each sample user as edges;
[0036] After training the graph neural network to be trained, the method further includes:
[0037] A topology graph corresponding to each user to be predicted is generated, with each user to be predicted as a node and the relationship between each user to be predicted as an edge.
[0038] For at least one user to be predicted, the subgraph corresponding to the user to be predicted is determined based on the node corresponding to the user in the topology graph.
[0039] The subgraph corresponding to the user to be predicted is input into the trained graph neural network to obtain the result of whether the user to be predicted is the target user, as output by the trained graph neural network.
[0040] This specification provides a training sample generation apparatus, comprising:
[0041] The acquisition module is used to acquire nodes in the graph as sampling nodes, determine the edges connected to the sampling nodes, and determine the set of edges to be sampled formed by the edges.
[0042] A creation module is used to construct a binary tree with the set of edges to be sampled as the root node and each edge in the set of edges to be sampled as a leaf node, using a preset partitioning strategy.
[0043] The sampling module is used to generate random numbers based on the weights of each edge, and determine the leaf node hit by the random number based on the weights of the edges contained in each node of the binary tree and the random number. The edges contained in the leaf node are used as sampling edges. The sampling edges are deleted from the binary tree to update the binary tree, and random numbers are regenerated. The sampling edges are determined based on the updated binary tree and the regenerated random numbers until the first sampling end condition is met. The subgraph formed by the sampling nodes, sampling edges and nodes connected to the sampling edges in the graph is used as the generated training samples. The training samples are used as input to the graph neural network to be trained to train the graph neural network.
[0044] Optionally, the creation module is specifically used to: take the edge set to be sampled as the parent node; divide the edge set to be sampled into two sub-edge sets according to a preset partitioning strategy, which serve as the two child nodes of the parent node; and for each child node, re-take the child node as the parent node, so as to continue to partition the newly determined parent node until each partitioned child node contains only one edge.
[0045] Optionally, the sampling module is specifically used to determine the minimum weight of the edges in the edge set to be sampled, and the sum of the weights of the edges in the edge set to be sampled; and to generate random numbers within the range of the minimum weight to the sum of the weights.
[0046] Optionally, the sampling module is specifically configured to: take the root node of the binary tree as the node to be sampled; for each child node of the node to be sampled, determine the sum of the weights of the edges contained in the child node as the node weight of the child node; determine the smaller weight among the node weights of each child node of the node to be sampled; determine whether the random number is not greater than the smaller weight; if so, determine the child node corresponding to the smaller weight as the child node hit by the random number; otherwise, determine the child node corresponding to the larger weight as the child node hit by the random number, and re-determine the difference between the random number and the smaller weight as the random number; and re-take the child node hit by the random number as the node to be sampled until the random number hits a leaf node.
[0047] Optionally, the sampling module is specifically used to: determine the nodes in the binary tree that contain the sampling edge as update nodes; and delete the sampling edge contained in the update node to update the binary tree.
[0048] Optionally, before deleting the sampling edge in the binary tree, the sampling module is further configured to determine that the currently obtained sampling edge does not satisfy the second sampling termination condition;
[0049] If the currently obtained sampling edge satisfies the second sampling end condition, the sampling module is further configured to, for each sampling edge, determine the node connected to the sampling edge in the graph, re-use the node as a sampling node, and continue to determine sampling edges based on the re-determined sampling node until the first sampling end condition is met.
[0050] Optionally, before acquiring the nodes in the graph, the acquisition module is further configured to generate a graph with each sample user as a node and the relationship between each sample user as an edge;
[0051] After training the graph neural network to be trained, the sampling module is further configured to generate a topology graph corresponding to each user to be predicted, using each user to be predicted as a node and the relationship between each user to be predicted as an edge; for at least one user to be predicted, a subgraph corresponding to the user to be predicted is determined based on the node corresponding to the user to be predicted in the topology graph; the subgraph corresponding to the user to be predicted is input into the trained graph neural network to obtain the result of whether the user to be predicted is the target user output by the trained graph neural network.
[0052] This specification provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method for generating training samples.
[0053] This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the above-described method for generating training samples.
[0054] The above-mentioned technical solutions adopted in this specification can achieve the following beneficial effects:
[0055] The training sample generation method provided in this specification employs a preset partitioning strategy to construct a binary tree with the set of edges to be sampled as the root node and each edge as a leaf node. Based on the generated random number and the weight of each node in the binary tree, each edge is sampled. After obtaining the sampled edges, the sampled edges are deleted from the binary tree to update the binary tree. Then, sampling is performed again based on the updated binary tree until the first sampling termination condition is met. The subgraph consisting of the sampled nodes, sampled edges, and nodes connected to the sampled edges is used as the generated training samples. The training samples are input into the graph neural network to be trained for training.
[0056] As can be seen from the above method, when sampling each edge connected to the sampling node, this method adopts a preset partitioning strategy to construct a binary tree with the set of edges to be sampled as the root node and each edge as the leaf node. Based on the generated random number, the matching leaf node is queried in the binary tree, which improves the sampling efficiency. Moreover, the sampled edges are deleted from the binary tree to avoid the problem of repeated sampling, thus improving the sampling efficiency and enabling efficient generation of subgraphs as training samples. Attached Figure Description
[0057] The accompanying drawings, which are included to provide a further understanding of this specification and form part of this specification, illustrate exemplary embodiments and their descriptions, serving to explain this specification and do not constitute an undue limitation thereof.
[0058] In the picture:
[0059] Figure 1 This is a flowchart illustrating one method for generating training samples in this specification.
[0060] Figure 2 This is a diagram of a training sample being generated in this specification;
[0061] Figure 3 This is a schematic diagram of a binary tree used in this specification;
[0062] Figure 4 This is a schematic diagram of the sub-graph sample generated in this specification;
[0063] Figure 5 This is a schematic diagram of a training sample generation device provided in this specification;
[0064] Figure 6 The corresponding information provided in this specification Figure 1 A schematic diagram of an electronic device. Detailed Implementation
[0065] To make the objectives, technical solutions, and advantages of this specification clearer, the technical solutions of this specification will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this specification, and not all of them. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this specification.
[0066] The embodiments of this specification provide a method, apparatus, storage medium, and electronic device for generating training samples. The technical solutions provided by the embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0067] Figure 1 This is a flowchart illustrating a method for generating training samples as described in this specification, specifically including the following steps:
[0068] S100: Obtain the nodes in the graph as sampling nodes, determine the edges connected to the sampling nodes, and determine the set of edges to be sampled composed of the edges.
[0069] When training a graph neural network, a subgraph consisting of some nodes and the edges between nodes can be used as training samples. The graph can be a static graph or a temporal graph; this specification does not specify a particular type. Graph sampling can be done through node sampling and hierarchical sampling, etc. For ease of explanation, this specification uses node sampling as an example. When performing node sampling on a graph, multiple samplings are required. Each time, the edges connected to the sampling nodes in the graph are sampled, and multiple edges connected to the sampling nodes are sampled at once. The nodes connected to the sampled edges are used as the sampling nodes for the next sampling. Finally, the subgraph consisting of the sampled nodes, sampled edges, and nodes connected to the sampled edges is output as the training samples.
[0070] Based on this, in this specification, the device used to generate training samples determines the nodes in the graph as sampling nodes, determines the edges connected to the sampling nodes, and determines the set of edges to be sampled. The device used to generate training samples can be a server for training a graph neural network, or a device such as a mobile phone or personal computer (PC) capable of executing the scheme described in this specification. For ease of explanation, the following description uses a server as the execution entity.
[0071] Specifically, the server will use the nodes identified in the graph as sampling nodes, determine the edges connected to the sampling nodes, and determine the set of edges to be sampled. The sampling nodes can be obtained from the graph according to preset rules, or they can be obtained through any other method. For example, Figure 2This specification describes a graph that is generating training samples. The graph contains nodes 1 to 10. The edges connecting each pair of nodes contain weights. For example, the weight of the edge from node 1 to node 2 is 2. Assuming that the sampling node obtained from the graph is node 1, the node number connected to node 1 is used as the number of the connecting edge. That is, the nodes connected to node 1 are node 2, node 3, node 4, and node 5. In other words, the edges connected to the sampling node are edge 2, edge 3, edge 4, and edge 5. The set consisting of edge 2, edge 3, edge 4, and edge 5 is used as the set of edges to be sampled.
[0072] S102: Using a preset partitioning strategy, construct a binary tree with the set of edges to be sampled as the root node and each edge in the set of edges to be sampled as a leaf node.
[0073] The server uses a preset partitioning strategy to construct a binary tree with the set of edges to be sampled as the root node and each edge in the set of edges to be sampled as a leaf node. The preset partitioning strategy can be to divide the set of edges to be sampled into subsets with the same number of edges. If the number of edges in the set of edges to be sampled cannot be evenly distributed, the subsets will be partitioned according to the rule that minimizes the difference in the number of edges in the subsets of the set of edges to be sampled.
[0074] Specifically, the server uses the set of edges to be sampled as the parent node. Based on a preset partitioning strategy, it divides the set of edges into two child sets, which are then the two child nodes of the parent node. For each child node, the child node is re-established as the parent node, and this process continues until each child node contains only one edge. When dividing the set of edges to be sampled into two child sets, the partitioning can be done directly according to the preset partitioning strategy, or the edges in the set can be sorted according to their weights from largest to smallest or smallest to largest, and then the resulting sequence can be partitioned according to the preset partitioning strategy.
[0075] Continuing with the previous example, when... Figure 2 When node 1 in the sample is used as the sampling node, such as Figure 3As shown, the server uses the set of edges to be sampled (edges 2, 3, 4, and 5) as parent node A. According to the preset partitioning strategy, since the set of edges to be sampled contains 4 edges, it can directly divide the set into two child sets, each containing two edges, as the two child nodes of parent node A: child node B and child node C. Assuming child node B contains edges 2 and 3, and child node C contains edges 4 and 5, for each child node, the child node is re-designated as the parent node to continue partitioning until each partitioned child node contains only one edge. For example, for child node B, child node B is re-designated as parent node B, and partitioning continues based on the re-designated parent node B, resulting in two child nodes of parent node B: child node D and child node E. At this point, child node D and child node E each contain only one edge. The same method is used to partition child node C, resulting in two child nodes of child node C: child node F and child node H. The completed binary tree is shown below. Figure 3 As shown. Figure 3 This is a schematic diagram of a binary tree in this specification. The binary tree in the diagram is a binary tree with the set of edges to be sampled as the root node A (i.e., parent node A) and each edge (i.e. edge 2, edge 3, edge 4 and edge 5) in the set of edges to be sampled as a leaf node (i.e. child node D, child node E, child node F and child node H).
[0076] S104: Generate a random number based on the weight of each edge, and determine the leaf node hit by the random number based on the weight of the edge contained in each node of the binary tree and the random number, and use the edge contained in the leaf node as the sampling edge.
[0077] The server generates a random number based on the weights of each edge, and determines the leaf node hit by the random number based on the weights of the edges contained in each node of the binary tree constructed in step S102 and the random number. The edges contained in the hit leaf node are then used as sampling edges. Specifically, the server determines the minimum weight of the edges in the set of edges to be sampled and the sum of the weights of the edges in the set of edges to be sampled, and generates a random number within the range of the minimum weight to the sum of the weights. Take the root node of the binary tree as the node to be sampled. For each child node of the node to be sampled, determine the sum of the weights of the edges contained in that child node, and use this sum as the node weight of that child node. Determine the smaller weight among the node weights of each child node of the node to be sampled. Check if the random number is not greater than the smaller weight. If it is not greater, then take the child node corresponding to the smaller weight as the child node hit by the random number. Otherwise, take the child node corresponding to the larger weight as the child node hit by the random number, and use the difference between the random number and the smaller weight as a new random number. Take the child node hit by the random number as the node to be sampled again, until the random number hits a leaf node. Then take the edges contained in the leaf node as the sampling edges.
[0078] Continuing with the previous example, the server determines the minimum weight of the edges in the set of edges to be sampled (i.e., edge 2, edge 3, edge 4, and edge 5), which is the weight of edge 2, which is 2. Then, it determines the sum of the weights of the edges in the set of edges to be sampled, which is the sum of the weights of edge 2, edge 3, edge 4, and edge 5, which is 14. A random number is generated within the range of 2 to 14. Let's assume the generated random number is 6. The root node A in the binary tree is taken as the node to be sampled. For each child node of the node to be sampled, the sum of the weights of the edges contained in that child node is taken as the node weight of that child node. For example, the node weight of child node B is the sum of the weights of edge 2 and edge 3 contained in it, which is 5. Determine the smaller weight among the node weights of each child node of the node to be sampled. Since the node weight of child node C is 9, the smaller weight is 5. Check if the random number 6 is not greater than the smaller weight 5. Obviously, 6 is greater than 5. Take the child node C corresponding to the larger weight as the child node hit by the random number. Take the difference 1 between the random number 6 and the smaller weight 5 as the random number again. Take the child node C hit by the random number again as the node to be sampled. Continue sampling until the random number hits a leaf node. The smaller weight between the child nodes F and H of child node C is the node weight 4 of child node F. The new random number 1 is less than the smaller weight 4. Take the child node F corresponding to the smaller weight 4 directly as the child node hit by the random number. At the same time, child node F is a leaf node. Take the edge 4 contained in the leaf node (i.e., child node F) directly as the sampling edge.
[0079] S106: Delete the sampling edge in the binary tree to update the binary tree, and regenerate random numbers. Continue to determine sampling edges based on the updated binary tree and the regenerated random numbers until the first sampling end condition is met. Then, use the subgraph formed by the sampling nodes, the sampling edges, and the nodes connected to the sampling edges in the graph as the generated training samples. The training samples are used to input the graph neural network to be trained to train the graph neural network.
[0080] After obtaining the sampled edges, the server deletes the sampled edges in the binary tree to update the binary tree and regenerates random numbers. Based on the updated binary tree and the regenerated random numbers, it continues to determine sampled edges until the first sampling termination condition is met. Then, the subgraph consisting of the sampled nodes, sampled edges, and nodes connected to the sampled edges in the graph is used as the generated training samples. The training samples are used as input to the graph neural network to be trained to train the graph neural network.
[0081] Specifically, after obtaining the sampled edge, before deleting it from the binary tree, the server needs to determine whether the currently obtained sampled edge does not meet the second sampling termination condition. If so, the node containing the sampled edge in the binary tree is designated as the update node, the sampled edge contained in the update node is deleted, and the difference between the node weight of the update node and the weight of the sampled edge is used as the weight of the update node to update the binary tree. Then, a new random number is generated, and the sampled edge is determined again based on the updated binary tree and the newly generated random number. That is, step S104 is repeated until the second sampling termination condition is met. The second sampling termination condition can be that the number of sampled nodes has reached a preset second number, where the second number is the number of sampled neighbor nodes among the sampled node's neighbor nodes.
[0082] When the second sampling termination condition is met, for each sampling edge, the node connected to that sampling edge is determined in the graph, and that node is re-determined as a sampling node. Sampling edges are then determined based on the newly determined sampling nodes until the first sampling termination condition is met, i.e., steps S100 to S106 are repeated. Afterwards, the subgraph formed by the sampling nodes, sampling edges, and nodes connected to the sampling edges in the graph is used as the generated training samples. These training samples are input into the graph neural network to be trained. The first sampling termination condition can be either that no new sampling edges can be sampled, or that the number of sampled nodes has reached a preset first number. The first number is the total number of all sampled nodes in the graph from the sampling node up to its Nth-order neighbor, and this first number is greater than the aforementioned second number, where N is a positive integer.
[0083] Continuing with the previous example, the server obtains edge 4, and the corresponding sampling node is node 4. Assume the preset second quantity is 2, and the number of neighboring nodes sampled among the current sampling node's neighboring nodes is 1, which does not meet the second sampling termination condition. The nodes in the binary tree that contain the sampled edge are taken as update nodes, that is, the root node A, child node C, and child node F are taken as update nodes. The sampled edge contained in the update node is deleted. For example, after deleting the sampled edge, the child node C only contains edge 5. The difference between the node weight of the update node and the weight 4 of the sampled edge (i.e., edge 4) is used as the weight of the update node again. That is, the node weight of the root node A is updated to 10, the node weight of the child node C is updated to 5, and the child node F is a leaf node that only contains edge 4. After the update, this child node no longer exists in the binary tree. Regenerate random numbers, and continue to determine sampling edges based on the updated binary tree and the regenerated random numbers. That is, repeat step S104 until the second sampling end condition is met. That is, when the number of sampling nodes corresponding to the sampling edge has reached the preset second number 2, the second sampling end condition is met, the current sampling is stopped, and the next sampling is performed.
[0084] Assuming the sampling edges are edges 3 and 4, the nodes connected to these edges in the graph are determined, namely nodes 3 and 4. For each node, it is re-sampled as a sampling node for the next sampling, i.e., steps S100 to S106 are repeated until the first sampling termination condition is met. Assuming the preset first number is 7, sampling ends when the total number of sampled nodes in the graph reaches 7. The subgraph formed by the sampling nodes, sampling edges, and nodes connected to the sampling edges in the graph is used as the generated training samples. The training samples are used as input to the graph neural network to be trained. Assuming the sampling edges obtained by sampling node 3 are edges 6 and 9, and the nodes connected to them are nodes 6 and 9 respectively, and the sampling edges obtained by sampling node 4 are edges 7 and 8, and the nodes connected to them are nodes 7 and 8 respectively, the subgraph formed by nodes 1, 3, 4, 6, 9, 7, and 8, and the sampling edges is as follows. Figure 4 As shown.
[0085] Subgraphs are obtained by sampling the graph using the method described above. These subgraphs, consisting of sampled nodes, sampled edges, and nodes connected to the sampled edges, are used as training samples. These training samples are then input into the graph neural network to be trained. Specifically, subgraph samples and their labels are obtained. The graph neural network to be trained is designed to determine the category of nodes with unknown categories in the graph. The subgraph samples consist of a subset of nodes and the edges between them, and the labels on the subgraph samples indicate the categories to which the nodes belong. The subgraph samples are then input into the graph neural network to be trained, yielding its output category. The training objective is to minimize the difference between the output category of the graph neural network and the labels on the subgraph samples.
[0086] Continuing with the previous example, such as Figure 4 As shown, Figure 4 This is a schematic diagram of the generated subgraph samples. The subgraph is used as the generated training sample, i.e., the subgraph sample. The category corresponding to the subgraph sample is used as the label of the subgraph sample. Assume... Figure 2 If the graph represents the citation relationships between papers in the citation network, then the subgraph sample represents the citation relationship between the paper represented by node 1 and other papers (i.e., nodes 3, 4, 6, 9, 7, and 8). Therefore, the category corresponding to the subgraph sample is the category corresponding to node 1, such as literature. Thus, the subgraph sample is labeled as literature. The subgraph sample is input into the graph neural network to be trained to obtain the output category of the graph neural network. The training objective is to minimize the difference between the output category of the graph neural network to be trained and the label of the subgraph sample. The graph neural network to be trained is then trained.
[0087] In step S106, if the graph sampling uses subgraph sampling, after the server obtains the sampling edge, before deleting the sampling edge in the binary tree, it needs to determine whether the currently obtained sampling edge does not meet the second sampling termination condition. If so, the node in the binary tree that contains the sampling edge is taken as the update node, the sampling edge contained in the update node is deleted, and the difference between the node weight of the update node and the weight of the sampling edge, plus the weight of the neighboring node of the node connected to the sampling edge, is used as the weight of the update node again to update the binary tree.
[0088] As can be seen from the above method, when generating training samples on the graph, this method samples nodes on the graph to obtain subgraphs as training samples. During sampling, a binary tree is constructed using a preset partitioning strategy. A query is performed in the binary tree based on the generated random number until a leaf node containing an edge is found. The edge contained therein is taken as a sampling edge, and the sampled edge is deleted from the binary tree to update the binary tree. Sampling is then performed again based on the updated binary tree until the first sampling termination condition is met. The subgraph consisting of the sampled nodes, sampled edges, and nodes connected to the sampled edges is used as the generated training samples. The training samples are input into the graph neural network to be trained. Sampling through a binary tree allows for quick finding of leaf nodes where the random number hits, improving sampling efficiency. Furthermore, after obtaining the sampled edge, deleting the sampled edge from the binary tree avoids the problem of duplicate sampling, resulting in fast training sample generation and efficient generation of subgraphs as training samples.
[0089] In this specification, before obtaining the nodes in the graph, the server can also generate a graph using each sample user as a node and the relationships between the sample users as edges. These relationships can be payment relationships, kinship relationships, or friend relationships, etc. After generating the graph, the server samples the graph to obtain subgraphs as training samples, and then trains the graph neural network to be trained. The specific process is as described in steps S100 to S106 above, and will not be repeated here.
[0090] After training the graph neural network (GNN), the server generates a topology graph for each user to be predicted, using each user as a node and the relationships between them as edges. Then, for at least one user, based on the node corresponding to that user in the topology graph, a subgraph corresponding to that user is determined. This subgraph is then input into the trained GNN to obtain the output of the trained GNN indicating whether the user is a target user. A target user can be a risky user or a user meeting certain conditions. The specific conditions are determined based on the specific needs and are not specifically limited here. For example, for an advertising company, target users are those who can be recommended ads. Therefore, the subgraph corresponding to the user to be predicted can be input into the trained GNN. Based on the output of the trained GNN indicating whether the user is a target user, if the user is a target user, an ad is recommended to the target user; otherwise, no ad is recommended.
[0091] For example, suppose Figure 2 The server generates a topology graph for each user to be predicted, with each user as a node and the relationships between them as edges. Figure 2In the graph, nodes 1 through 10 represent users 1 through 10 to be tested. For each user 1 through 10, the subgraph corresponding to that user is determined based on the node corresponding to that user in the topology graph. For example, based on node 1 corresponding to user 1 in the topology graph, the subgraph corresponding to user 1 is determined as follows: Figure 4 As shown, the subgraph corresponding to the user to be tested 1 is input into the trained graph neural network to obtain the result of whether the user to be predicted is the target user.
[0092] The above describes one or more embodiments of the training sample generation method provided in this specification. Based on the same idea, this specification also provides a corresponding training sample generation apparatus, such as... Figure 5 As shown.
[0093] Figure 5 This specification provides a schematic diagram of a training sample generation device, which specifically includes:
[0094] The acquisition module 200 is used to acquire nodes in the graph as sampling nodes, determine the edges connected to the sampling nodes, and determine the set of edges to be sampled composed of the edges.
[0095] A creation module 202 is used to construct a binary tree with the set of edges to be sampled as the root node and each edge in the set of edges to be sampled as a leaf node, using a preset partitioning strategy.
[0096] The sampling module 204 is used to generate random numbers based on the weights of each edge, and determine the leaf node hit by the random number based on the weights of the edges contained in each node of the binary tree and the random number. The edges contained in the leaf node are used as sampling edges. The sampling edges are deleted in the binary tree to update the binary tree, and random numbers are regenerated. The sampling edges are determined based on the updated binary tree and the regenerated random numbers until the first sampling end condition is met. The subgraph formed by the sampling nodes, the sampling edges and the nodes connected to the sampling edges in the graph is used as the generated training samples. The training samples are used as input to the graph neural network to be trained to train the graph neural network.
[0097] Optionally, the creation module 202 is specifically used to: take the edge set to be sampled as the parent node; divide the edge set to be sampled into two sub-edge sets according to a preset partitioning strategy, which serve as the two child nodes of the parent node; and for each child node, re-take the child node as the parent node, so as to continue to partition the newly determined parent node until each partitioned child node contains only one edge.
[0098] Optionally, the sampling module 204 is specifically used to determine the minimum weight of the edges in the edge set to be sampled, and the sum of the weights of the edges in the edge set to be sampled; and to generate random numbers within the range of the minimum weight to the sum of the weights.
[0099] Optionally, the sampling module 204 is specifically configured to: take the root node in the binary tree as the node to be sampled; for each child node of the node to be sampled, determine the sum of the weights of the edges contained in the child node as the node weight of the child node; determine the smaller weight among the node weights of each child node of the node to be sampled; determine whether the random number is not greater than the smaller weight; if so, determine the child node corresponding to the smaller weight as the child node hit by the random number; otherwise, determine the child node corresponding to the larger weight as the child node hit by the random number, and re-determine the difference between the random number and the smaller weight as the random number; and re-take the child node hit by the random number as the node to be sampled until the random number hits a leaf node.
[0100] Optionally, the sampling module 204 is specifically used to: determine the nodes in the binary tree that contain the sampling edge as update nodes; and delete the sampling edge contained in the update node to update the binary tree.
[0101] Optionally, before deleting the sampling edge in the binary tree, the sampling module 204 is further configured to determine that the currently obtained sampling edge does not satisfy the second sampling end condition;
[0102] If the currently obtained sampling edge satisfies the second sampling end condition, the sampling module 204 is further configured to, for each sampling edge, determine the node connected to the sampling edge in the graph, re-use the node as a sampling node, and continue to determine sampling edges based on the re-determined sampling node until the first sampling end condition is met.
[0103] Optionally, before acquiring the nodes in the graph, the acquisition module 200 is further configured to generate a graph with each sample user as a node and the relationship between each sample user as an edge;
[0104] After training the graph neural network to be trained, the sampling module 204 is further configured to generate a topology graph corresponding to each user to be predicted, using each user to be predicted as a node and the relationship between each user to be predicted as an edge; for at least one user to be predicted, determine the subgraph corresponding to the user to be predicted based on the node corresponding to the user to be predicted in the topology graph; input the subgraph corresponding to the user to be predicted into the trained graph neural network to obtain the result of whether the user to be predicted is the target user output by the trained graph neural network.
[0105] This specification also provides a computer-readable storage medium storing a computer program that can be used to execute the above-described... Figure 1 The method for generating training samples is shown.
[0106] This instruction manual also provides Figure 6 The diagram shows a schematic structural representation of the electronic device. Figure 6 At the hardware level, the electronic device includes a processor, internal bus, network interface, memory, and non-volatile memory, and may also include other hardware required for the business operations. The processor reads the corresponding computer program from the non-volatile memory into memory and then runs it to achieve the above-mentioned functions. Figure 1 The method for generating training samples is shown. Of course, in addition to software implementation, this specification does not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. In other words, the execution subject of the following processing flow is not limited to individual logic units, but can also be hardware or logic devices.
[0107] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.
[0108] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, ASICs, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.
[0109] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, a computer can be, for example, a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any combination of these devices.
[0110] For ease of description, the above devices are described in terms of function, divided into various units. Of course, in implementing this specification, the functions of each unit can be implemented in one or more software and / or hardware components.
[0111] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0112] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0113] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0114] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0115] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0116] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0117] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0118] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0119] Those skilled in the art will understand that the embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this specification may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0120] This specification can be described in the general context of computer-executable instructions that are executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. This specification can also be practiced in distributed computing environments, where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0121] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0122] The above description is merely an embodiment of this specification and is not intended to limit this specification. Various modifications and variations can be made to this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims of this specification.
Claims
1. A method for generating training samples, comprising: Obtain the nodes in the graph as sampling nodes, determine the edges connected to the sampling nodes, and determine the set of edges to be sampled composed of the edges. A binary tree is constructed using a preset partitioning strategy, with the set of edges to be sampled as the root node and each edge in the set of edges to be sampled as a leaf node. Based on the weights of each edge, a random number is generated. Based on the weights of the edges contained in each node of the binary tree and the random number, the leaf node hit by the random number is determined, and the edges contained in the leaf node are used as sampling edges. The process of generating random numbers includes: determining the minimum weight of the edges in the set of edges to be sampled, and the sum of the weights of the edges in the set of edges to be sampled; and generating random numbers within the range of the minimum weight to the sum of the weights. The step of determining the leaf node hit by the random number based on the weights of the edges contained in each node of the binary tree and the random number includes: taking the root node of the binary tree as the node to be sampled; for each child node of the node to be sampled, determining the sum of the weights of the edges contained in that child node as the node weight of that child node; determining the smaller weight among the node weights of each child node of the node to be sampled; determining whether the random number is not greater than the smaller weight; if so, determining the child node corresponding to the smaller weight as the child node hit by the random number; otherwise, determining the child node corresponding to the larger weight as the child node hit by the random number, and re-determining the difference between the random number and the smaller weight as the random number; re-taking the child node hit by the random number as the node to be sampled, until the random number hits a leaf node; The sampling edge is deleted from the binary tree to update the binary tree, and a new random number is generated. The sampling edge is determined based on the updated binary tree and the new random number until the first sampling end condition is met. The subgraph formed by the sampling node, the sampling edge and the node connected to the sampling edge in the graph is used as the generated training sample. The training sample is used to input the graph neural network to be trained to train the graph neural network.
2. The method as described in claim 1, employing a preset partitioning strategy, constructs a binary tree with the set of edges to be sampled as the root node and each edge in the set of edges to be sampled as a leaf node, specifically including: The set of edges to be sampled is taken as the parent node; According to the preset partitioning strategy, the edge set to be sampled is divided into two sub-edge sets, which serve as the two child nodes of the parent node; For each child node, the child node is re-established as the parent node, and the newly determined parent node is further divided until each divided child node contains only one edge.
3. The method of claim 1, wherein deleting the sampling edge in the binary tree to update the binary tree, specifically includes: Nodes in the binary tree that contain the sampled edge are identified as update nodes; The sampled edges contained in the updated node are deleted to update the binary tree.
4. The method of claim 1, wherein before deleting the sampling edge in the binary tree, the method further comprises: It is determined that the currently obtained sampling edge does not satisfy the second sampling termination condition; If the currently obtained sampling edge satisfies the second sampling termination condition, then the method further includes: For each sampling edge, the node connected to the sampling edge is determined in the graph, and the node is re-used as a sampling node. Sampling edges are then determined based on the re-determined sampling node until the first sampling termination condition is met.
5. The method of claim 1, further comprising, before obtaining the nodes in the graph: Generate a graph using each sample user as a node and the relationships between each sample user as edges; After training the graph neural network to be trained, the method further includes: A topology graph corresponding to each user to be predicted is generated, with each user to be predicted as a node and the relationship between each user to be predicted as an edge. For at least one user to be predicted, the subgraph corresponding to the user to be predicted is determined based on the node corresponding to the user in the topology graph. The subgraph corresponding to the user to be predicted is input into the trained graph neural network to obtain the result of whether the user to be predicted is the target user, as output by the trained graph neural network.
6. A training sample generation apparatus, comprising: The acquisition module is used to acquire nodes in the graph as sampling nodes, determine the edges connected to the sampling nodes, and determine the set of edges to be sampled formed by the edges. A creation module is used to construct a binary tree with the set of edges to be sampled as the root node and each edge in the set of edges to be sampled as a leaf node, using a preset partitioning strategy. The sampling module is used to generate random numbers based on the weights of each edge, and determine the leaf node hit by the random number based on the weights of the edges contained in each node of the binary tree and the random number. The edges contained in the leaf node are used as sampling edges. The sampling edges are deleted from the binary tree to update the binary tree, and random numbers are regenerated. The sampling edges are determined based on the updated binary tree and the regenerated random numbers until the first sampling end condition is met. The subgraph formed by the sampling nodes, the sampling edges and the nodes connected to the sampling edges in the graph is used as the generated training samples. The training samples are used as input to the graph neural network to be trained to train the graph neural network. The sampling module is specifically used to determine the minimum weight of the edges in the edge set to be sampled, and the sum of the weights of the edges in the edge set to be sampled; and to generate random numbers within the range of the minimum weight to the sum of the weights. The sampling module is specifically used to: take the root node in the binary tree as the node to be sampled; and for each child node of the node to be sampled, determine the sum of the weights of the edges contained in the child node as the node weight of the child node. Determine the smaller weight among the node weights of each child node of the node to be sampled; determine whether the random number is not greater than the smaller weight; if so, determine the child node corresponding to the smaller weight as the child node hit by the random number; otherwise, determine the child node corresponding to the larger weight as the child node hit by the random number, and re-determine the difference between the random number and the smaller weight as a random number; re-select the child node hit by the random number as the node to be sampled, until the random number hits a leaf node.
7. The apparatus of claim 6, wherein the creation module is specifically configured to: take the edge set to be sampled as a parent node; divide the edge set to be sampled into two sub-edge sets according to a preset partitioning strategy, which serve as the two child nodes of the parent node; and for each child node, re-take the child node as a parent node, so as to continue partitioning the newly determined parent node until each partitioned child node contains only one edge.
8. The apparatus of claim 6, wherein the sampling module is specifically configured to: determine nodes in the binary tree that contain the sampling edge as update nodes; and delete the sampling edge contained in the update node to update the binary tree.
9. The apparatus of claim 6, wherein the sampling module, before deleting the sampling edge in the binary tree, is further configured to determine that the currently obtained sampling edge does not satisfy the second sampling termination condition; If the currently obtained sampling edge satisfies the second sampling end condition, the sampling module is further configured to, for each sampling edge, determine the node connected to the sampling edge in the graph, re-use the node as a sampling node, and continue to determine sampling edges based on the re-determined sampling node until the first sampling end condition is met.
10. The apparatus of claim 6, wherein the acquisition module, before acquiring the nodes in the graph, is further configured to generate a graph with each sample user as a node and the relationship between each sample user as an edge; After training the graph neural network to be trained, the sampling module is further configured to generate a topology graph corresponding to each user to be predicted, using each user to be predicted as a node and the relationship between each user to be predicted as an edge; for at least one user to be predicted, a subgraph corresponding to the user to be predicted is determined based on the node corresponding to the user to be predicted in the topology graph; the subgraph corresponding to the user to be predicted is input into the trained graph neural network to obtain the result of whether the user to be predicted is the target user output by the trained graph neural network.
11. A computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in any one of claims 1 to 5.
12. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in any one of claims 1 to 5.
Citation Information
Patent Citations
Multi-class support vector machine classification method based on dynamic binary tree
CN102722726A
Sampling task load balancing and fault-tolerant method for wireless sensor network
CN104486795A