Sample sampling method, device, equipment and storage medium based on graph structure
Patent Information
- Authority / Receiving Office
- HK · HK
- Patent Type
- Patents
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2023-05-25
- Publication Date
- 2026-07-10
AI Technical Summary
In existing technologies, the types of training samples based on graph structures are relatively limited, resulting in insufficient training of graph neural network models. This is especially true in scenarios involving cold-start users or low-activity users, where there are insufficient positive samples and poor training performance.
A hybrid attenuation sampling method is adopted to generate soft links with structural information, synthesize new nodes and edge connections, construct training samples for graph neural network models, and determine link weights by using the number of paths between anchor nodes and sampling nodes, thereby enhancing data augmentation and node feature representation.
It improves the richness and robustness of training samples, enhances the training effect of graph neural network models, and is particularly effective in capturing potential interaction relationships and improving the prediction accuracy of models in scenarios with cold start users or low-activity users.
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a sample sampling method, apparatus, device and storage medium based on graph structure. Background Technology
[0002] With the development of artificial intelligence technology, graph structures can be used to represent the relationships between data flows. Taking video recommendation as an example, users can be treated as nodes in the graph structure, and videos can also be treated as nodes in the graph structure. Whether a user watches a video determines whether there is a direct interaction between the user node and the video node (i.e., an edge directly connecting the user node and the video node).
[0003] In related technologies, training samples are constructed based on graph structure information to train graph neural network models, enabling the trained models to output node feature information. Typically, positive and negative samples are determined by whether there are direct interactions between nodes.
[0004] However, the aforementioned technologies determine training samples solely based on whether there is direct interaction between nodes, resulting in a limited variety of training samples. Summary of the Invention
[0005] This application provides a graph-based sample sampling method, apparatus, device, and storage medium, which can construct richer training samples, thereby helping to increase the quantity and richness of training samples extracted from graph structure information, and further helping to improve the robustness of subsequent training of graph neural network models using the obtained training samples. The technical solution is as follows:
[0006] According to one aspect of the embodiments of this application, a graph-based sample sampling method is provided, the method comprising:
[0007] Obtain graph structure information, which includes multiple nodes, and two nodes connected by an edge constitute a positive sample pair;
[0008] For the anchor node among the plurality of nodes, the link weight between the anchor node and the sampling node is determined based on the number of paths between the anchor node and the sampling node; wherein, the sampling node is a node among the plurality of nodes that does not have an edge connection with the anchor node;
[0009] Based on the anchor node, the sampling node, and the link weights between the anchor node and the sampling node, a first training sample for the graph neural network model is constructed; wherein, the graph neural network model is used to extract features from the graph structure information.
[0010] According to one aspect of the embodiments of this application, a graph-based sample sampling device is provided, the device comprising:
[0011] The information acquisition module is used to acquire graph structure information, which includes multiple nodes, and two nodes connected by an edge constitute a positive sample pair.
[0012] The weight determination module is used to determine the link weight between the anchor node and the sampling node based on the number of paths between the anchor node and the sampling node among the plurality of nodes; wherein, the sampling node is a node among the plurality of nodes that does not have an edge connection with the anchor node;
[0013] The sample construction module is used to construct the first training sample of the graph neural network model based on the anchor node, the sampling node, and the link weights between the anchor node and the sampling node; wherein the graph neural network model is used to extract features from the graph structure information.
[0014] According to one aspect of the embodiments of this application, a computer device is provided, the computer device including a processor and a memory, the memory storing a computer program, the computer program being loaded and executed by the processor to implement the above-described method.
[0015] According to one aspect of the embodiments of this application, a computer-readable storage medium is provided, wherein a computer program is stored in the storage medium, the computer program being loaded and executed by a processor to implement the above-described method.
[0016] According to one aspect of the embodiments of this application, a computer program product is provided, the computer program product including 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, causing the computer device to perform the method described above.
[0017] The technical solutions provided in this application embodiment may have the following beneficial effects:
[0018] In the graph structure information, the link weights between anchor nodes and sampling nodes are determined based on the number of paths between them. Training samples for the graph neural network model are then constructed based on the anchor nodes, sampling nodes, and the link weights between them. This embodiment determines the link weights based on the number of paths between anchor nodes and sampling nodes, making the determined link weights more consistent with the graph structure information. The training samples determined based on these link weights are also closer to the graph structure itself. Naturally, the training samples are also richer, which helps to increase the quantity and richness of training samples extracted from the graph structure information, thereby improving the robustness of subsequently training the graph neural network model using these obtained training samples. Attached Figure Description
[0019] Figure 1 This is a schematic diagram of the implementation environment of a solution provided in one embodiment of this application;
[0020] Figure 2 This is a schematic diagram of a hybrid attenuation sampling method provided in one embodiment of this application;
[0021] Figure 3 This is a flowchart of a graph-based sample sampling method provided in one embodiment of this application;
[0022] Figure 4 This is a schematic diagram of an attenuation sampling method provided in one embodiment of this application;
[0023] Figure 5 This is a schematic diagram of an anchoring node and a sampling node provided in one embodiment of this application;
[0024] Figure 6 This is a schematic diagram of an attenuation sampling method provided in another embodiment of this application;
[0025] Figure 7 This is a flowchart of a graph-based sample sampling method provided in another embodiment of this application;
[0026] Figure 8 This is a schematic diagram of a hybrid sampling method provided in one embodiment of this application;
[0027] Figure 9 This is a schematic diagram of a hybrid attenuation sampling method provided in another embodiment of this application;
[0028] Figure 10 This is a block diagram of a graph-based sample sampling device provided in one embodiment of this application;
[0029] Figure 11 This is a block diagram of a graph-based sample sampling device provided in another embodiment of this application;
[0030] Figure 12 This is a structural block diagram of a computer device provided in one embodiment of this application. Detailed Implementation
[0031] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0032] Before introducing the technical solution of this application, some background technical knowledge involved in this application will be introduced and explained. The following related technologies are optional solutions and can be arbitrarily combined with the technical solutions of the embodiments of this application, all of which fall within the protection scope of the embodiments of this application. The embodiments of this application include at least some of the following contents.
[0033] Artificial intelligence (AI) is the theory, methods, technology, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that attempts to understand the essence of intelligence and produce a new kind of intelligent machine that can react in a way similar to human intelligence. AI studies the design principles and implementation methods of various intelligent machines, enabling them to possess the functions of perception, reasoning, and decision-making.
[0034] Artificial intelligence (AI) is a comprehensive discipline encompassing a wide range of fields, including both hardware and software technologies. Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies primarily include natural language processing and machine learning / deep learning.
[0035] Computer vision (CV) is a science that studies how to enable machines to "see." More specifically, it refers to machine vision, which uses cameras and computers to replace human eyes in recognizing and measuring targets, and then performs image processing to create images more suitable for human observation or transmission to instruments. As a scientific discipline, computer vision studies related theories and technologies, attempting to build artificial intelligence systems capable of extracting information from images or multidimensional data. Computer vision technologies typically include image processing, image recognition, image semantic understanding, image retrieval, video processing, video semantic understanding, video content / behavior recognition, 3D object reconstruction, virtual reality, augmented reality, simultaneous localization and mapping (SLAM), and common biometric recognition technologies such as facial recognition and fingerprint recognition.
[0036] Natural Language Processing (NLP) is an important field within computer science and artificial intelligence. It studies the theories and methods for enabling effective communication between humans and computers using natural language. NLP is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field involves natural language—the language people use in daily life—and thus it has a close relationship with linguistic research. NLP techniques typically include text processing, semantic understanding, machine translation, question answering, and knowledge graphs.
[0037] Machine learning (ML) is a multidisciplinary field involving probability theory, statistics, approximation theory, convex analysis, and algorithm complexity theory. It specifically studies how computers can simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to endow computers with intelligence; its applications span all areas of artificial intelligence. Machine learning and deep learning typically include techniques such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and learn-by-doing.
[0038] With the research and advancement of artificial intelligence (AI) technology, AI is being studied and applied in various fields, such as smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, autonomous driving, drones, robots, smart healthcare, and smart customer service. It is believed that with the development of technology, AI will be applied in more fields and play an increasingly important role.
[0039] The solutions provided in this application involve technologies such as computer vision and natural language processing in artificial intelligence, and are specifically illustrated through the following embodiments.
[0040] Before introducing the technical solutions of this application, some terms involved in this application will be explained. The following related explanations are optional solutions and can be arbitrarily combined with the technical solutions of the embodiments of this application, all of which fall within the protection scope of the embodiments of this application. The embodiments of this application include at least some of the following contents.
[0041] Deep learning: The concept of deep learning originated from research on artificial neural networks. A multilayer perceptron with multiple hidden layers is a type of deep learning architecture. Deep learning discovers distributed feature representations of data by combining low-level features to form more abstract high-level representations of attribute categories or features.
[0042] Graph Neural Networks (GNNs) are a general term for algorithms that use neural networks to learn graph-structured data, extract and discover features and patterns within the data, and meet the needs of graph learning tasks such as clustering, classification, prediction, segmentation, and generation. Applications of GNNs include: at the node level, common applications include node classification, node aggregation, and node representation learning; at the edge level, there are edge classification, edge clustering, and link prediction; at the graph level, graph classification, graph generation, subgraph partitioning, and graph similarity analysis are widely used. Based on graph type, they can be categorized into citation networks, social networks, traffic networks, image networks, compound molecular structures, and protein networks. Based on application domain, they can be categorized into natural language processing, image processing, trajectory prediction, physical chemistry, and pharmacology.
[0043] Feature vector: Taking a graph neural network model as an example, the features of a node can be represented by a vector. That is, the feature vector output by the graph neural network model is used to characterize the node features of the graph structure or the structural features between nodes. Optionally, the feature vector is a numerical vector.
[0044] Linear interpolation: Interpolation is a method of finding patterns in a known data sequence (which can be understood as a series of discrete points in a coordinate system) and then using these patterns to estimate the values of points for which there is no data yet. Applications include: compensating for missing data and scaling up or down data. Linear interpolation is a method for one-dimensional data. It estimates the values of the two nearest neighbors to the point in the one-dimensional data sequence that needs interpolation. However, it doesn't calculate the average of these two points (which would be the case at the center point), but rather assigns weights based on the distance to these two points.
[0045] Mixup algorithm: It is an algorithm used in computer vision to enhance images by mixing different classes. It can combine images from different classes to expand the training dataset.
[0046] Breadth-First Search (BFS) is a graph search algorithm used to solve the shortest path problem.
[0047] The random walk algorithm, defined as a random walk, is conceptually similar to Brownian motion, representing its ideal mathematical state. Its basic idea is to traverse a graph starting from one or a series of vertices. At any vertex, the traverser will move to its neighboring vertices with probability 1-a, and then randomly jump to any vertex in the graph with probability a, where a is the jump probability. After each walk, a probability distribution is obtained, which describes the probability of each vertex being visited. This probability distribution is used as the input for the next walk, and this process is iterated repeatedly. Under certain preconditions, this probability distribution will tend to converge. After convergence, a stationary probability distribution is obtained.
[0048] A bipartite graph, also known as a bipartite graph, is a special model in graph theory. Let G = (V, E) be an undirected graph. If a vertex V can be partitioned into two disjoint subsets (A, B), and each edge (i, j) in the graph is associated with two vertices i and j belonging to these two distinct vertex sets (i in A, j in B), then graph G is called a bipartite graph.
[0049] The beta distribution is a probability density function that serves as the conjugate prior distribution of the Bernoulli and binomial distributions, and it has important applications in machine learning and mathematical statistics. The parameters in the beta distribution can be understood as pseudo-counts. The likelihood function of the Bernoulli distribution can be expressed as , representing the probability of an event occurring. It has the same form as the beta distribution, therefore the beta distribution can be used as its prior distribution.
[0050] Sampling: In graph model training, in order to better represent the relationship between nodes, positive and negative samples of a node are often constructed through different sampling methods, so that the node structure presents a non-normal distribution.
[0051] Item: Content in the recommendation feed, which can be articles, videos, images, etc.
[0052] Please refer to Figure 1 This diagram illustrates an implementation environment for a solution provided in one embodiment of this application. The implementation environment may include: a terminal device 10 and a server 20.
[0053] Terminal device 10 includes, but is not limited to, mobile phones, tablets, smart voice interaction devices, game consoles, wearable devices, multimedia playback devices, PCs (Personal Computers), in-vehicle terminals, smart home appliances, and other electronic devices. The client for the target application can be installed on terminal device 10.
[0054] In this embodiment, the target application can be any application with a recall function. Typically, this application is a video recall application. Of course, in addition to video recall applications, other types of applications can also provide recall functions. For example, social applications, entertainment applications, news and information applications, virtual reality (VR) applications, augmented reality (AR) applications, etc., are not limited in this embodiment. In addition, the content to be recalled is different for different applications, so the recalled content can be images or other recommended content. For example, videos, files, emoticons, news, etc., are not limited in this embodiment. Optionally, the terminal device 10 runs a client of the above-mentioned application.
[0055] Server 20 is used to provide backend services for the client of the target application in terminal device 10. For example, server 20 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as 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 big data and artificial intelligence platforms, but it is not limited to these.
[0056] Terminal device 10 and server 20 can communicate with each other via a network. This network can be a wired network or a wireless network.
[0057] The method provided in this application embodiment can be executed by a computer device in each step. The computer device can be any electronic device capable of data storage and processing. For example, the computer device can be... Figure 1 Server 20 in the middle can be Figure 1 The terminal device 10 can also be another device other than the terminal device 10 and the server 20.
[0058] Please refer to Figure 2 The diagram illustrates a graph-based sample sampling method provided in one embodiment of this application.
[0059] In related technologies, user interests have a significant impact on the effectiveness of video recommendation. In some embodiments, behaviors that do not generate interaction may still contain potential for interaction or disinterest. Furthermore, since cold-start users or low-activity users exhibit less behavior in the scenario, meaning there is less behavioral data for this type of user, it is difficult to characterize their interests. In related technologies, sampling a node simply treats all samples as either positive or negative. In some embodiments, positive samples are constructed based on anchor nodes and nodes with direct interaction relationships with the anchor node, while negative samples are constructed based on anchor nodes and nodes without direct interaction relationships with the anchor node. In other embodiments, positive samples are constructed based on anchor nodes and nodes with edge connections to the anchor node within L hops, while negative samples are constructed based on anchor nodes and nodes with edge connections to the anchor node beyond L hops, where L is a positive integer. Furthermore, the link weight between node pairs constituting a positive sample is considered to be 1, while the link weight between node pairs constituting a negative sample is considered to be 0. However, simply classifying the relationships between sampled nodes into two categories will lead to the following problems: the nodes in the graph are connected by multi-hop neighbors. When sampling, the method ignores the multi-hop relationships between nodes and simply divides the relationships between nodes into positive and negative categories, thus losing the potential interaction possibilities that can be captured in the graph structure; secondly, cold start users or low-activity users have less behavior in the scenario, resulting in fewer positive samples for the model and insufficient training.
[0060] Based on this, the technical solution provided in this application, by employing MixDecSampling, generates soft links with structural information based on the graph structure, and synthesizes new nodes and edge connections. This integrates graph structure information into the sampling process and enhances the features of the nodes. Figure 2As shown, 200 represents the graph structure, where node U is connected to nodes P1 and P2 by edges. Using hybrid sampling, a new node M1 is generated based on nodes N and P1, and a new node M2 is generated based on nodes P1 and P2. Soft links are then constructed between anchor node U and nodes M1 and M2. The link weights of the soft links between node M1 and anchor node U are determined based on the link weights of nodes N and P1 with anchor node U, respectively. Similarly, the link weights of the soft links between node M2 and anchor node U are determined based on the link weights of nodes P1 and P2 with anchor node U, respectively. Using decay sampling, node U is considered the anchor node, and nodes Q1 and Q2 are decaying nodes (decade table) with a breadth of 3 (3 hops) connected to node U. The link weights of the soft links between decaying nodes Q1 and Q2 and node U are determined based on the number of reachable paths from decaying node Q1 to anchor node U and the number of reachable paths from decaying node Q2 to anchor node U. Hybrid attenuation sampling is a sampling method that combines hybrid sampling with attenuation sampling. In some embodiments, in video recommendation scenarios, hybrid attenuation sampling can capture potential interactions through graph structures and, when cold-started users or low-activity users have limited activity in the scenario, fully construct positive samples for the model, resulting in more thorough model training.
[0061] The main problem with related techniques is that during negative sampling, sampling a single node simply treats all samples globally as either positive or negative, leading to the loss of graph structure information. Specifically, nodes in a graph are connected by multi-hop neighbors. Related techniques ignore these multi-hop relationships during sampling, simply classifying them into positive and negative categories. However, graph neural network training requires aggregating information about a node's neighbors, but the sampling process neglects these multiple neighbor relationships, resulting in the loss of structural information.
[0062] The technical solution provided in this application, by borrowing the strategy of BFS, processes the neighbors of each node, quantifies the relationships between nodes based on the number of paths, and transforms the links between nodes into soft links. This better reflects the differences in relationships between nodes and clearly displays structural information. Linear interpolation is used to augment the nodes and features in the graph, generating synthetic nodes and links to increase interaction for nodes that have not been seen or have had little interaction. By combining differentiated soft links with data augmentation methods, more accurate nodes and links can be generated, maximizing the utilization of the node and structural information content in the graph.
[0063] The sample pairs obtained based on the technical solutions provided in this application can be used to train a graph neural network, enabling the trained graph neural network to be used for tasks such as edge prediction, recommendation, and generation. When the graph type is content, for example, when the content is video, a graph structure is generated based on the user's video browsing behavior records, with both the user and the video as nodes. When the user clicks, browses, or watches the video, the node containing the video is connected to the node containing the user. Correspondingly, the video will also be viewed by other users, so the node containing the video will also have multiple connections with the nodes containing other users. Based on the graph structure generated from this user information, the graph structure-based sample sampling method provided in this application can construct relatively rich training samples. The graph neural network trained using these training samples can output feature information about the user and the video. Based on this feature information, videos that the user may be interested in can be recommended to the current user. Here, the degree of interest can be determined based on the similarity of feature information between the user and the video. In other words, when the similarity between a user's profile and a video's profile exceeds a threshold, the video is considered potentially of interest to the user, and is retrieved from the video library and displayed on the recommended video page. This includes, but is not limited to, videos, articles, news, emojis, songs, and items in a shopping cart; essentially, articles, news, emojis, songs, and items in a shopping cart can be retrieved and recommended to the user based on their relevance.
[0064] When the graph is a social network, the graph structure is generated based on users' friend relationships. Users can be considered as nodes, and friends between users can be considered as connections between nodes. Using the graph structure-based sampling method provided in this application, a relatively rich training sample can be constructed based on the graph structure generated from these user friend information. The graph neural network trained using this training sample can output user feature information. Based on this feature information, users that the current user may know or be interested in can be recommended. That is, when the similarity between a user's feature information and the feature information of other non-friend users (referred to as the first user) is greater than a threshold, the first user is considered to be someone the user may be interested in or know, and the first user is recalled from the large user pool, with their homepage or contact information displayed on the recommended user interface.
[0065] When the graph is a transportation network, the graph structure is generated based on the user's frequently traveled routes or navigation routes. The user, the user's starting and ending locations can also be considered nodes, as can intersections or landmarks along the user's route. Using the graph structure-based sample sampling method provided in this application, a relatively rich set of training samples can be constructed from the graph structure generated based on this route information. The graph neural network trained using these training samples can output location feature information. Based on this feature information, locations of interest can be recommended to the current user. That is, when the similarity between the user's feature information and the feature information of other locations is greater than a threshold, the location is considered to be a location of interest or a desired destination for the user, and this location is recalled from among many locations, displaying it as the first recommended destination.
[0066] In this application embodiment, the type of graph is not limited. Any graph that has a corresponding relationship and can form a graph structure can be sampled using the sampling method provided in this application embodiment to obtain richer training samples, thereby better training the graph neural network model and making the model's prediction results more accurate.
[0067] The technical solution provided in this application, drawing on the Mixup algorithm—a commonly used data augmentation method in CV and NLP—constructs a linear interpolation method for generating soft links and synthetic nodes. For a user's operation, such as user-click-item, in addition to negative sample sampling, the Mixup algorithm can be used for linear interpolation to construct synthetic samples and links, performing Mixup Sampling. The main advantage of this approach is feature-based graph structure optimization to mine more accurate feature representations for cold start. To more clearly represent the graph structure, the algorithm performs a K-layer BFS on each node and calculates the number of paths between each node and reachable nodes, scaling soft links based on the number of paths. This distinguishes the relevance of nodes at different distances, and by generating a decay table for each node, the algorithm's complexity in actual training is reduced through preprocessing. Based on attenuation sampling, the generation of nodes and links in hybrid sampling has been further optimized, and interpolation between positive sample nodes has been performed in combination with the relationship between nodes. The interpolation between positive sample nodes and negative sample nodes, and the interpolation between positive sample nodes and attenuation sample nodes, have resulted in a more accurate and comprehensive node representation.
[0068] It should be noted that this application may display prompt interfaces, pop-ups, or output voice prompts before and during the collection of user data. These prompt interfaces, pop-ups, or voice prompts are used to inform the user that their data is being collected. This ensures that the application only begins the steps for collecting user data after receiving confirmation from the user regarding the prompt interface or pop-up; otherwise (i.e., without user confirmation), the steps for collecting user data end, meaning no user data is collected. In other words, all user data collected in this application is collected with the user's consent and authorization, and the collection, use, and processing of related user data must comply with the relevant laws, regulations, and standards of the relevant countries and regions.
[0069] In some embodiments, the sampling method is decaying sampling plus negative sample sampling. To preserve the structural information of the graph during sampling, decaying sampling is proposed, which enhances the mining of graph structural information through a soft link mechanism. In breadth-first search, the link weights between nodes decay with their distance.
[0070] Please refer to Figure 3 The diagram illustrates a flowchart of a graph-based sample sampling method provided in one embodiment of this application. This method can be... Figure 1 The method can be executed by terminal device 10 or server 20 in the implementation environment shown, or by both terminal device 10 and server 20. In the following method embodiments, for ease of description, the execution subject of each step is only referred to as "computer device". The method may include at least one of the following steps (310-330):
[0071] Step 310: Obtain graph structure information, which includes multiple nodes. Two nodes connected by an edge constitute a positive sample pair.
[0072] Graph structure information: This refers to the graph structure information representing the data flow. The data flow in this application can be of any type; any graph structure information formed based on data flows with interactive relationships can be included within the protection scope of this application. In some embodiments, the data flow can be a user-content-driven data flow. When a user clicks on content, it can be assumed that there is an edge connection between the user and the content, with both the user and the content constituting nodes.
[0073] A node is at least one of the following in a data stream: a subject or an object that a subject views. Taking a video recommendation scenario as an example, the data stream is the stream of videos viewed by a user. The user is the subject (a node), and the video is the object (also a node). When a user views a video, it is assumed that there is an edge connection between the user node and the video node.
[0074] Edge connection: Two nodes that directly interact are considered to be connected by an edge, while two nodes that do not directly interact are not connected by an edge. Direct interaction here means that there are no other nodes between the two nodes, and they are connected by only one edge. For example... Figure 4 As shown, nodes U and P1 are considered to be connected by an edge, and nodes U and P2 are also considered to be connected by an edge, but nodes P1 and P2 are not connected by an edge. Therefore, nodes U and P1 constitute a positive sample, and nodes U and P2 also constitute a positive sample.
[0075] like Figure 2 As shown, 200 is a graph structure with multiple nodes and edges connecting them.
[0076] Step 320: For anchor nodes among multiple nodes, determine the link weight between anchor nodes and sampling nodes based on the number of paths between anchor nodes and sampling nodes; wherein, sampling nodes are nodes among multiple nodes that do not have edge connections with anchor nodes.
[0077] In some embodiments, taking the graph type as content as an example, the anchor node corresponds to the user, the sampling node corresponds to the content, and the link weight between the anchor node and the sampling node is used to characterize the user's degree of interest in the content. Optionally, the content can be a video, in which case the anchor node is the user, the sampling node is the video, and the link weight between the user and the video is used to characterize the user's degree of interest in the video. In some embodiments, the anchor node is any node in the graph structure information. Optionally, every node in the graph structure information is used as an anchor node, and a corresponding decay node is determined. Optionally, some nodes from all nodes in the graph structure information can also be used as anchor nodes, and corresponding decay nodes are determined.
[0078] In some embodiments, a sampling node is a node among a plurality of nodes that does not have an edge connection to the anchor node. Optionally, a sampling node may also be considered a decay node. In some embodiments, such as Figure 4 As shown, node Q1 and node U are not connected by an edge, and node Q1 can be considered as a sampling node (attenuation node).
[0079] In some embodiments, step 320 includes at least one of steps 321 to 323 (not shown in the figures).
[0080] Step 321: Determine the number of paths with a specified number of hops between the anchor node and the sampling node as the number of sampling paths.
[0081] In some embodiments, nodes with a specified number of hops to the anchor node are considered as sampling nodes. This application embodiment does not limit the number of sampling nodes; all nodes meeting the criteria can be used as sampling nodes, or a set number of sampling nodes can be used to select a target sampling node from multiple sampling nodes as the sampling node needed to construct the first training sample. This application embodiment uses a breadth-first search algorithm to determine decaying nodes in the graph structure. Optionally, other algorithms can also be used to determine decaying nodes, and this application does not limit this. In some embodiments, when using the breadth-first search algorithm, if the breadth is L (where L is a positive integer), then the number of hops is considered to be L. That is, nodes in the graph structure with a hop count of L to the anchor node are considered as decaying nodes with a breadth of L.
[0082] In this embodiment, the specific value of the hop count is not limited; optionally, the specified hop count is 3. In some embodiments, the specified hop count is the same as the number of aggregation layers in the graph neural network model. For the graph neural network model, the aggregation layer's role is to fuse the feature information of neighbors within a few hops and perform feature inference together. Similarly, the sampling nodes for the specified hop count are selected nodes relatively related to the anchor node; therefore, their purposes are similar. Associating the aggregation layer with the hop count, that is, setting the hop count of the samples selected when constructing training samples to be the same as the number of aggregation layers, maximizes the utilization of the graph neural network model's aggregation layer to infer the feature information of the samples, thereby maximizing model efficiency and reducing unnecessary processing overhead. If the specified hop count is different from the number of aggregation layers in the graph neural network model, the graph neural network model could have fused feature information from sampling points with more hop counts, but the number of hops allocated to the sampling points is less, potentially leading to a waste of resources.
[0083] In some embodiments, the hop count can also be considered as the number of edges between nodes. When the specified hop count is 3, such as... Figure 4 As shown, there are multiple sampling nodes with 3 hops to the anchor node, where node Q1 can be considered as one of the sampling nodes, and there are 3 hops between node Q1 and the anchor node U.
[0084] like Figure 5 The diagram illustrates an embodiment of the anchor node and sampling nodes provided in this application. Node K1 is the anchor node, and nodes K2, K3, K4, and K5 are the four sampling nodes (attenuation nodes) corresponding to anchor node K1, with a specified hop count of 3. Taking nodes K1 and K2 as an example, there is only one path from node K1 to node K2, j1+j2+j3; therefore, the hop count between node K1 and node K2 is 3 hops. Thus, when the anchor node is node K1 and the specified hop count is 3, node K2 is one of the sampling nodes.
[0085] Step 322: Determine the target node and the maximum number of paths corresponding to the target node from multiple nodes; where the target node is the node with the most paths with a specified number of hops to the anchor node, and the maximum number of paths is the number of paths with a specified number of hops between the anchor node and the target node.
[0086] like Figure 5 As shown, when the hop count is 3, the number of paths from anchor node K1 to sampling node K2 is 1, the number of paths from anchor node K1 to sampling node K3 is 3, the number of paths from anchor node K1 to sampling node K4 is 4, and the number of paths from anchor node K1 to sampling node K5 is 1. Therefore, the maximum number of paths is 4, and the target node is sampling node K4 corresponding to path 4.
[0087] Step 323: Determine the link weight between the anchor node and the sampling node based on the number of sampling paths and the maximum number of paths.
[0088] The number of sampling paths refers to the number of paths from the anchor node to the sampling node. The maximum number of paths is the maximum number of sampling paths corresponding to all sampling nodes. For example... Figure 5 As shown, for sampling node K3, the number of sampling paths is 3.
[0089] In some embodiments, step 323 includes at least one of steps 323-1 to 323-2 (not shown in the figure).
[0090] Step 323-1: Calculate the quotient of the number of sampling paths and the maximum number of paths.
[0091] Step 323-2: Multiply the difference between 1 and the weight coefficient by the quotient, and add the product to the weight coefficient to obtain the link weight between the anchor node and the sampling node; where the weight coefficient is a constant greater than 0 and less than 1.
[0092] In some embodiments, for each anchor node in the graph, a decay weight (link weight) of the link between it and its neighbors (sample nodes) within L hops (a specified number of hops) is calculated based on BFS. The link weight is designed based on the number of reachable paths r (the number of paths within a specified number of hops) between the anchor node and its L-hop (a specified number of hops) neighbors (sample nodes). The number of hops L in BFS is the same as the number of aggregation layers in the GNN model, where L and r are both positive integers. The link weights for anchor nodes and sample nodes are defined as follows:
[0093] In some embodiments, the formula for determining the link weight between the anchor node and the sampling node is as follows:
[0094]
[0095] Where node d is one of the neighbors of node v within L hops (specified number of hops) reached by node v in BFS, node d is the sampling node (attenuation node), and w d It is the link weight between node v (anchor node) and node d, and ρ is used to map w. d The weights are assigned to [ρ, 1], where ρ is the weight coefficient. max It is all r within L's neighbor. d The maximum value of r max It represents the maximum number of paths. It is the quotient of the number of sampling paths and the maximum number of paths.
[0096] In some embodiments, when ρ (weighting coefficient) is set to 0.5, such as Figure 4 The anchor node (node U) and sampling nodes (nodes Q1, Q2, Q3, and Q4) shown have 1, 1, 3, and 2 reachable paths with a specified hop count of 3, respectively. Then, the link weights of each sampling node determined according to the number of paths and the weight coefficient ρ are 0.66, 0.66, 1, and 0.83, respectively.
[0097] In some embodiments, when ρ (weighting coefficient) is set to 0.5, such as Figure 5 The number of paths for the anchor nodes and sampling nodes shown are 1, 3, 4, and 1, respectively. Therefore, the link weights of each sampling node determined by the number of paths and the weight coefficient ρ are 0.625, 0.875, 1, and 0.625, respectively.
[0098] In some embodiments, the method further includes at least one of steps 324 to 327 (not shown in the figures).
[0099] Step 324: Obtain the link weights corresponding to each candidate node that can be reached from the anchor node by a path with a specified number of hops; wherein, the link weights corresponding to the candidate nodes are determined based on the number of paths with a specified number of hops between the anchor node and the candidate nodes, and the maximum number of paths.
[0100] In some embodiments, the anchor node corresponds to multiple sampling nodes with a specified number of hops. However, several of these sampling nodes are selected as candidate nodes. The selection of candidate nodes can be randomized after setting a certain number, or it can be manually selected; this application does not impose any limitations. Of course, if computational accuracy is considered without considering computational cost, all sampling nodes can also be used as candidate nodes.
[0101] Step 325: Sort the link weights corresponding to each candidate node in descending order to obtain the candidate node sequence.
[0102] After calculating the link weights corresponding to each candidate node, the link weights are sorted in descending order to obtain the candidate node sequence.
[0103] In some embodiments, such as Figure 4 The candidate nodes shown are nodes Q1, Q2, Q3, and Q4, with link weights of 0.66, 0.66, 1, and 0.83, respectively. Therefore, the candidate node sequence obtained by sorting the link weights in descending order is nodes Q3, Q4, Q1, and Q2.
[0104] In some embodiments, such as Figure 5 The candidate nodes shown are nodes K2, K3, K4, and K5, with link weights of 0.625, 0.875, 1, and 0.625 respectively. Therefore, the candidate node sequence obtained by descending the link weight is nodes K4, K3, K2, and K5.
[0105] Step 326: If the sampling node is located in the first D positions of the candidate node sequence, the link weight between the anchor node and the sampling node, which is determined by the number of sampling paths and the maximum number of paths, will be used as the link weight corresponding to the sampling node.
[0106] In some embodiments, D is a positive integer. Optionally, D is 2, meaning the link weights of the first two sampled nodes in the candidate node sequence are determined based on the number of sampled paths and the maximum number of paths. Optionally, for the candidate node sequence of nodes Q3, Q4, Q1, and Q2, the link weight of node Q3 is considered to be 1, and the link weight of node Q4 is considered to be 0.83. Optionally, for the candidate node sequence of nodes K4, K3, K2, and K5, the link weight of node K4 is considered to be 1, and the link weight of node K3 is considered to be 0.875.
[0107] Step 327: If the sampling node is not located in the first D positions of the candidate node sequence, then 0 is determined as the link weight corresponding to the sampling node.
[0108] In some embodiments, D is a positive integer. Optionally, D is 2, meaning the link weights of the sampled nodes after the first two in the candidate node sequence are set to 0. Optionally, for the candidate node sequence of nodes Q3, Q4, Q1, and Q2, the link weights of nodes Q1 and Q2 are set to 0. Optionally, for the candidate node sequence of nodes K4, K3, K2, and K5, the link weights of nodes K2 and K5 are set to 0.
[0109] In some embodiments, such as Figure 6As shown, D1 and D2 are decay nodes, which are the third-hop nodes found by anchor node U through BFS. Then, in<D1,U> and<D2,U> Create a symbolic link between each element. Using symbolic links effectively preserves the structural information of the graph.
[0110] Step 330: Based on the anchor node, the sampling node, and the link weights between the anchor node and the sampling node, construct the first training sample of the graph neural network model; wherein, the graph neural network model is used to extract features from the graph structure information.
[0111] In some embodiments, the feature is feature information; alternatively, the feature information is a feature vector.
[0112] In some embodiments, the method further includes at least one of steps 340 to 350 (not shown in the figures).
[0113] Step 340: Using a graph neural network model, determine the prediction weights between the anchor node and the sampling node based on the feature information of the anchor node and the feature information of the sampling node.
[0114] Step 350: Determine the first loss function value of the graph neural network model based on the prediction weights between the anchor node and the sampling node, and the link weights between the anchor node and the sampling node.
[0115] In some embodiments, since the cross-entropy loss function is not suitable for soft links, the loss cannot be reduced to zero. To adapt to the representation of soft links, the attenuated sampling loss function can optionally be used as follows:
[0116]
[0117] in, This represents the first loss function value, where v represents the anchor node and d represents the sampling node. Let σ represent the set of all sampled nodes, and let σ represent the sigmoid function. e represents the transpose of the eigenvector of the anchor node v. d w represents the feature vector of sampling node d. d This represents the link weight of the sampling node d.
[0118] In some embodiments, the above method further includes steps 510 to 520 (not shown in the figures).
[0119] Step 510: Randomly sample negative sample nodes of the anchor node from multiple nodes. Negative sample nodes are nodes among the multiple nodes that do not have an edge connection with the anchor node.
[0120] Step 520: Based on the anchor node, the negative sample node, and the link weights between the anchor node and the negative sample node, construct the third training sample for the graph neural network model.
[0121] In some embodiments, a graph neural network model is used to determine the prediction weights between anchor nodes and sampling nodes based on the feature information of anchor nodes and sampling nodes. Based on the prediction weights between anchor nodes and sampling nodes, and the link weights between anchor nodes and negative sample nodes, the value of the third loss function of the graph neural network model is determined.
[0122] In some embodiments, the loss function for negative sample sampling is as follows:
[0123]
[0124] in, This represents the value of the third loss function, where v represents the anchor node, and n... + Represents positive sample nodes, n - Indicates a negative sample node. Let σ represent the set of all positive and negative sample nodes, and let σ represent the sigmoid function. e represents the transpose of the eigenvector of the anchor node v. n This represents the feature vector of the negative sample node n.
[0125] In some embodiments, using the first and third training samples as training samples, the loss function for obtaining the final training samples is:
[0126] The technical solution provided in this application determines the link weights between anchor nodes and sampling nodes based on the number of paths between them in the graph structure information. Then, based on the anchor nodes, sampling nodes, and the link weights between them, a first training sample for the graph neural network model is constructed. This application determines the link weights based on the number of paths between anchor nodes and sampling nodes, making the determined link weights more consistent with the graph structure information. The training samples determined based on these link weights are also closer to the graph structure itself. Therefore, the construction of training samples is more diverse, which helps to increase the quantity and richness of training samples extracted from the graph structure information. Furthermore, more accurate features can be obtained based on the graph neural network model, thereby improving the robustness of subsequently training the graph neural network model using these obtained training samples.
[0127] The technical solution provided in this application determines the number of sampling paths by defining the number of paths with a specified number of hops between the anchor node and the sampling node. It then identifies the maximum sampling path and the target node from among these multiple sampling paths. In other words, it selects the node most relevant to the anchor node from among multiple sampling nodes and determines the link weights corresponding to different sampling nodes based on the maximum number of paths and the number of sampling paths. Therefore, the method for determining link weights in the technical solution provided in this application is more closely aligned with the graph structure information itself. By focusing on the number of paths with a specified number of hops, the determined link weights are relatively more accurate.
[0128] Furthermore, introducing weight coefficients makes the determination of link weights more objective and reasonable, preventing erroneous cases where weights exceed 1. Simultaneously, different link weights are determined based on the position of the sampled node within the candidate node sequence. Nodes with a large number of paths with a specified number of hops to the anchor node are considered to have non-zero link weights, determined based on the number of paths and the weight coefficient. Conversely, nodes with a small number of paths with a specified number of hops to the anchor node are considered to have zero link weights. This targeted selection ensures that the selected sampled nodes with non-zero link weights are more representative and relevant, better reflecting the relationship between nodes and anchor nodes. The training samples constructed based on this approach are more reasonable and accurate, and simultaneously improve training accuracy while reducing processing costs.
[0129] In addition, setting the specified number of hops to be the same as the number of aggregation layers in the graph neural network model can enable the graph neural network model to better process training samples and make the output feature information more accurate.
[0130] Therefore, the technical solution provided in this application can more accurately characterize the relationships between nodes, alleviating the problem of insufficient training for nodes with few neighbors (nodes connected to the anchor node by edges). Taking video recommendation scenarios as an example, the graph neural network model trained using the training samples constructed by the technical solution provided in this application can improve the recommendation effect for cold-start users and low-activity users, meaning that the videos recommended to users are more in line with their viewing habits.
[0131] In some embodiments, the sampling method is a mixture sampling + negative sample sampling. To improve feature learning for nodes with few neighbors, data augmentation is performed on the node features in the graph by generating synthetic nodes and soft links. The features of the positive and negative samples for each anchor node are linearly mixed. The features of the positive and negative samples for each anchor node are linearly mixed, and their links are fused accordingly.
[0132] Please refer to Figure 7This illustrates a flowchart of a graph-based sample sampling method provided in another embodiment of this application. The method can be... Figure 1 The method can be executed by terminal device 10 or server 20 in the implementation environment shown, or by both terminal device 10 and server 20. In the following method embodiments, for ease of description, only the execution subject of each step is referred to as "computer device". The method may include at least one of the following steps (310-440):
[0133] Step 310: Obtain graph structure information, which includes multiple nodes. Two nodes connected by an edge constitute a positive sample pair.
[0134] Step 410: Obtain sample node pairs of the anchor node. The sample node pairs include a first sample node and a second sample node. Both the first sample node and the second sample node are positive sample nodes of the anchor node, or the first sample node is a positive sample node of the anchor node and the second sample node is a negative sample node of the anchor node. Among them, a positive sample node refers to a node among multiple nodes that has an edge connection with the anchor node, and a negative sample node refers to a node among multiple nodes that does not have an edge connection with the anchor node.
[0135] In some embodiments, the sample node pair includes a first sample node and a second sample node, both of which are positive sample nodes of the anchor node.
[0136] like Figure 8 As shown, if nodes P1 and P2 are positive sample nodes anchored to node U, then nodes P1 and P2 are considered to be a sample node pair.
[0137] In some embodiments, a sample node pair includes a first sample node and a second sample node, wherein the first sample node is a positive sample node of the anchor node and the second sample node is a negative sample node of the anchor node.
[0138] like Figure 8 As shown, node P1 is a positive sample node of anchor node U, node N has no edge connection with anchor node U, and node N is a negative sample node of anchor node U. Therefore, node P1 and node N are considered to be a sample node pair.
[0139] Step 420: Determine the feature information of the hybrid node based on the feature information of the first sample node and the feature information of the second sample node; wherein, the hybrid node is a new node generated based on the first sample node and the second sample node.
[0140] In some embodiments, such as Figure 8As shown, nodes P1 and P2 are sample node pairs, and node M2 is considered to be a new node (hybrid node) generated based on the sample node pairs (nodes P1 and P2).
[0141] In some embodiments, such as Figure 8 As shown, node P1 and node N are also sample node pairs, and node M1 is a new node (hybrid node) generated based on the sample node pairs (node P1 and node N).
[0142] In some embodiments, step 420 includes step 421 (not shown in the figures).
[0143] Step 421: Based on the linear mixing coefficient, the feature information of the first sample node and the feature information of the second sample node are weighted and summed to obtain the feature information of the mixed node; where the linear mixing coefficient is a constant greater than 0 and less than 1.
[0144] In some embodiments, the linear mixing coefficients are randomly sampled from a dataset that follows a beta distribution. In some embodiments, the specific weight values for the weighted summation are not limited.
[0145] In some embodiments, such as Figure 8 As shown, when a mixed node is constructed by node N and node P1, the linear mixing coefficient is λ1. When a mixed node is constructed by node P2 and node P1, the linear mixing coefficient is λ2. λ1 and λ2 are randomly sampled from a dataset that follows a beta distribution; they can be the same or different.
[0146] Step 430: Determine the link weight between the anchor node and the hybrid node based on the link weight between the anchor node and the first sample node, and the link weight between the anchor node and the second sample node.
[0147] In some embodiments, step 430 includes step 431 (not shown in the figures).
[0148] Step 431: Based on the linear mixing coefficient, the link weights between the anchor node and the first sample node, and the link weights between the anchor node and the second sample node are weighted and summed to obtain the link weights between the anchor node and the mixed node.
[0149] In some embodiments, nodes are assigned from the positive samples, with positive links (links between nodes with edge connections) having a weight of 1 and negative links (links between nodes without edge connections) having a weight of 0. For each anchor node in the graph, the positively and negatively sampled nodes are transformed into links weighted by 1 and 0, respectively. Then, the positive and negative samples of an anchor node are linearly interpolated to generate new nodes and corresponding links. Specifically, the new pairing can be two positive samples, or one positive sample and one negative sample. The node representation is as follows:
[0150] e s =λe i +(1-λ)e j ,
[0151] w s =λw i +(1-λ)w j ,
[0152] Where e represents the characteristics of the synthesized node, w represents the link weight between the synthesized node and the anchor node, λ represents the coefficient of the linear mixture, which follows a Beta distribution. i and j represent nodes obtained by sampling the anchor node positively and negatively. s is the synthesized node. w represents the link weight.
[0153] Step 440: Based on anchor nodes, hybrid nodes, and the link weights between anchor nodes and hybrid nodes, construct the second training sample for the graph neural network model.
[0154] In some embodiments, the method further includes at least one of steps 450 to 460 (not shown in the figures).
[0155] Step 450: Using a graph neural network model, determine the prediction weights between the anchor nodes and the hybrid nodes based on the feature information of the anchor nodes and the feature information of the hybrid nodes.
[0156] Step 460: Determine the second loss function value of the graph neural network model based on the prediction weights between anchor nodes and hybrid nodes, and the link weights between anchor nodes and hybrid nodes.
[0157] In some embodiments, since the cross-entropy loss function is not suitable for soft links, the loss cannot be reduced to zero. To adapt to the representation of soft links, the mixed sampling loss function can optionally be as follows:
[0158]
[0159] in, This represents the value of the second loss function, where v represents the anchor node and s represents the hybrid node. Let σ represent the set of all mixed nodes, and let σ represent the sigmoid function. e represents the transpose of the eigenvector of the anchor node v. s w represents the feature vector of the mixed node s. s This represents the link weight of the hybrid node s. N represents the number of hybrid nodes.
[0160] In some embodiments, the above method further includes steps 510 to 520 (not shown in the figures).
[0161] Step 510: Randomly sample negative sample nodes of the anchor node from multiple nodes. Negative sample nodes are nodes among the multiple nodes that do not have an edge connection with the anchor node.
[0162] Step 520: Based on the anchor node, the negative sample node, and the link weights between the anchor node and the negative sample node, construct the third training sample for the graph neural network model.
[0163] In some embodiments, a graph neural network model is used to determine the prediction weights between anchor nodes and sampling nodes based on the feature information of anchor nodes and sampling nodes. Based on the prediction weights between anchor nodes and sampling nodes, and the link weights between anchor nodes and negative sample nodes, the value of the third loss function of the graph neural network model is determined.
[0164] In some embodiments, the loss function for negative sample sampling is as follows:
[0165]
[0166] in, This represents the value of the third loss function, where v represents the anchor node, and n... + Represents positive sample nodes, n - Indicates a negative sample node. Let σ represent the set of all positive and negative sample nodes, and let σ represent the sigmoid function. e represents the transpose of the eigenvector of the anchor node v. n This represents the feature vector of the negative sample node n.
[0167] In some embodiments, using the second and third training samples as training samples, the loss function for obtaining the final training samples is:
[0168] The technical solution provided in this application combines mixed sampling with negative sample sampling, which further enriches the form of sample construction, making the constructed samples more closely match the graph structure information itself. In other words, the constructed samples are richer, which is conducive to better representing the graph structure information in the form of samples, and facilitates the subsequent training of the graph neural network structure model.
[0169] Furthermore, constructing hybrid samples based on sample node pairs can enrich the types of nodes and further enrich the types of training samples. Simultaneously, in a sample node pair, both the first and second sample nodes are positive sample nodes of the anchor node, or the first sample node is a positive sample node of the anchor node and the second sample node is a negative sample node of the anchor node. By constructing hybrid nodes with other sample nodes, provided that at least one node is a positive sample node, the constructed hybrid samples will necessarily have strong training significance. Nodes that are both negative samples will not form a sample node pair to reduce unnecessary processing overhead.
[0170] Furthermore, introducing linear mixing coefficients that conform to the beta distribution enables the construction of mixed nodes to be more random while meeting the requirements, further enriching the forms of sample construction and making the constructed training samples more diverse.
[0171] In addition, the technical solution provided in this application, when nodes with few neighbors (nodes connected to the anchor node) are insufficiently trained, enriches the nodes constituting the sample by constructing hybrid nodes. This results in a larger number of samples participating in model training, which are also relatively closer to the graph structure information itself.
[0172] In this embodiment, the two sampling methods described above can be randomly combined. The first and third training samples can be obtained using a combination of decaying sampling and negative sample sampling, serving as training samples for the graph neural network structure model. Alternatively, the second and third training samples can be obtained using a combination of mixed sampling and negative sample sampling, serving as training samples for the graph neural network structure model. Of course, the first, second, and third training samples can also be obtained using a combination of decaying sampling, mixed sampling, and negative sample sampling, serving as training samples for the graph neural network structure model.
[0173] The following example illustrates the training process of a graph neural network model using a sampling method that combines decaying sampling, mixed sampling, and negative sample sampling. The decaying sampling + mixed sampling method can also be called mixed decaying sampling.
[0174] When the sampling method is hybrid attenuation sampling + negative sample sampling, the training samples include the first training sample, the second training sample, and the third training sample mentioned above. For example... Figure 9As shown, nodes D1 and D2 are sampling nodes, while nodes N and P1 form a sample node pair, nodes P1 and P2 form a sample node pair, nodes D2 and P2 form a sample node pair, and nodes M1, M2, and M3 are mixed nodes.
[0175] The loss function value of the graph neural network model is determined based on the prediction weights between anchor nodes and sampling nodes, the link weights between anchor nodes and sampling nodes, the prediction weights between anchor nodes and hybrid nodes, the link weights between anchor nodes and negative sample nodes, and the link weights between anchor nodes and negative sample nodes.
[0176] MixDec Sampling is a joint sampling process combining Mixup Sampling and Decay Sampling. Mixup Sampling synthesizes nodes and links, while Decay Sampling uses soft links to preserve the graph's structure. Since mixed sampling performs better on sparse graphs and decaying sampling performs better on dense graphs, mixed decaying sampling combines the advantages of both for graph optimization. The overall loss function is obtained by directly adding the loss function of negative sampling to the loss functions of mixed sampling and decaying sampling.
[0177]
[0178] in, For the overall loss function, The loss function for negative sampling. The loss function for mixed sampling, This is the loss function for attenuated sampling.
[0179] Based on the MixDec Sampling method, (1) it can more accurately depict the relationship between nodes in the graph and achieve higher MRR and Hit TopK performance on multiple datasets, that is, it can more accurately depict the relationship between users and content; (2) by synthesizing new nodes and edges, it can alleviate the problem of insufficient training of nodes with few neighbors, that is, improve the recommendation effect for cold start users and low active users.
[0180] To evaluate the effectiveness of the proposed method, the technical solution provided in this application was tested on three representative GNN recommendation models based on three benchmark datasets. The original default negative sampling in the three representative GNN models was replaced with our sampling method (i.e., mixed sampling, attenuated sampling, and mixed attenuated sampling), and its effectiveness was evaluated. The specific results are shown in Table 1.
[0181] The original negative sampling method performed the worst among all results because it simply forces the relationships between nodes into positive or negative sample pairs.
[0182] The technical solution provided in this application is the most effective in all metrics. This demonstrates the effectiveness of the soft-link-based sampling method for graph data augmentation of composite nodes and links in this scenario.
[0183] In most cases, attenuated sampling is superior to mixed sampling, indicating that preserving structural information during sampling is crucial.
[0184] Decaying sampling benefits more significantly in high-density maps. Specifically on the Last-FM dataset, decaying sampling can improve MRR by up to 44.62% and Hit@30 by up to 13.02%. Mixed sampling performs significantly better on low-density maps, such as the Amazon-Book and Yelp 2018 datasets.
[0185] This application further explores the generalization ability. Table 1 shows that among all GNN-based recommendation models, the strategy of the technical solution provided in this application consistently outperforms traditional negative sampling, demonstrating its universality. Compared to GraphSAGE and GAT, the hybrid decay sampling effect on GCN is significantly improved. This is because GCN originally had the worst performance. The method of the technical solution provided in this application greatly improves the poor-performing GNN model.
[0186] Table 1 compares the performance improvements of models obtained using different sampling methods for different data acquisition methods.
[0187]
[0188] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.
[0189] Please refer to Figure 10 The diagram illustrates a block diagram of a graph-based sample sampling device according to an embodiment of this application. The device 1000 may include: an information acquisition module 1010, a weight determination module 1020, and a sample construction module 1030.
[0190] The information acquisition module 1010 is used to acquire graph structure information, which includes multiple nodes, and two nodes connected by an edge constitute a positive sample pair.
[0191] The weight determination module 1020 is used to determine the link weight between the anchor node and the sampling node based on the number of paths between the anchor node and the sampling node among the plurality of nodes; wherein the sampling node is a node among the plurality of nodes that does not have an edge connection with the anchor node.
[0192] The sample construction module 1030 is used to construct a first training sample for a graph neural network model based on the anchor node, the sampling node, and the link weights between the anchor node and the sampling node; wherein the graph neural network model is used to extract features from the graph structure information.
[0193] In some embodiments, such as Figure 11 As shown, the weight determination module 1020 includes a quantity determination unit 1022, a node determination unit 1024, and a weight determination unit 1026.
[0194] The quantity determination unit 1022 determines the number of paths with a specified number of hops between the anchor node and the sampling node as the number of sampling paths.
[0195] The node determination unit 1024 determines a target node and the maximum number of paths corresponding to the target node from the plurality of nodes; wherein, the target node is the node with the most paths having the specified number of hops between it and the anchor node, and the maximum number of paths is the number of paths having the specified number of hops between the anchor node and the target node.
[0196] The weight determination unit 1026 determines the link weight between the anchor node and the sampling node based on the number of sampling paths and the maximum number of paths.
[0197] In some embodiments, the weight determination unit 1026 is used to calculate the quotient of the number of sampling paths and the maximum number of paths.
[0198] The weight determination unit 1026 is used to multiply the difference between 1 and the weight coefficient by the quotient, and add the product to the weight coefficient to obtain the link weight between the anchor node and the sampling node; wherein the weight coefficient is a constant greater than 0 and less than 1.
[0199] In some embodiments, such as Figure 11 As shown, the weight determination module 1020 further includes a weight acquisition unit 1027 and a sequence determination unit 1028.
[0200] The weight acquisition unit 1027 acquires the link weights corresponding to each candidate node reached from the anchor node by a path with the specified number of hops; wherein the link weights corresponding to the candidate nodes are determined based on the number of paths with the specified number of hops between the anchor node and the candidate node, and the maximum number of paths.
[0201] The sequence determination unit 1028 sorts the link weights corresponding to each candidate node in descending order to obtain a candidate node sequence.
[0202] The weight determination unit 1026 is further configured to determine the link weight corresponding to the sampling node as the link weight between the anchor node and the sampling node determined according to the number of sampling paths and the maximum number of paths if the sampling node is located in the first D positions of the candidate node sequence.
[0203] The weight determination unit 1026 is further configured to determine 0 as the link weight corresponding to the sampling node if the sampling node is not located in the first D positions of the candidate node sequence, where D is a positive integer.
[0204] In some embodiments, the specified number of hops is the same as the number of aggregation layers in the graph neural network model.
[0205] In some embodiments, such as Figure 11 As shown, the device 1000 also includes a function value determination module 1040.
[0206] The weight determination module 1020 is further configured to determine the prediction weight between the anchor node and the sampling node based on the feature information of the anchor node and the feature information of the sampling node through the graph neural network model.
[0207] The function value determination module 1040 is used to determine the first loss function value of the graph neural network model based on the prediction weight between the anchor node and the sampling node, and the link weight between the anchor node and the sampling node.
[0208] In some embodiments, such as Figure 11 As shown, the device 1000 also includes a node pair acquisition module 1050 and an information determination module 1060.
[0209] The node pair acquisition module 1050 is used to acquire sample node pairs of the anchor node. The sample node pairs include a first sample node and a second sample node. Both the first sample node and the second sample node are positive sample nodes of the anchor node, or the first sample node is a positive sample node of the anchor node and the second sample node is a negative sample node of the anchor node. The positive sample node refers to a node among the plurality of nodes that has an edge connection with the anchor node, and the negative sample node refers to a node among the plurality of nodes that does not have an edge connection with the anchor node.
[0210] The information determination module 1060 is used to determine the feature information of the hybrid node based on the feature information of the first sample node and the feature information of the second sample node; wherein the hybrid node is a new node generated based on the first sample node and the second sample node.
[0211] The weight determination module 1020 is further configured to determine the link weight between the anchor node and the hybrid node based on the link weight between the anchor node and the first sample node, and the link weight between the anchor node and the second sample node.
[0212] The sample construction module 1030 is further configured to construct a second training sample for the graph neural network model based on the anchor node, the hybrid node, and the link weights between the anchor node and the hybrid node.
[0213] In some embodiments, the information determination module 1060 is used to perform a weighted summation of the feature information of the first sample node and the feature information of the second sample node based on a linear mixing coefficient to obtain the feature information of the mixed node.
[0214] The weight determination module 1020 is further configured to perform a weighted summation of the link weights between the anchor node and the first sample node, and the link weights between the anchor node and the second sample node, based on the linear mixing coefficient, to obtain the link weights between the anchor node and the mixed node; wherein, the linear mixing coefficient is a constant greater than 0 and less than 1.
[0215] In some embodiments, the linear mixing coefficients are obtained by random sampling from a dataset that follows a beta distribution.
[0216] In some embodiments, the weight determination module 1020 is further configured to determine the prediction weight between the anchor node and the hybrid node based on the feature information of the anchor node and the feature information of the hybrid node through the graph neural network model.
[0217] The function value determination module 1040 is further configured to determine the second loss function value of the graph neural network model based on the prediction weights between the anchor node and the hybrid node, and the link weights between the anchor node and the hybrid node.
[0218] In some embodiments, such as Figure 11 As shown, the device 1000 also includes a node sampling module 1070.
[0219] The node sampling module 1070 is used to randomly sample negative sample nodes of the anchor node from the plurality of nodes. The negative sample nodes refer to nodes among the plurality of nodes that do not have an edge connection with the anchor node.
[0220] The sample construction module 1030 is further configured to construct a third training sample for the graph neural network model based on the anchor node, the negative sample node, and the link weights between the anchor node and the negative sample node.
[0221] The technical solution provided in this application determines the link weights between anchor nodes and sampling nodes based on the number of paths between them in the graph structure information. Based on the anchor nodes, sampling nodes, and the link weights between them, training samples for the graph neural network model are constructed. This application determines the link weights based on the number of paths between anchor nodes and sampling nodes, making the determined link weights more consistent with the graph structure information. The training samples determined based on these link weights are also closer to the graph structure itself. Naturally, the training samples are also richer, which helps to increase the quantity and richness of training samples extracted from the graph structure information, thereby improving the robustness of subsequently training the graph neural network model using these obtained training samples.
[0222] It should be noted that the apparatus provided in the above embodiments is only illustrated by the division of the above functional modules when implementing its functions. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0223] Figure 12 A structural block diagram of a computer device provided in an exemplary embodiment of this application is shown. The computer device may be a terminal device or a server.
[0224] Typically, computer device 1200 includes a processor 1201 and a memory 1202.
[0225] Processor 1201 may include one or more processing cores, such as a quad-core processor, a twelfth-core processor, etc. Processor 1201 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field Programmable Gate Array), and PLA (Programmable Logic Array). Processor 1201 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 1201 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, processor 1201 may also include an AI processor for handling computational operations related to machine learning.
[0226] The memory 1202 may include one or more computer-readable storage media, which may be tangible and non-transitory. The memory 1202 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 1202 stores a computer program that is loaded and executed by the processor 1201 to implement the graph-based sample sampling method provided in the above-described method embodiments.
[0227] Those skilled in the art will understand that Figure 12 The structure shown does not constitute a limitation on the computer device 1200 and may include more or fewer components than shown, or combine certain components, or use different component arrangements.
[0228] In an exemplary embodiment, a computer-readable storage medium is also provided, wherein a computer program is stored therein, which, when executed by a processor, implements the graph-based sample sampling method.
[0229] Optionally, the computer-readable storage medium may include: ROM (Read-Only Memory), RAM (Random Access Memory), SSD (Solid State Drives), or optical disc, etc. The random access memory may include ReRAM (Resistance Random Access Memory) and DRAM (Dynamic Random Access Memory).
[0230] In an exemplary embodiment, a computer program product is also provided, the computer program product including 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, causing the computer device to perform the graph-based sample sampling method described above.
[0231] It should be understood that "multiple" as used herein refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. Furthermore, the step numbers described herein are merely illustrative of one possible execution order. In some other embodiments, the steps may not be executed in numerical order, such as two steps with different numbers being executed simultaneously, or two steps with different numbers being executed in the reverse order of the illustration. This application does not limit this.
[0232] The above description is merely an exemplary embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A sample sampling method based on a graph structure, characterized in that, The method comprises: obtaining graph structure information, the graph structure information comprising a plurality of nodes, two nodes connected by an edge forming a positive sample pair, the graph structure information being formed based on a data stream of an existing interaction relationship, the data stream comprising a data stream of user viewing content, the nodes corresponding to users or content; for an anchor node in the plurality of nodes, obtaining a sample node pair of the anchor node, the sample node pair comprising a first sample node and a second sample node, the first sample node and the second sample node both being positive sample nodes of the anchor node, or the first sample node being a positive sample node of the anchor node and the second sample node being a negative sample node of the anchor node; wherein the positive sample node refers to a node in the plurality of nodes having an edge connection with the anchor node, and the negative sample node refers to a node in the plurality of nodes not having an edge connection with the anchor node; determining feature information of a mixed node based on feature information of the first sample node and feature information of the second sample node; wherein the mixed node is a new node generated based on the first sample node and the second sample node; determining a link weight between the anchor node and the mixed node based on a link weight between the anchor node and the first sample node and a link weight between the anchor node and the second sample node; based on the anchor node, the mixed node, and the link weight between the anchor node and the mixed node, constructing a second training sample of a graph neural network model, the graph neural network model being used to extract features in the graph structure information to recommend content to a user.
2. The method of claim 1, wherein, The method further comprises: determining a link weight between the anchor node and a sample node based on a number of paths between the anchor node and the sample node; wherein the sample node is a node in the plurality of nodes not having an edge connection with the anchor node; based on the anchor node, the sample node, and the link weight between the anchor node and the sample node, constructing a first training sample of the graph neural network model.
3. The method of claim 2, wherein, The determination of the link weight between the anchor node and the sample node based on the number of paths between the anchor node and the sample node comprises: determining the number of paths between the anchor node and the sample node having a specified number of hops as a sample path number; determining a target node from the plurality of nodes and a maximum path number corresponding to the target node; wherein the target node refers to a node having the most number of paths with the specified number of hops between the anchor node and the target node, and the maximum path number refers to the number of paths with the specified number of hops between the anchor node and the target node; determining the link weight between the anchor node and the sample node based on the sample path number and the maximum path number.
4. The method of claim 3, wherein, The determination of the link weight between the anchor node and the sample node based on the sample path number and the maximum path number comprises: calculating a quotient of the sample path number and the maximum path number; Multiplying the difference between 1 and the weight coefficient by the quotient to obtain a product, and adding the weight coefficient to the product to obtain a link weight between the anchor node and the sampling node, wherein the weight coefficient is a constant greater than 0 and less than 1.
5. The method of claim 3, wherein, The method further comprises: obtaining a link weight corresponding to each candidate node reached by a path with the specified hop number starting from the anchor node; wherein the link weight corresponding to the candidate node is determined according to a number of paths with the specified hop number between the anchor node and the candidate node and the maximum path number; sorting the link weights corresponding to the candidate nodes in descending order to obtain a candidate node sequence; if the sampling node is located in the first D positions in the candidate node sequence, determining the link weight between the anchor node and the sampling node according to the sampling path number and the maximum path number as the link weight corresponding to the sampling node; if the sampling node is not located in the first D positions in the candidate node sequence, determining 0 as the link weight corresponding to the sampling node, and D is a positive integer.
6. The method of claim 3, wherein, The specified hop number is the same as the number of aggregation layers in the graph neural network model.
7. The method of claim 2, wherein, The method further comprises: determining, by the graph neural network model, a predicted weight between the anchor node and the sampling node according to the feature information of the anchor node and the feature information of the sampling node; determining a first loss function value of the graph neural network model based on the predicted weight between the anchor node and the sampling node and the link weight between the anchor node and the sampling node.
8. The method according to any one of claims 2 to 7, characterized in that, The anchor node corresponds to a user, the sampling node corresponds to content, and the link weight between the anchor node and the sampling node is used to represent the degree of interest of the user in the content.
9. The method of claim 1, wherein, The determination of the feature information of the mixed node according to the feature information of the first sample node and the feature information of the second sample node comprises: performing weighted summation on the feature information of the first sample node and the feature information of the second sample node based on a linear mixing coefficient to obtain the feature information of the mixed node; The determination of the link weight between the anchor node and the mixed node according to the link weight between the anchor node and the first sample node and the link weight between the anchor node and the second sample node comprises: performing weighted summation on the link weight between the anchor node and the first sample node and the link weight between the anchor node and the second sample node based on the linear mixing coefficient to obtain the link weight between the anchor node and the mixed node; wherein the linear mixing coefficient is a constant greater than 0 and less than 1.
10. The method of claim 9, wherein, The linear mixing coefficient is randomly sampled from a data set subject to a Beta distribution.
11. The method of claim 1, wherein, The method further comprises: determining, by the graph neural network model, a predicted weight between the anchor node and the mixed node according to the feature information of the anchor node and the feature information of the mixed node; determine a second loss function value of the graph neural network model based on the predicted weight between the anchor node and the hybrid node and the link weight between the anchor node and the hybrid node.
12. The method of claim 1, wherein, The method further includes: randomly sampling a negative sample node of the anchor node from the plurality of nodes, the negative sample node being a node in the plurality of nodes that does not have an edge connection with the anchor node; constructing a third training sample of the graph neural network model based on the anchor node, the negative sample node, and a link weight between the anchor node and the negative sample node.
13. A sample sampling device based on a graph structure, characterized by, The device includes: an information obtaining module configured to obtain graph structure information, the graph structure information including a plurality of nodes, two nodes having an edge connection constituting a positive sample pair, the graph structure information being formed based on a data stream in which an interaction relationship exists, the data stream including a data stream in which a user views content, the nodes corresponding to users or content; a weight determining module configured to, for an anchor node in the plurality of nodes, obtain a sample node pair of the anchor node, the sample node pair including a first sample node and a second sample node, the first sample node and the second sample node both being positive sample nodes of the anchor node or the first sample node being a positive sample node of the anchor node and the second sample node being a negative sample node of the anchor node; wherein the positive sample node is a node in the plurality of nodes that has an edge connection with the anchor node, and the negative sample node is a node in the plurality of nodes that does not have an edge connection with the anchor node; the weight determining module is further configured to determine feature information of a hybrid node based on feature information of the first sample node and feature information of the second sample node; wherein the hybrid node is a new node generated based on the first sample node and the second sample node; the weight determining module is further configured to determine a link weight between the anchor node and the hybrid node based on a link weight between the anchor node and the first sample node and a link weight between the anchor node and the second sample node; a sample constructing module configured to construct a second training sample of a graph neural network model based on the anchor node, the hybrid node, and a link weight between the anchor node and the hybrid node, the graph neural network model being used to extract features in the graph structure information to recommend content to a user.
14. A computer device, comprising: The computer device includes a processor and a memory, the memory storing a computer program, the computer program being loaded and executed by the processor to implement the method of any one of claims 1 to 12.
15. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, the computer program being loaded and executed by a processor to implement the method of any one of claims 1 to 12.
16. A computer program product, characterised in that, The computer program product comprises a computer program stored in a computer readable storage medium, which is read and executed by a processor to implement the method according to any one of claims 1 to 12.