A friend recommendation method in social networks based on subgraph sampling
By using sub-graph sampling and graph neural networks in social networks, the problem of difficulty in making full use of high-order user interaction information in the prior art is solved, and more accurate and high-quality friend recommendations are achieved.
Patent Information
- Application Number
- CN202411346447.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-26
- Publication Date
- 2025-03-07
- Estimated Expiration
- 2044-09-26
AI Technical Summary
The existing social network friend recommendation methods are difficult to make full use of advanced user interaction information, resulting in inaccurate recommendation results.
Using a method based on subgraph sampling, the user node weight is evaluated by the rebooted heterogeneous nodes, a homoproton graph is constructed, and a graph neural network is used to calculate the similarity between users for friend recommendation.
It improves the accuracy of friend recommendations in social networks, reduces modeling information loss, obtains high-quality user node representations, and realizes high-precision friend recommendations.
Smart Images

Figure CN118861435B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of social network data processing, and in particular to a social network friend recommendation method based on subgraph sampling. Background Art
[0002] Social networks are composed of social entities and their relationships and interactions, including complex relationships between people in the real world. As social networks continue to develop, the information they contain is becoming richer and richer. Friend recommendation refers to the analysis of social networks through certain methods to recommend other users with similar interests and hobbies to users, which has important applications in reality. For example, in online social platforms, friend recommendation can improve user experience, increase user activity on the platform, and enhance the commercial value of the software.
[0003] Existing friend recommendation methods usually calculate the similarity between users in social networks and push other users with high similarity to users to achieve friend recommendation. They can be further divided into methods based on indicators, network embedding, and graph neural networks. Most of the methods based on indicators are heuristic methods. These methods are highly interpretable and work well on small-scale social networks, but they do not fully utilize topological information and have low recommendation accuracy. The network embedding-based method obtains low-dimensional vectors of user nodes through matrix decomposition or machine learning methods, and then calculates vector similarity as the similarity value between users to perform recommendations. Compared with the indicator-based method, it can achieve better recommendation results, but in the process of network embedding, it rarely combines the user's own attribute information, and does not optimize the recommendation task in a targeted manner. The graph neural network-based method can more fully combine the semantic information and attribute information of the network to obtain more accurate recommendation results in an end-to-end manner, but the existing related methods cannot fully utilize high-order user interaction information, and there are information loss or redundancy problems, resulting in inaccurate friends recommended to users. Summary of the invention
[0004] To this end, the purpose of the present invention is to provide a social network friend recommendation method based on subgraph sampling, which uses heterogeneous node pairs with restarts to evaluate user node weights, makes full use of high-order user interaction information, simplifies the modeled heterogeneous graph into homogeneous subgraphs, calculates the similarity between users through graph neural networks, makes friend recommendations, and improves the accuracy of friend recommendations in social networks.
[0005] A social network friend recommendation method based on subgraph sampling comprises the following steps:
[0006] S1, read the social network database, process the outliers and missing values, set the meta-path and construct a heterogeneous graph; calculate the size of the corresponding homogeneous subgraph of the user node pair whose similarity is to be obtained, and use the random walk of the heterogeneous node pair with restart to capture the weight values of the remaining user nodes, select the user nodes from large to small according to the weight value, and construct a homogeneous subgraph;
[0007] S2, input the heterogeneous graph into the Metapath2vec model to obtain the initial vector of each user node; the weight value of each user node captured by random walk is processed and position encoded to obtain the weight vector; the weight vector and the initial vector are concatenated to obtain the feature vector;
[0008] S3, input the homogeneous subgraph and the feature vector of each user node into the graph neural network model DGCNN to obtain the embedding vector of each user node, concatenate the embedding vectors of the user node pairs to obtain similarity, form a user pair representation vector, and then input it into the multi-layer perceptron to obtain the similarity value between users. When the similarity value is greater than the threshold, perform friend recommendation; use the Ranking Loss loss function to calculate the loss value, and use back propagation to adjust all learnable parameters.
[0009] The social network friend recommendation method based on subgraph sampling provided by the present invention has the following beneficial effects:
[0010] (1) The present invention has a small modeling information loss: Traditional methods usually model social networks as homogeneous graphs, ignoring the heterogeneity of information and interactions, resulting in a large information loss. The present invention fully considers the above characteristics, models social networks as heterogeneous graphs, and retains rich semantic information;
[0011] (2) The present invention has high-quality user node representation: There are a large number of different types of nodes on a heterogeneous graph. Directly processing them is likely to lose important information, and the quality of the obtained user node representation vector is low. The present invention identifies important user nodes and constructs subgraphs through random walks of heterogeneous nodes with restarts. While avoiding the existence of redundant nodes or excluding important nodes in the subgraph, it fully utilizes the multi-order interaction information between users and can obtain high-quality user node representation vectors.
[0012] (3) The present invention has high-precision friend recommendation: The present invention uses graph neural networks and multi-layer perceptrons to calculate the similarity between users, better combining heterogeneous graph topology information with downstream tasks, and the obtained user similarity is more accurate, which can achieve high-accuracy friend recommendation.
[0013] In summary, the present invention can eliminate redundant information, enrich node features, generate high-quality user node representation vectors based on user attributes and user interaction data in social networks through random walks and subgraph sampling, and thus provide more accurate friend recommendations and improve user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] Figure 1 A schematic diagram of the process of the social network friend recommendation method based on subgraph sampling provided by the present invention;
[0015] Figure 2 This is an example diagram of a random walk of a heterogeneous node pair with restart in one embodiment of the present invention;
[0016] Figure 3 This is an example diagram of constructing a homogeneous subgraph corresponding to a user node pair (u, v) for which similarity is to be obtained in a heterogeneous graph G in one embodiment of the present invention. DETAILED DESCRIPTION
[0017] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0018] See also Figure 1 The present invention provides a social network friend recommendation method based on subgraph sampling, comprising steps S1 to S3:
[0019] S1, read the social network database, process the outliers and missing values, set the meta-path and construct a heterogeneous graph; calculate the size of the corresponding homogeneous subgraph of the user node pair whose similarity is to be obtained, and use the random walk of the heterogeneous node pair with restart to capture the weight values of the remaining user nodes, select the user nodes from large to small according to the weight value, and construct a homogeneous subgraph.
[0020] Wherein, step S1 specifically includes:
[0021] S11, read the social network database, process the outliers and missing values, set the meta-path and construct the heterogeneous graph;
[0022] Specifically, we read user attributes and interaction information from the social network database, and use the random forest algorithm to fill in missing values and outliers. We abstract users and attributes into nodes, and abstract the interaction relationships between users and the relationships between users and attributes into edges to construct a heterogeneous graph. G =( V , E, VT , ET ),in V It is a node collection; it includes user nodes and attribute nodes; E is an edge set, including the attention relationship between users; VT is a node type collection, ET is a set of edge types. Then, set the meta path MP ={ MP 1, MP 2, …, MP m},in m represents the number of meta-paths set. Since friend recommendations are made for users in social networks, the meta-paths set should all be symmetric meta-paths, denoted as ,in MP i The length of the metapath is n , VT 1. VT 2 for VT The elements in ET 1. ET 2. ET n for ET The elements in .
[0023] S12, calculating the density and average degree of the heterogeneous graph, obtaining the influence of each set meta-path, and then determining the size of the corresponding homogeneous subgraph of the user node pair to be obtained for similarity;
[0024] Among them, the graph density describes the closeness of the connection between the nodes in the graph, and the calculation formula is as follows:
[0025] ;
[0026] in, is the heterogeneous graph density, is the number of edges in the heterogeneous graph, is the number of nodes in the heterogeneous graph.
[0027] Average degree refers to the average value of the degrees of each node in the graph, which is used to describe the degree of clustering of the graph. The calculation formula is as follows:
[0028] ;
[0029] in, is the average degree of the heterogeneous graph, For user nodes i The degree value.
[0030] Then, the influence of each set meta-path is calculated according to its length, as shown in the following formula:
[0031] ;
[0032] in, Metapath MP i The influence of Indicates the maximum length of the meta-path operation, Metapath MP i Length.
[0033] In step S12, the calculation formula of the homogeneous subgraph size is:
[0034] ;
[0035] in, size represents the size of the homogeneous subgraph, distance ( u , v ) is the user node pair whose similarity is to be obtained ( u , v ), AHr ( G ) is the average degree of the heterogeneous graph, mpl is the average length of the meta-path, , D ( G ) is the heterogeneous graph density, and ⌈⌉ represents the rounding up operation.
[0036] S13, executing a random walk of heterogeneous node pairs with restart on the heterogeneous graph to obtain the number of sampling times of each user node, and then calculating the weight value;
[0037] Step S13 specifically includes:
[0038] Determine the random walk parameters, which include the walk length, the number of walks, and the restart probability. Perform the random walk. At the beginning of each random walk, start the walk from one of the user node pairs whose similarity is to be obtained with equal probability. When walking to any node, first determine whether to restart the random walk. If restarted, directly end the current walk and start the next walk. Otherwise, find all the meta-path neighbors of the node according to the set meta-path set, obtain the node influence by accumulating the influence of all meta-paths between nodes, and calculate the transfer probability using the following formula:
[0039] ;
[0040] in, For user nodes i Walk to the user node j The probability of For user nodesj Relative to user node i The influence of k For user nodes i The meta-path neighbors of For user nodes i The set of meta-path neighbors of Y is the set of user nodes sampled during this random walk, To connect to the user node i With user node j The set of meta-paths of is the and symbol, is the or symbol, and ∅ is an empty set. i With user node j Depend on MP i If the meta-paths are connected, the user node is considered i Is a user node j exist MP i Neighbors under a meta-path (referred to as meta-path neighbors).
[0041] Specifically, in this embodiment, at the beginning of each random walk, a 50% probability is set to u Start walking, otherwise v Start walking. When walking to the user node i , determine whether to restart the random walk. If so, end the current random walk and start the next random walk directly. Otherwise, MP Finding User Nodes i Considering that there may be multiple meta-paths connecting two nodes, the present invention calculates the node influence and obtains the transition probability. Represents a user node j Relative to user node i The influence of By connecting user nodes i With user node j When there is no meta-path connecting the user nodes or the user node has been sampled in this random walk, its influence is set to 0, so that the next step will not walk to such a node.
[0042] See also Figure 2 , Figure 2 The circular nodes in the middle represent user nodes, and the dotted lines in Figure 2 represent all possible walking paths. Suppose the current random walk to the user node i ,but NMP i ={1, 2}, user node 1 for user node iThe influence value of user node 2 is equal to the influence value of meta-path 1. i The influence value of user node 3 is equal to 2 times the influence value of setting meta-path 2. i The influence value will be set to 0.
[0043] When a random walk has sampled enough user nodes or cannot select the next walk node, the random walk will be terminated, and the next random walk will start after recording all the user nodes sampled this time. When the number of walks reaches the upper limit, the random walk algorithm will terminate.
[0044] In step S13, the weight value is calculated as follows:
[0045] ;
[0046] in, For user nodes i The weight value of For user nodes i The number of times it is sampled in the random walk, t is the number of random walks, u , v is a user node. u , v ) must appear in homogeneous subgraphs, and their weight values will be set to 1 (maximum value).
[0047] S14, sorting all user nodes in the network from large to small according to weight, and selecting a preset number of user nodes in the sequence to construct a homogeneous subgraph according to the corresponding homogeneous subgraph size.
[0048] Among them, all user nodes are sorted from large to small according to the weight value, and the first one in the sequence is selected. size Homogeneous subgraphs G homo . When some user nodes have equal weight values, the one with ( u , v )The user nodes with the smallest sum of distances are selected. If they are still equal, these user nodes are randomly selected.
[0049] An example is Figure 3 As shown, the user nodes are circular nodes, and the weights of the remaining user nodes are obtained by random walk of heterogeneous node pairs with restart. After sorting, the first 5 user nodes are taken to form a homogeneous subgraph.
[0050] S2, input the heterogeneous graph into the Metapath2vec model to obtain the initial vector of each user node; the weight value of each user node captured by random walk is processed and position encoded to obtain the weight vector; the weight vector and the initial vector are concatenated to obtain the feature vector.
[0051] Wherein, step S2 specifically includes:
[0052] S21, the heterogeneous graph G Input into the Metapath2vec model to obtain the initial vector of each user node. The expression is as follows:
[0053] ;
[0054] in, is the initial vector matrix, which is composed of the initial vectors of each node.
[0055] S22, processing the weight values of all user nodes in the homogeneous subgraph and inputting them into the position code to obtain the weight vector of each user node;
[0056] Wherein, step S22 specifically includes:
[0057] The weight values of all user nodes in the homogeneous subgraph are processed as follows:
[0058] ;
[0059] in, For processed user nodes i The weight value of , ⌊⌋ represents the rounding down operation, Indicates the operation of taking the minimum weight value. Indicates the operation of taking the maximum weight value;
[0060] After obtaining the processed weight value, the weight vector of each user node is calculated using the following formula:
[0061] ;
[0062] in, For user nodes i The weight vector is given by d w Elements for The first element in for The d w elements; for No. POS elements; d wis the weight vector dimension, express POS Modulo 2 operation.
[0063] S23, concatenate the initial vector and weight vector of each user node to form a feature vector, which is expressed as follows:
[0064] ;
[0065] in, For user nodes i The characteristic vector of for The i Row element, representing a user node i The embedding vector of Represents a vector concatenation operation.
[0066] S3, input the homogeneous subgraph and the feature vector of each user node into the graph neural network model DGCNN to obtain the embedding vector of each user node, concatenate the embedding vectors of the user node pairs to obtain similarity, form a user pair representation vector, and then input it into the multi-layer perceptron to obtain the similarity value between users. When the similarity value is greater than the threshold, perform friend recommendation; use the Ranking Loss loss function to calculate the loss value, and use back propagation to adjust all learnable parameters.
[0067] Wherein, step S3 specifically includes:
[0068] S31, input the feature matrix composed of the feature vectors of each user node and the homogeneous subgraph into the graph neural network model DGCNN to obtain the embedding vector of each user node, which is expressed as follows:
[0069] ;
[0070] in, is the embedding matrix obtained by the graph neural network; is the feature matrix of the homogeneous subgraph, which is composed of the feature vectors of each user node in the subgraph. u , v ) Their respective embedding vectors can be obtained by and express, and They are No. u Row elements and v Row element.
[0071] S32, assembling respective embedding vectors of the user node pairs whose similarities are to be obtained to form a user pair representation vector;
[0072] Among them, the concatenated embedding vector and ,form( u , v )’s user pair representation vector ;
[0073] S33, input the user pair representation vector into the multi-layer perceptron for processing, and obtain the user pair similarity value, which is expressed as follows:
[0074] ;
[0075] in, express( u , v ), and are the weight matrix and bias matrix of the first layer of the multilayer perceptron, and They are the weight matrix and bias matrix of the second layer of the multilayer perceptron respectively. represents the RELU activation function, Represents the Sigmoid activation function.
[0076] S34, sampling positive sample node pairs and negative sample node pairs to train the model, where the positive and negative sample ratio will be set to 1:1, and after obtaining the similarity value, the Ranking Loss loss function is used to calculate the loss value, and back propagation is used to adjust all learnable parameters;
[0077] Among them, the loss value The calculation formula is:
[0078] ;
[0079] in, E p represents the set of positive sample pairs, represents a positive sample pair, E n represents the set of negative sample pairs, represents a negative sample pair, for The similarity value of for To prevent the imbalance of positive and negative samples, the ratio of positive samples to negative samples is set to 1:1.
[0080] S35, selecting other users whose similarity value with the current user is greater than a threshold to perform recommendation.
[0081] The social network friend recommendation method based on subgraph sampling provided by the present invention has the following beneficial effects:
[0082] (1) The present invention has a small modeling information loss: Traditional methods usually model social networks as homogeneous graphs, ignoring the heterogeneity of information and interactions, resulting in a large information loss. The present invention fully considers the above characteristics, models social networks as heterogeneous graphs, and retains rich semantic information;
[0083] (2) The present invention has high-quality user node representation: There are a large number of different types of nodes on a heterogeneous graph. Directly processing them is likely to lose important information, and the quality of the obtained user node representation vector is low. The present invention identifies important user nodes and constructs subgraphs through random walks of heterogeneous nodes with restarts. While avoiding the existence of redundant nodes or excluding important nodes in the subgraph, it fully utilizes the multi-order interaction information between users and can obtain high-quality user node representation vectors.
[0084] (3) The present invention has high-precision friend recommendation: The present invention uses graph neural networks and multi-layer perceptrons to calculate the similarity between users, better combining heterogeneous graph topology information with downstream tasks, and the obtained user similarity is more accurate, which can achieve high-accuracy friend recommendation.
[0085] In summary, the present invention can eliminate redundant information, enrich node features, generate high-quality user node representation vectors based on user attributes and user interaction data in social networks through random walks and subgraph sampling, and thus provide more accurate friend recommendations and improve user experience.
[0086] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.
[0087] Although the embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.
Claims
1. A social network friend recommendation method based on subgraph sampling, characterized in that: The following steps are involved: S1, read the social network database, process the outliers and missing values, set the meta-path and construct a heterogeneous graph; calculate the size of the corresponding homogeneous subgraph of the user node pair whose similarity is to be obtained, and use the random walk of the heterogeneous node pair with restart to capture the weight values of the remaining user nodes, select the user nodes from large to small according to the weight value, and construct a homogeneous subgraph; S2, input the heterogeneous graph into the Metapath2vec model to obtain the initial vector of each user node; the weight value of each user node captured by random walk is processed and position encoded to obtain the weight vector; the weight vector and the initial vector are concatenated to obtain the feature vector; S3, input the homogeneous subgraph and the feature vector of each user node into the graph neural network model DGCNN to obtain the embedding vector of each user node, concatenate the embedding vectors of the user node pairs to obtain the similarity, form the user pair representation vector, and then input it into the multi-layer perceptron to obtain the similarity value between users. When the similarity value is greater than the threshold, perform friend recommendation; Use the Ranking Loss function to calculate the loss value and use back propagation to adjust all learnable parameters; Step S1 specifically includes: S11, read the social network database, process the outliers and missing values, set the meta-path and construct the heterogeneous graph; S12, calculating the density and average degree of the heterogeneous graph, obtaining the influence of each set meta-path, and then determining the size of the corresponding homogeneous subgraph of the user node pair to be obtained for similarity; S13, executing a random walk of heterogeneous node pairs with restart on the heterogeneous graph to obtain the number of sampling times of each user node, and then calculating the weight value; S14, sorting all user nodes in the network from large to small according to weight, and selecting a preset number of user nodes in the sequence to construct a homogeneous subgraph according to the corresponding homogeneous subgraph size; Step S13 specifically includes: Determine the random walk parameters, which include the walk length, the number of walks, and the restart probability. Perform the random walk. At the beginning of each random walk, start the walk from one of the user node pairs whose similarity is to be obtained with equal probability. When walking to any node, first determine whether to restart the random walk. If restarted, directly end the current walk and start the next walk. Otherwise, find all the meta-path neighbors of the node according to the set meta-path set, obtain the node influence by accumulating the influence of all meta-paths between nodes, and calculate the transfer probability using the following formula: ; in, For user nodes i Walk to the user node j The probability of For user nodes j Relative to user node i The influence of k For user nodes i The meta-path neighbors of For user nodes i The set of meta-path neighbors of Y is the set of user nodes sampled during this random walk, To connect to the user node i With user node j The set of meta-paths of is the and symbol, is the or symbol, and ∅ is the empty set.
2. The social network friend recommendation method based on subgraph sampling according to claim 1, characterized in that: In step S12, the calculation formula of the homogeneous subgraph size is: ; in, size represents the size of the homogeneous subgraph, distance ( u , v ) is the user node pair whose similarity is to be obtained ( u , v ), AHr ( G ) is the average degree of the heterogeneous graph, mpl is the average length of the meta-path, D ( G ) is the heterogeneous graph density, and ⌈⌉ represents the rounding up operation.
3. The social network friend recommendation method based on subgraph sampling according to claim 1, characterized in that: In step S13, the weight value is calculated as follows: ; in, For user nodes i The weight value of For user nodes i The number of times it is sampled in the random walk, t is the number of random walks, u , v For user nodes.
4. The social network friend recommendation method based on subgraph sampling according to claim 1, characterized in that: Step S2 specifically includes: S21, the heterogeneous graph G Input into the Metapath2vec model to obtain the initial vector of each user node; S22, processing the weight values of all user nodes in the homogeneous subgraph and inputting them into the position code to obtain the weight vector of each user node; S23, concatenating the initial vector and weight vector of each user node to form a feature vector.
5. The social network friend recommendation method based on subgraph sampling according to claim 4, characterized in that: Step S22 specifically includes: The weight values of all user nodes in the homogeneous subgraph are processed as follows: ; in, For processed user nodes i The weight value of , ⌊⌋ represents the rounding down operation, Indicates the operation of taking the minimum weight value. Indicates the operation of taking the maximum weight value; After obtaining the processed weight value, the weight vector of each user node is calculated using the following formula: ; in, For user nodes i The weight vector is given by d w Elements for The first element in for The d w elements; for No. POS elements; d w is the weight vector dimension, express POS Modulo 2 operation.
6. The social network friend recommendation method based on subgraph sampling according to claim 1, characterized in that: Step S3 specifically includes: S31, inputting the feature matrix composed of the feature vectors of each user node and the homogeneous subgraph into the graph neural network model DGCNN to obtain the embedding vector of each user node; S32, assembling respective embedding vectors of the user node pairs whose similarities are to be obtained to form a user pair representation vector; S33, inputting the user pair representation vector into a multi-layer perceptron for processing to obtain a user pair similarity value; S34, sampling positive sample node pairs and negative sample node pairs to train the model, where the positive and negative sample ratio will be set to 1:1, and after obtaining the similarity value, the Ranking Loss loss function is used to calculate the loss value, and back propagation is used to adjust all learnable parameters; S35, selecting other users whose similarity value with the current user is greater than a threshold to perform recommendation.
Citation Information
Patent Citations
Social network friend prediction method based on random walk degree punishment mechanism
CN112132326A
Vector representation learning method and system based on heterogeneous information network random walk
CN114611668A