Graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization
Through the methods of multi-hop path enhancement and adaptive graph structure optimization, the entity-relationship path matrix is constructed and the graph structure is optimized, which solves the data sparsity and cold start problems in the knowledge graph recommendation system and achieves efficient and personalized recommendation effects.
Patent Information
- Application Number
- CN202511120114.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-12
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2045-08-12
AI Technical Summary
Existing knowledge graph recommendation methods have shortcomings in dealing with data sparsity, cold start and graph structure optimization, making it difficult to effectively mine high-order semantic associations and improve the robustness of the recommendation system.
The method of multi-hop path enhancement and adaptive graph structure optimization is adopted. By constructing the entity-relationship path matrix, dynamically adding pseudo edges and discarding low-frequency noise edges, combined with the cross-attention aggregation network, the graph structure is optimized to achieve personalized recommendations.
It significantly improves the accuracy and robustness of the recommendation system, solves the problems of data sparsity and cold start, and enhances the in-depth understanding of user interests and the personalization of recommendations.
Smart Images

Figure CN120632222B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization. Background Art
[0002] With the explosive growth of information on the Internet, how to accurately capture users' personalized needs and push products or services that match their interests to them has become a core challenge in improving user experience and platform value. Traditional recommendation systems mainly rely on collaborative filtering technology, which is based on the assumption that "similar users prefer similar items" and constructs latent embedding representations through historical interaction data between users and items, and has achieved good results in multiple application scenarios. In recent years, with the introduction of deep learning technology, collaborative filtering methods have gradually integrated advanced models such as variational autoencoders, attention mechanisms, and graph neural networks, significantly improving recommendation accuracy. However, the interaction data between users and items is naturally sparse. Especially in cold start scenarios, it is difficult for the model to effectively learn the representation of users or items, which seriously restricts the improvement of recommendation performance.
[0003] To alleviate the problem of data sparsity, knowledge graphs, as structured semantic networks, are gradually being introduced into recommendation systems due to their powerful knowledge integration and association capabilities. By integrating user behavior data with the rich entity and relationship information in knowledge graphs, recommendation systems can leverage the high-order semantic connections between entities in the graph to explore users' potential interests, thereby improving the accuracy and interpretability of recommendations. For example, on e-commerce platforms, knowledge graphs not only contain product attribute information but also build deep connections between products and user preferences through relationship chains such as "brand-manufacturer-origin."
[0004] Although knowledge graphs have brought new development opportunities to recommendation systems, in practical applications, problems such as incompleteness, lack of structure, and sparse relationships in graph data are still prominent, which directly affects the recommendation effect. The current mainstream knowledge graph enhancement methods mainly include two categories: data generation and graph completion. On the one hand, generative models can mine potential entities and relationships based on existing graph patterns, such as generating new product associations through analogical reasoning; on the other hand, external knowledge fusion technology uses multi-source heterogeneous data such as encyclopedias and industry reports to complete entity attributes and relationships. However, these methods still have significant bottlenecks in terms of credibility verification of generated data, the complexity of multi-source information fusion, and the accuracy of long-tail relationship completion. In particular, when faced with complex semantic paths or long-tail entities, the graph completion effect is limited and it is difficult to meet the needs of high-order semantic reasoning.
[0005] In addition, existing knowledge graph-based recommendation methods mainly focus on the extraction of structured information of the graph, and lack a dynamic optimization mechanism for the graph structure itself. Redundant, low-frequency or even incorrect relationship edges in the graph may introduce noise and interfere with the modeling of user interests by the model. In addition, missing potential associations in the graph may limit the model's understanding of user preferences. Therefore, how to dynamically adjust the graph structure during training, while retaining high-value associations and eliminating noisy paths, is a key problem to improve the robustness and generalization ability of the recommendation system.
[0006] In summary, although existing technologies have attempted to alleviate the data sparsity and cold start problems in the recommendation system through knowledge graphs, there are still significant deficiencies in terms of graph structure integrity, semantic path modeling depth, and graph dynamic optimization capabilities. Therefore, there is an urgent need for a recommendation method that can balance high-order semantic association mining and adaptive graph structure optimization to achieve more accurate, efficient and robust personalized recommendations.
[0007] In view of this, the present application is proposed. SUMMARY
[0008] The present application provides a graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization, which can at least partially improve the above problems.
[0009] To achieve the above object, the present application adopts the following technical solutions:
[0010] A graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization, comprising:
[0011] Obtain an information dataset, extract user data, entity data and relationship data from the information dataset, and determine their quantities. Initialize the user embedding layer, the entity embedding layer and the relationship embedding layer, obtain the corresponding continuous embedding vector representation, and construct a knowledge graph adjacency dictionary;
[0012] Based on the knowledge graph adjacency dictionary, perform three-layer loop processing, traverse all entities, a preset number of paths and path lengths, and construct an entity-relationship path matrix;
[0013] Based on the entity-relationship path matrix, construct a positive sample interaction table and a negative sample interaction table according to the user data, the entity data and the corresponding interaction records, and combine to obtain a complete interaction table;
[0014] Based on the complete interaction table, train and predict the recommendation model through an adaptive graph structure optimization module. The training process includes pseudo-edge enhancement processing, and the prediction process includes original graph structure retention processing;
[0015] After the processing is completed, the linear layer of the attention mechanism fuses the relationship embedding vector and the user embedding vector, calculates an attention score, converts the score into a weight, and performs weighted summation on the neighbor entity embedding vectors according to the weight to obtain a final output.
[0016] In summary, the core of the method is to drive the "multi-hop path enhancement" and "adaptive graph structure optimization" in two rounds, and systematically alleviate the problems of data sparsity, cold start and long tail coverage. Firstly, the user-item interaction record and external knowledge are abstracted into a triple knowledge graph, and a entity-relation multi-hop path matrix is constructed through hierarchical sampling, and the high-order semantic association is explicitly modeled; then, in the training stage, the adaptive graph optimization strategy of "pseudo edge addition + probability edge discard" is dynamically executed, the trusted pseudo edge is introduced in the area without neighbors by using the similarity of entity embedding, and at the same time, the low-frequency noise edge is randomly shielded, which expands the effective connection and suppresses the redundant interference, and the prediction stage reverts to the original graph structure to ensure the reasoning efficiency. In order to accurately depict user preferences, the scheme further designs a cross-attention aggregation network to jointly calculate the attention of user embedding and multi-hop neighbor relationship embedding, realize personalized weight allocation and deep information fusion. At the model training level, a four-element combined objective function composed of basic cross-entropy loss, label smoothing, embedding regularization and BPR ranking loss is adopted, and a phased strategy of graph structure pre-optimization, main network training and edge discard rate dynamic attenuation is used, supplemented by early stopping mechanism, which balances the accuracy, robustness and convergence speed.
[0017] In summary, the core of the method is to drive the "multi-hop path enhancement" and "adaptive graph structure optimization" in two rounds, and systematically alleviate the problems of data sparsity, cold start and long tail coverage. Firstly, the user-item interaction record and external knowledge are abstracted into a triple knowledge graph, and a entity-relation multi-hop path matrix is constructed through hierarchical sampling, and the high-order semantic association is explicitly modeled; then, in the training stage, the adaptive graph optimization strategy of "pseudo edge addition + probability edge discard" is dynamically executed, the trusted pseudo edge is introduced in the area without neighbors by using the similarity of entity embedding, and at the same time, the low-frequency noise edge is randomly shielded, which expands the effective connection and suppresses the redundant interference, and the prediction stage reverts to the original graph structure to ensure the reasoning efficiency. In order to accurately depict user preferences, the scheme further designs a cross-attention aggregation network to jointly calculate the attention of user embedding and multi-hop neighbor relationship embedding, realize personalized weight allocation and deep information fusion. At the model training level, a four-element combined objective function composed of basic cross-entropy loss, label smoothing, embedding regularization and BPR ranking loss is adopted, and a phased strategy of graph structure pre-optimization, main network training and edge discard rate dynamic attenuation is used, supplemented by early stopping mechanism, which balances the accuracy, robustness and convergence speed. BRIEF DESCRIPTION OF DRAWINGS
[0018] Figure 1 is a flowchart of the graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization provided by the embodiment of the application;
[0019] Figure 2Schematic diagram of a framework of a graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization provided by an embodiment of the present invention;
[0020] Figure 3 This is a schematic diagram of the edge discard process provided by an embodiment of the present invention;
[0021] Figure 4 This is a schematic diagram of the process of adding pseudo edges provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0022] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention will be further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0023] refer to Figures 1-4 As shown, the first embodiment of the present invention discloses a graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization, which can be executed by a graph recommendation device based on multi-hop path enhancement and adaptive graph structure optimization (hereinafter referred to as a graph recommendation device), and in particular, executed by one or more processors in the graph recommendation device to implement the following method:
[0024] S1: Obtain an information dataset (taking a common recommendation system dataset as an example), extract user data, entity data (also called items), and relationship data from the information dataset, determine their quantity, initialize the user embedding layer, entity embedding layer, and relationship embedding layer, obtain the corresponding continuous embedding vector representation, and construct a knowledge graph adjacency dictionary;
[0025] Specifically, step S1 further includes: extracting user data, entity data and relationship data from the information data set, and traversing the information data set to count the number of users , number of entities and the number of relationships ,wherein, the information data set includes: a user ID set, an entity ID set, and a relationship data set embodied by the user-item interaction records;
[0026] Embed the user layer by ID , entity embedding layer and relation embedding layer Initialize and map the discrete user ID data, entity ID data, and relationship ID data into low-dimensional continuous embedding vector representations with a dimension of d;
[0027] Among them, for the user ID set , user embedding layer The mathematical expression is , for the entity ID set , the entity embedding layer The mathematical expression is , for the relationship data set , the relationship embedding layer The mathematical expression is , is the embedding vector of the user , is the embedding vector of the entity , is the embedding vector of the relationship , is a set of all d-dimensional real vectors;
[0028] Each triple in the information data set is traversed , a knowledge graph adjacency dictionary is constructed , the graph structure information is stored in the form of triples, h is the head entity ID, t is the tail entity ID, and r is the relationship ID;
[0029] Among them, for each head entity ID, the corresponding tail entity ID and relationship ID are added to the corresponding head entity list in the knowledge graph adjacency dictionary , and the formula is , for each tail entity ID, the corresponding head entity ID and relationship ID are added to the corresponding tail entity list in the knowledge graph adjacency dictionary , and the formula is , is the neighbor entity and relationship list corresponding to the head entity ID h in the knowledge graph adjacency dictionary, is the neighbor entity and relationship list corresponding to the tail entity ID t in the knowledge graph adjacency dictionary.
[0030] In this embodiment, first, the full records are sequentially pulled from such information data sets, and the user ID, item ID (corresponding to the entity in the knowledge graph) and multiple relationship IDs implied by multiple behaviors between them are parsed line by line; At the same time of parsing, the total number of users, the total number of items (i.e. entities) and the total number of relationship types are counted in real time, laying a dimensional foundation for subsequent tensor pre-allocation and embedding layer initialization. After obtaining the accurate scales of the three, the system calls a unified initializer to randomly generate a low-dimensional continuous vector with a dimension of d for each user ID, entity ID, and relationship ID, and the mapping process is completed at one time, thereby converting the original high-dimensional sparse representation into a dense learnable embedding, providing a basic vector representation for subsequent model calculation, significantly reducing storage overhead and improving the efficiency of subsequent matrix operations.
[0031] Subsequently, at the same time, in order to facilitate subsequent rapid query of the relationship between entities, the information dataset is scanned again in sequence in units of triples to construct a directly addressable knowledge graph adjacency dictionary; for each triple, not only is the tail entity and the relationship appended to the list with the head entity as the key, but also the head entity and the relationship are appended to the list with the tail entity as the key, forming a bidirectional index. The dictionary is resident in memory and is compactly arranged in a linked list or continuous memory block manner, so that the subsequent model can locate all first-order neighbors of any entity and their corresponding relationships in time at any time, providing millisecond-level high-speed access capability for subsequent multi-hop path sampling, pseudo-edge expansion and attention aggregation. Through this initialization-constructing process, discrete raw data is efficiently converted into a differentiable and scalable graph structure representation, which not only ensures sufficient mining of high-order relationships in the training phase, but also takes into account the low-latency requirements of online reasoning, thereby laying the accuracy and performance foundation of the entire knowledge graph recommendation framework from the source. Figure 1
[0032] S2, based on the knowledge graph adjacency dictionary, three-layer loop processing is performed to traverse all entities, preset path numbers and path lengths to construct an entity-relation path matrix;
[0033] Specifically, step S2 further includes: based on the knowledge graph adjacency dictionary, determining three key parameters, respectively, the number of entities , the preset path number num_paths , and the path length path_length , and creating two three-dimensional arrays path_entities and path_relations , wherein the array is used to store entity IDs, and the array is used to store relationship IDs, and the initial values of the stored relationship IDs and array elements are both 0.
[0034] According to the three key parameters, three-layer loop processing is performed to randomly select the next entity and its corresponding relationship from the neighbor nodes of the current entity and store them in the arrays path_entities and path_relations to update the data in the three-dimensional arrays path_entities and path_relations , construct an entity-relation path matrix, and the three-layer loop processing includes entity loop, path loop and path length loop.
[0035] According to the three key parameters, three-layer loop processing is performed to update the data in the three-dimensional arrays path_entities and path_ relations , construct an entity-relation path matrix, specifically:
[0036] The entity loop is the outer loop, and its steps include: traversing all entities, whose index is marked as , , for each entity, a plurality of paths starting from the entity are generated;
[0037] The path cycle is a middle layer cycle, and the steps include determining the number of paths generated by each entity, and the index is marked as , For each path of each entity, the sampling of the path node and the relationship is independently performed;
[0038] The path length cycle is an inner layer cycle, and the steps include determining each step of the path, and the index is marked as , At the starting position of the path , the current entity amplitude is added to the array , and the starting position is , in each step, it is judged whether there is a neighbor entity;
[0039] If yes, a neighbor entity and the corresponding relationship next_entity are randomly selected from the neighbor node set of the array next_relation , the array is updated according to the formula , ;
[0040] If no, the entity is filled into the subsequent position of the path, and at the same time, the corresponding relationship of the array is set to 0, and the formula is: , ;
[0041] After completing all the cycle processing, the array path_entities and path_relations are converted into a PyTorch tensor, and a structured multi-hop path representation is formed based on the tensor, and an entity-relation path matrix is constructed.
[0042] In this embodiment, the entity-relation path matrix is constructed by using a hierarchical sampling algorithm through a path construction function. The hierarchical sampling algorithm is realized by the construct_path_adj function, and the multi-hop relationship between entities in the knowledge graph is captured, which provides a data basis for mining high-order semantic association for subsequent recommendation models.
[0043] The total number of entities, the preset path number and the expected semantic depth are read, and two three-dimensional arrays path_entities (dimensions: entity number path number path length) and path_relations (same dimensions) are continuously opened in the video memory or the main memory, and the initial values are all set to zero, which facilitates subsequent vectorization calculation and avoids time jitter caused by dynamic expansion.
[0044] Subsequently, a three-layer nested loop is started: the outermost layer traverses all entities in entity index order to ensure that none are missed; the middle layer starts multiple independent random walks for each entity, thereby providing multiple-angle, redundant context descriptions for the same entity in one training iteration; and the innermost layer extends along each path step by step, with the number of steps being strictly limited by a preset value. At each step of extension, the full neighbors of the current entity are located instantaneously through the adjacency dictionary. If the neighbors are not empty, the next entity and its corresponding relationship are extracted in a uniform random manner and written into the array immediately. If the entity unfortunately becomes an isolated node, the entity itself is looped back and the relationship is set to 0, thereby ensuring that the tensor shape is constant and subsequent GPU kernels do not need additional branch judgments. When the three-layer loop is completed, the two three-dimensional arrays are converted to PyTorch FloatTensor in place and directly bound to the GPU for subsequent calculations, eliminating additional memory copying and greatly reducing I / O bottlenecks. The entity-relation path matrix obtained in this way not only records the multi-hop semantic trajectory starting from any entity, but also naturally has a data enhancement effect through random sampling, enabling the subsequent graph neural network to perceive richer high-order associations without increasing the cost of labeling; at the same time, the structured tensor representation allows the framework to fully utilize the parallelism of CUDA during the training phase to complete batch path aggregation at millisecond level, significantly shortening the overall training period and improving the real-time response capability of online reasoning.
[0045] For entities with no neighbors, the entity itself is filled to ensure the completeness of the path, thereby forming a structured multi-hop path representation and laying the foundation for subsequent analysis of complex relationships between entities. The two tensors constitute a structured multi-hop path representation, clearly recording the path information of each entity, laying the foundation for the model to perform semantic reasoning and recommendation calculations based on path relationships. Through subsequent pseudo-edge addition, edge discarding, and other operations, the effectiveness of the path is further enhanced, and noisy paths are filtered, making the path information more in line with user needs and entity semantic associations, thereby laying a solid foundation for the recommendation model to deeply mine the potential relationship between user interests and item features.
[0046] S3, based on the entity-relation path matrix, constructing a positive sample interaction table and a negative sample interaction table according to user data, entity data, and corresponding interaction records, and combining to obtain a complete interaction table;
[0047] Specifically, step S3 further comprises: using the function to construct a positive sample interaction table, specifically: obtaining a user ID set, an entity ID set, and corresponding interaction records, and defining an offset offset , the value of which is The offset is used to combine the user ID data and the entity ID into a unique key;
[0048] Based on the offset, each set of user ID data and entity ID data is calculated to generate the positive sample composite key value , and combine the positive sample key value with the interaction label y into a positive sample key value pair ,in, is the ith user ID data, is the j-th entity ID data. In the positive sample, y=1, indicating that there is interaction between the user and the item;
[0049] Construct a positive sample interaction table and store all key-value pairs of positive samples in the positive sample interaction table The formula is , A collection of interaction records between users and entities;
[0050] use The function randomly generates negative samples, where the number of negative samples and the number of positive samples The same is as follows: randomly select user ID data and entity ID data in a loop and calculate the negative sample combination key , For the User ID data, For the entity ID data, and determine whether the negative sample combination key exists in the list;
[0051] If not, combine the negative sample key with the interaction label y to form a negative sample key-value pair ,In the positive sample, y=0, indicating that there is no interaction between the user and the item;
[0052] Construct a negative sample interaction table and store all key-value pairs of negative samples in the negative sample interaction table of the knowledge graph adjacency dictionary The formula is: ;
[0053] Merged positive sample interaction table and negative sample interaction table , get the complete interaction table ,Among them, the complete interaction table covers the positive and negative interaction information,between users and entities.
[0054] In this example, user-item interaction information is extracted from a dataset. Positive samples are constructed by extracting items with which users have actually interacted, and negative samples are randomly generated from items with which users have not interacted. This provides positive and negative sample data for model training, which is used to learn the associations between users and items. The goal is to provide balanced and highly discriminative training signals for subsequent ranking models with zero additional annotation cost.
[0055] During implementation, user-item interaction data is first read from the dataset. To losslessly map any user-entity interaction to a unique integer key, an offset is introduced to compress the two-dimensional index into a one-dimensional one. This avoids string concatenation overhead while inherently ensuring key-value uniqueness. For each real interaction, a positive key-value pair is generated and stored, where label 1 explicitly informs the model that the user has performed a positive action on this entity. Once all positive examples have been written, their number is counted and a negative sampling loop is initiated: each time, a user or entity is randomly sampled and a candidate key is calculated. If a candidate key does not appear in the positive sample table, it is immediately written to the negative sample table. This loop continues until the number of negative examples equals the number of positive examples. Finally, the table is concatenated with the sequence to obtain a complete interaction table covering all positive and negative interactions. This strict balance between the number of positive and negative examples ensures a more stable gradient distribution during model training, effectively mitigating the risk of overfitting caused by class imbalance. Furthermore, the key-value sharing mechanism enables subsequent sampling, shuffling, and batch splitting to be performed using simple integer slicing, significantly improving GPU utilization and training throughput.
[0056] The complete interaction table covers the positive and negative interaction information between users and items, providing rich and discriminative data for subsequent model training, enabling the model to effectively learn users' interests and preferences as well as the characteristics of items, thereby achieving accurate recommendations.
[0057] S4, based on the complete interaction table, the recommendation model is trained and predicted by the adaptive graph structure optimization module, wherein the training process includes pseudo-edge enhancement and the prediction process includes original graph structure preservation.
[0058] Specifically, step S4 further includes: using the complete interaction table as positive and negative sample data for model training, using The function calculates the similarity between entities, where the entity embedding vector matrix is , normalize it and get the normalized embedding vector matrix , the normalized formula is: , is the normalized entity embedding vector matrix Rank Elements of the column, is the corresponding element of the original matrix, It is the entity embedding vector matrix, which is used to store the low-dimensional continuous embedding vectors of all entities. Each row of the matrix corresponds to the embedding vector of an entity. It is the result of mapping the discrete entity ID into a computable continuous vector. is the total number of knowledge graph entities, is the dimension of the entity embedding vector, is the square of the embedding value of the ath entity in the Kth dimension in the entity embedding matrix E, used to calculate the L2 norm of the entity embedding vector (the denominator item when normalized);
[0059] Calculate the entity similarity matrix , whose formula is: , is the similarity matrix between entities, used to measure the similarity between any two entities, is the transpose;
[0060] Perform a masking operation on the normalized matrix, where when judging the jth entity There is a set of neighbor entities in the knowledge graph adjacency dictionary , set the element of the entity similarity matrix to the minimum value, whose formula is: ;
[0061] Select the highest similarity of the preset number of entity indexes from the masked entity similarity matrix by row fake_edge_num , and store them in the array fake_edges_cache , whose formula is: , where represents the index corresponding to the first u maximum values selected from the vector;
[0062] In the get_neighbors function, based on the array fake_edges_cach , add pseudo edges to each entity edge, where for a specific entity , get the entity set corresponding to the edge from the array fake_edges_cache [ ] and create the corresponding pseudo relationship ID set , , is a preset pseudo relationship ID;
[0063] Concatenate the entities and relationships corresponding to these pseudo edges with the original one-hop neighbor entities and relationships, respectively, to expand the knowledge graph structure.
[0064] Introduce a probability edge discard mechanism to remove noise edges that interfere with the learning of the recommendation model. In the get_neighbors function, call the edge discard function to filter paths based on user preferences when obtaining neighbor nodes;
[0065] Process the relationship ID, whose formula is: , , use the embedding vector of the effective relationship relations_ embs Combine the user embedding vector user_emb to calculate the user-relation score , where, is the path dimension, is the element value of the relationship embedding vector corresponding to the w-th path in the d-th dimension of the effective relationship embedding matrix, is the element value of the user embedding vector in the d-th dimension, is the effectiveness mask, is the original input relationship ID set, is the relationship embedding layer, which is a module for mapping discrete relationship IDs to low-dimensional continuous embedding vectors, is the number of embeddings of the relationship embedding layer, is the safe relationship ID after effectiveness screening;
[0066] transforming the user-relation score to obtain in combination with the preset dropout probability drop_rate calculate the path retention probability where, in the training processing stage, the Bernoulli distribution is used to generate the retention mask in the prediction processing stage, the retention mask is set to all True, and all paths are retained.
[0067] In the aggregate function, the neighbor entities and the relationship neighbor_ents are filtered according to the retention mask neighbor_rels , and are updated according to the rule . .
[0068] In this embodiment, step S4 aims to solve the data sparsity problem by dynamically adjusting the knowledge graph structure, and improve the inference efficiency in the prediction stage while ensuring the training effect of the model. The process mainly includes pseudo-edge enhancement in the training stage and original graph structure retention in the prediction stage. In the training stage, the adaptive graph structure optimization module is used to realize the double strategy of edge dropping and pseudo-edge adding. First, after calculating the similarity matrix using entity normalized embedding vectors, shielding the self and real neighbor relationships, high-similarity entities are selected as pseudo-edge connection objects, which are stored to complete the pseudo-edge adding operation; at the same time, a probability edge dropping mechanism is introduced to randomly drop low-frequency connection edges in the original graph with a certain probability, reducing the interference of redundant relationships. According to the pseudo-edge cache, pseudo-edges are added to each entity to dynamically expand the knowledge graph structure, effectively alleviating the data sparsity problem. In the prediction stage, the original graph structure is retained to avoid additional computational overhead and ensure the inference efficiency.
[0069] Specifically, the adaptive graph structure optimization process is entered: first, the similarity matrix is calculated using the entity normalized embedding vector. After obtaining the similarity matrix, in order to avoid "connecting oneself" or repeating the existing edge, that is, to avoid selecting the neighbor as a pseudo edge which is oneself and the existing connection; it is necessary to perform a masking operation on the matrix. Write the highest similar entity index in the array by row, which is resident in the memory, and can be directly indexed. The entities and relationships corresponding to these pseudo edges are spliced with the original one-hop neighbor entities and relationships, respectively, to expand the knowledge graph structure and effectively alleviate the data sparseness problem.
[0070] At the same time, the probability edge discard mechanism is enabled, and the dynamic edge discard is used to further optimize the graph structure; in order to ensure the effectiveness of the relationship ID, the relationship ID is processed according to the preset formula, and the user-relation score is calculated. In order to increase the discard probability of low-score relationships, the score is transformed, and the retention mask is generated through Bernoulli distribution. In the prediction stage, the original graph structure is retained to avoid additional calculation overhead and ensure the inference efficiency. After the above series of operations such as path sampling, pseudo edge addition and edge discard, the dynamic enhancement of multiple paths is realized, which not only enriches the path information, but also filters the noise path, laying a solid foundation for the subsequent model to accurately mine the semantic association between users and items and improve the recommendation performance.
[0071] S5, after the processing is completed, the linear layer of the attention mechanism is used to fuse the relationship embedding vector and the user embedding vector, the attention score is calculated, the score is converted into a weight, and the neighbor entity embedding vector is weighted and summed according to the weight to obtain the final output.
[0072] Specifically, step S5 further includes: after the training processing and the prediction processing are completed, the original item embedding item_emb and the one-hop neighbor entity neighbor_ents and the relationship neighbor_rels are obtained. neighbor_ ents and the relationship neighbor_rels are filtered and processed, and the safe neighbor entity embedding neighbor_ent_emb and the relationship embedding neighbor_rel_emb are obtained based on the effective mask.
[0073] The user embedding vector user_embeddings is expanded to match the dimension of the neighbor relationship embedding, forming a vector user_embeded with a dimension of batch_size,num_paths,emb_dim .
[0074] The attention input attention_input is constructed, the expanded user vector user_embeded is spliced with the neighbor relationship embedding neighbor_rel_emb to obtain a tensor with a dimension of .
[0075] adopting attention_layer linear layer to tensor performing calculation to obtain attention score , whose dimension is batch_size,num_paths , is a tensor operation function, which means removing the dimension of the tensor;
[0076] setting the score corresponding to the invalid relationship to negative infinity, and its formula is: , and using the softmax function to convert the attention score into attention weight ;
[0077] performing multi-hop information fusion based on the calculated attention weight , weighting and summing the neighbor entity embedding neighbor_ent_emb to obtain the aggregation result tensor ;
[0078] based on the configured aggregator_class parameters, combining the original item embedding item_emb with the aggregation result tensor using addition, and its formula is: ;
[0079] transforming the combination result self.linear_layers[0] by a linear layer , processing it through the Tanh activation function, and obtaining the final output output .
[0080] In this embodiment, in the aggregate function, a user_ relationship attention mechanism is designed. The relationship embedding vector and the user embedding vector are fused through the linear layer of the attention mechanism, the attention score is calculated, the score of the invalid relationship is set to negative infinity, and then the function is used to convert it into attention weight. According to the weight, the neighbor entity embedding vectors are weighted and summed to realize dynamic fusion and focus on user preferences, so that the model can give different attention degrees to different neighbor entities and relationships according to user interests, and improve the personalization degree of recommendation. At the same time, the one-hop and two-hop neighbor information is fused, the neighbor labels are weighted and aggregated by the user-relation score, the complex relationships between entities are deeply mined, and more comprehensive and accurate recommended content is provided for users. This step aims to deeply fuse multi-hop neighbor information interest preferences by constructing a cross-attention aggregation network, to provide more comprehensive and accurate recommended content for users, and effectively improve the personalization degree and relevance of recommendation. This network mainly relies on aggregate and label_ smoothness_predict functions to realize.
[0081] The user-relation attention mechanism is one of the core operations, and in order to ensure the effectiveness of subsequent calculations, the neighbor entities and relations are screened, such as obtaining safe neighbor entity embeddings and relation embeddings based on the effective mask after the edge discard operation. In order to align in the batch dimension, the user embedding is first expanded, and then spliced with the relation embedding in the last dimension. Next, the attention_layer linear layer projects each row with weight sharing, outputting the attention score; in order to avoid invalid relations interfering with attention calculation, the score corresponding to the invalid relation (including discarded edges) is set to negative infinity, and then the attention score is converted into attention weight by using the softmax function. The weight reflects the degree of attention of the model to different neighbor relations, so that the model can dynamically focus on relevant neighbor information according to user preferences. Next, the row multi-hop information fusion operation is performed, and the neighbor entity embedding is weighted and summed based on the calculated attention weight, realizing the aggregation of neighbor information and obtaining the tensor. Finally, it is determined according to the parameters whether to add the aggregation result to the original entity embedding; the superposition result is subjected to a layer of learnable linear transformation and Tanh activation, and the output dimension remains unchanged.
[0082] In addition, in label_smoothness_predict the function, multi-hop information fusion is also involved. In the calculation process, the neighbor labels are weighted and aggregated by the user-relation score to deeply mine the complex relationships between entities. Specifically, in the label propagation process, the user-relation score is calculated using the user embedding and the relation embedding, the neighbor labels of different hops are weighted, and the entity label is updated gradually, thereby realizing effective utilization of multi-hop information and providing richer semantic information support for recommendation decision-making.
[0083] Through the construction and operation of the above cross-attention aggregation network, the model can deeply fuse multi-hop neighbor information, accurately capture user preferences, effectively mine complex semantic associations between entities, and generate more interesting recommendation content for users, thereby significantly improving the performance of the recommendation system and user experience.
[0084] Preferably, it further comprises: In calculate_loss the function, a function combination containing four losses is constructed, which are the basic recommendation loss rec_loss , the label smoothing regularization loss ls_loss , the embedding vector regularization loss l2_loss and the ranking optimization loss rank_loss , and their mathematical expressions are respectively:
[0085] , wherein, is the total number of samples, is the sigmoid function, is the label before smoothing, indicating that user i and entity or relation j have interactions, as the smoothed label;
[0086] , , as the smoothing parameter;
[0087] , as the regularization coefficient, , as the total number of user-positive sample pairs, as the positive sample entity, as the negative sample entity, as the predicted interaction score of the user to the positive sample , as the entity actually interacted by the user , which belongs to the positive sample. as the predicted interaction score of the user to the negative sample , as the entity not interacted by the user (negative sampling generation), which belongs to the negative sample;
[0088] Based on the above four loss functions, the total loss function , as the basic recommendation loss weight, as the label smoothing regularization loss weight, as the embedding vector regularization loss weight, as the ranking optimization loss weight.
[0089] In this embodiment, by designing a combined loss function and adopting a phased training and gradient optimization strategy, the performance of the model in terms of recommendation accuracy, generalization ability and other aspects is balanced, the model is ensured to converge efficiently and overfitting is avoided, thereby improving the overall recommendation effect. The BCEWithLogitsLoss basic recommendation loss is calculated to measure the difference between the model prediction and the true label; then label smoothing regularization is performed to prevent the model from overfitting; the embedding vector is regularized to improve the generalization ability of the model; based on BPR ranking optimization, the ranking quality of the recommendation list is improved. By reasonably setting the weights of each loss term, the performance of the model in different performance indicators is balanced.
[0090] Specifically, the binary cross-entropy logarithmic loss function BCEWithLogitsLoss is used to calculate the basic recommendation loss, which is used to measure the difference between the model prediction result and the true label. Let the user-item interaction score matrix predicted by the model be , and the true interaction label matrix be ; the basic recommendation loss rec_loss is obtained.The original score output by the model is mapped to the [0, 1] probability interval after the calculation formula of the loss function. The loss function prompts the model to accurately predict whether the user and the item have an interaction relationship.
[0091] The label smoothing regularization loss is calculated by the calculate_ls_loss function to alleviate the problem of model overfitting. Assuming that the 1 label of the real label y after smoothing is , the label smoothing regularization loss is ls_loss Based on the same binary cross-entropy loss calculation, the label smoothing operation makes the model prediction more general, avoiding excessive dependence on training data.
[0092] In order to improve the generalization ability of the model, L2 regularization is performed on the user embedding vector, entity embedding vector and relationship embedding vector, and by constraining the size of the embedding vector, it is prevented that the model parameters are too large to cause overfitting. Finally, based on the Bayesian personalized ranking (BPR) principle, the sorting optimization loss rank_loss is involved to optimize the sorting quality of the recommendation list. The loss function prompts the model to learn a more reasonable item sorting and improves the relevance of the recommendation list.
[0093] Further, the method also adopts a phased training method, first performs graph structure pre-optimization to construct a pseudo-edge enhanced knowledge graph, then trains the subject network to learn the representation of entities and relationships, and in the training process, dynamically decays the edge dropout rate to further optimize the model performance. At the same time, the early stopping mechanism is introduced to monitor the performance of the validation set, avoid model overfitting, improve training efficiency and accelerate model convergence.
[0094] The phased training method is used to optimize the model performance. First, the graph structure is pre-optimized by the precompute_fake_edges function to calculate the entity similarity and add pseudo edges to enhance the knowledge graph structure; then it enters the training stage of the subject network, learns the embedding representation of entities and relationships using the combined loss function, and adjusts the model parameters; in the fine-tuning stage, the edge dropout rate is dynamically decayed drop_rate from the initial value to gradually decrease to close to 0, so that the model can use more path information in the later training stage to further optimize the model performance.
[0095] In addition, the early stopping mechanism is introduced to avoid model overfitting. During the training process, the model performance is evaluated on the validation set regularly, and key evaluation indicators (such as AUC, Recall, etc.) are recorded. If the performance of the model on the validation set does not improve (or the improvement is less than a threshold ) for T consecutive training cycles, the training is stopped and the current optimal model parameters are retained. This mechanism effectively reduces the training time, improves the training efficiency, and ensures a good balance between the generalization ability and the training effect of the model.
[0096] Through the above loss function design and gradient optimization strategy, the model can effectively learn the complex relationship between users and items during the training process, balance multiple performance indicators, improve recommendation accuracy and generalization ability, and provide reliable recommendation services for practical applications.
[0097] To further verify the effectiveness of the method from multiple dimensions such as recommendation accuracy, training efficiency, cold start adaptability, and long-tail commodity coverage, a variety of classic recommendation evaluation indicators are used to comprehensively evaluate the model, including recall rate , average reciprocal rank , normalized discounted cumulative gain , hit rate , and accuracy . At the same time, to measure the performance of the cold start scenario, the area under the curve (AUC) is introduced; to evaluate the long-tail commodity coverage, the long-tail commodity coverage rate is used. Through experiments on the MovieLens-1M dataset, the effectiveness and superiority of the method are comprehensively verified from multiple dimensions such as recommendation accuracy, training efficiency, cold start adaptability, and long-tail commodity coverage.
[0098] The experimental indicators include: recall rate, which calculates the proportion of items that the user has actually interacted with among the top K items in the recommendation list. Let R(u) be the set of top K recommended items generated by the model for user u, and T(u) be the set of items that user u has actually interacted with, then . This indicator measures the ability of the model to retrieve items of interest to the user.
[0099] Average reciprocal rank: for user u, if the ranking of the item he is actually interested in is rank in the recommendation list, its formula is: , where U is the set of users. This indicator reflects the degree to which relevant items are ranked high in the recommendation list.
[0100] Normalized discounted cumulative gain: to consider the relevance and ranking position of items in the recommendation list. First, calculate the ideal recommendation list DCG, then calculate the actual recommendation list DCG, its formula is: , , where represents the relevance score of the th item in the recommendation list to the user.
[0101] Hit rate: to determine whether there is an item that the user has actually interacted with among the top K items in the recommendation list. Its formula is , [] is the Iverson bracket, 1 if the condition is true, otherwise 0. Accuracy: calculate the proportion of items that the user has actually interacted with among the top K items in the recommendation list, its formula is: .
[0102] The model developed in this method was compared with KGIN. During the experiments, model hyperparameters were fixed, including an embedding vector dimension of 64, a multi-hop path length of 3, a preset number of paths of 10, a learning rate of 0.00075, and a batch size of 4096. Each experiment was repeated five times, and the average result was taken as the final result to reduce errors caused by experimental randomness. The other models were run at their optimal parameter configurations.
[0103] Experimental results show that this model outperforms the other three models in multiple metrics on the lastfm and book-crs datasets. It can more accurately capture user interests and generate high-quality recommendation lists. The experimental results are shown in Table 1.
[0104] Table 1
[0105]
[0106] In summary, rigorous experiments and analysis on the lastfm and book-crs datasets demonstrate that this model significantly outperforms the other three models across multiple key evaluation metrics. In terms of user interest mining, this model leverages a unique multi-hop path enhancement mechanism to penetrate the data surface and deeply analyze users' underlying preferences. In the recommendation list generation phase, leveraging the structured information transfer of the knowledge graph, it effectively improves the relevance and diversity of recommended content. These experimental results demonstrate that this model is capable of more accurately capturing user interests and consistently producing high-quality recommendation lists, providing a new and viable direction for technical optimization in the field of personalized recommendations.
[0107] The above is a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications are also considered to be within the scope of protection of the present invention.
Claims
1. A graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization, characterized in that: include: Obtain an information dataset, extract user data, entity data, and relationship data from the information dataset, determine their quantity, initialize the user embedding layer, entity embedding layer, and relationship embedding layer, obtain the corresponding continuous embedding vector representation, and construct a knowledge graph adjacency dictionary; Based on the knowledge graph adjacency dictionary, a three-layer loop process is performed to traverse all entities, preset the number of paths and path lengths, and construct the entity-relationship path matrix; Based on the entity-relationship path matrix, construct positive sample interaction tables and negative sample interaction tables according to user data, entity data, and corresponding interaction records, and combine them to obtain a complete interaction table; Based on the complete interaction table, the recommendation model is trained and predicted by the adaptive graph structure optimization module. The training process includes pseudo-edge enhancement, and the prediction process includes original graph structure preservation. Specifically, Use the complete interaction table as positive and negative sample data for model training. The function calculates the similarity between entities, where the entity embedding vector matrix is , normalize it and get the normalized embedding vector matrix , the normalized formula is: , is the normalized entity embedding vector matrix Rank Elements of the column, is the corresponding element of the original matrix, It is the entity embedding vector matrix, which is used to store the low-dimensional continuous embedding vectors of all entities. Each row of the matrix corresponds to the embedding vector of an entity. It is the result of mapping the discrete entity ID into a computable continuous vector. is the total number of knowledge graph entities, is the dimension of the entity embedding vector, is the square of the embedding value of the a-th entity in the entity embedding matrix E in the K-th dimension; Calculate entity similarity matrix , the formula is: , is the entity similarity matrix, which is used to measure the similarity between any two entities. is transposed; The normalized matrix is masked, where when the jth entity is judged There is a set of neighbor entities in the knowledge graph adjacency dictionary When , let the elements of the entity similarity matrix be is the minimum value, and its formula is: ; Select the preset number of entities with the highest similarity from the masked entity similarity matrix row by row fake_edge_num The entity index is stored in the array fake_edges_cache The formula is: ,in, Indicates selecting the index corresponding to the first u maximum values from the vector; exist get_neighbors In the function, based on the array fake_edges_cach , add a pseudo edge to each entity edge, where for a specific entity , from the array fake_edges_cache [ ] to get the entity set corresponding to the edge , and create the corresponding pseudo-relationship ID set , It is the preset pseudo relation ID; The entities and relationships corresponding to these pseudo-edges are spliced with the original one-hop neighbor entities and relationships to expand the knowledge graph structure; After the processing is completed, the relationship embedding vector and the user embedding vector are fused through the linear layer of the attention mechanism, the attention score is calculated, the score is converted into a weight, and the neighbor entity embedding vectors are weighted and summed according to the weight to obtain the final output.
2. The graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization according to claim 1, characterized in that: Obtain an information dataset, extract user data, entity data, and relationship data from the information dataset, determine their quantity, initialize the user embedding layer, entity embedding layer, and relationship embedding layer, obtain the corresponding continuous embedding vector representation, and construct a knowledge graph adjacency dictionary, specifically: Extract user data, entity data, and relationship data from the information dataset, and traverse the information dataset to count the number of users , number of entities and the number of relationships ,wherein, the information data set includes: a user ID set, an entity ID set, and a relationship data set embodied by the user-item interaction records; Embed the user layer by ID , entity embedding layer and relation embedding layer Initialize and map the discrete user ID data, entity ID data, and relationship ID data into low-dimensional continuous embedding vector representations with a dimension of d; Among them, for the user ID set , user embedding layer The mathematical expression is , for the entity ID set , entity embedding layer The mathematical expression is , for relational data sets , relation embedding layer The mathematical expression is , For users The embedding vector of For Entity Embedded vector, For the relationship Embedded vector, is the set of all d-dimensional real vectors; Traverse each triple in the information dataset , build a knowledge graph adjacency dictionary , the graph structure information is stored in the form of triples, where h is the entity ID, t is the tail entity ID, and r is the relationship ID; For each head entity ID, its corresponding tail entity ID and relationship ID are added to the knowledge graph adjacency dictionary Under the corresponding header entity list in , the formula is For each tail entity ID, add its corresponding head entity ID and relationship ID to the knowledge graph adjacency dictionary Under the corresponding tail entity list in , the formula is , is the head entity in the knowledge graph adjacency dictionary The corresponding neighbor entity and relationship list, The tail entity in the knowledge graph adjacency dictionary The corresponding list of neighbor entities and relations.
3. The graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization according to claim 2 is characterized in that: Based on the knowledge graph adjacency dictionary, a three-layer loop process is performed to traverse all entities, preset the number of paths and path lengths, and construct the entity-relationship path matrix, specifically: Based on the knowledge graph adjacency dictionary, three key parameters are determined, namely the number of entities , preset number of paths num_paths , and path length path_length , and create two three-dimensional arrays path_entities and path_ relations , where the array Used to store entity ID, array Used to store relationship IDs. The initial values of relationship IDs and array elements are both 0. Perform three-layer loop processing based on three key parameters, randomly select the next entity and its corresponding relationship from the neighbor nodes of the current entity, and store them in the array path_entities and path_relations To update the three-dimensional array path_ entities and path_relations The data in the,entity-relationship path matrix is constructed, and the three-layer loop processing includes,entity loop, path loop and path length loop.
4. The graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization according to claim 3 is characterized in that: Perform three-layer loop processing based on three key parameters to update the three-dimensional array path_entities and path_ relations The data in the ,construct the entity-relationship path matrix, specifically: The entity loop is the outer loop, and its steps include: traversing all entities, whose indexes are marked as , ,For each entity, multiple paths starting from the entity are generated; The path loop is a middle-level loop, which includes the following steps: determining the number of paths generated by each entity, whose index is marked as , ,For each path of each entity, the path nodes and relationships are sampled independently; The path length loop is the inner loop, and its steps include: determining each step of the path, whose index is marked as , , at the start of the path At, the current entity amplitude is added to the array and from Initially, at each step, determine whether there is a neighbor entity; If so, from the array Randomly select a neighbor entity from the neighbor node set next_entity and their corresponding relationships next_relation , according to the formula , Update the array; If not, fill the entity to the subsequent position of the path, and set the corresponding relationship with the time array to 0. The formula is: , ; After all loops are processed, the array path_entities and path_relations Convert it into a PyTorch tensor, form a structured multi-hop path representation based on the tensor, and construct the entity-relationship path matrix.
5. The graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization according to claim 4 is characterized in that: Based on the entity-relationship path matrix, we construct a positive sample interaction table and a negative sample interaction table according to user data, entity data, and corresponding interaction records. The complete interaction table is obtained by combining them. Specifically: use The function constructs a positive sample interaction table, specifically: Get the user ID set, entity ID set and corresponding interaction records, and define an offset offset , whose value is , this offset is used to combine the user ID data and the entity ID into a unique key; Based on the offset, each set of user ID data and entity ID data is calculated to generate the positive sample composite key value , and combine the positive sample key value with the interaction label y to form a positive sample key value pair ,in, is the ith user ID data, is the j-th entity ID data. In the positive sample, y=1, indicating that there is interaction between the user and the item; Construct a positive sample interaction table and store all key-value pairs of positive samples in the positive sample interaction table The formula is , A collection of interaction records between users and entities; use The function randomly generates negative samples, where the number of negative samples and the number of positive samples The same, specifically: Calculate the negative sample combination key by randomly selecting user ID data and entity ID data in a loop , For the User ID data, For the entity ID data, and determine whether the negative sample combination key exists in the list; If not, combine the negative sample key with the interaction label y to form a negative sample key-value pair ,In the positive sample, y=0, indicating that there is no interaction between the user and the item; Construct a negative sample interaction table and store all the key-value pairs of negative samples in the negative sample interaction table of the knowledge graph adjacency dictionary The formula is: ; Merged positive sample interaction table and negative sample interaction table , get the complete interaction table ,Among them, the complete interaction table covers the positive and negative interaction information,between users and entities.
6. The graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization according to claim 5, characterized in that: Also includes: Introducing a probabilistic edge discarding mechanism to remove noise edges that interfere with the learning of the recommendation model. get_neighbors When the function obtains neighbor nodes, it calls the edge discard function to filter the paths based on user preferences; The formula for processing the relationship ID is: , , using the embedding vector of the effective relationship relations_ embs Combined with user embedding vector user_emb Calculating user-relationship scores ,in, is the path dimension, To represent the element value of the relation embedding vector corresponding to the w-th path in the effective relation embedding matrix on the d-th dimension, is the element value of the user embedding vector in the dth dimension, is the validity mask, is the original input relation ID set, It is a relation embedding layer, a module for mapping discrete relation IDs into low-dimensional continuous embedding vectors. is the number of embeddings in the relation embedding layer, It is the security relationship ID after validity screening; Transform the user-relationship score to obtain , combined with the preset drop probability drop_rate Calculate path retention probability , where, during the training process, the retention mask is generated using the Bernoulli distribution , during the prediction processing stage, the mask will be retained Set to all True to keep all paths; exist aggregate In the function, according to the retention mask To neighbor entities neighbor_ents and relationships neighbor_rels Filter according to the rules , to update.
7. The graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization according to claim 6, characterized in that: After processing is completed, the relationship embedding vector and the user embedding vector are fused through the linear layer of the attention mechanism to calculate the attention score, convert the score into a weight, and then perform a weighted sum of the neighbor entity embedding vectors according to the weight to obtain the final output, which is: After the training and prediction processes are completed, get the original item embeddings item_emb and one-hop neighbor entities neighbor_ents and relationships neighbor_rels , for neighbor entities neighbor_ents and relationships neighbor_rels Perform filtering to obtain safe neighbor entity embedding based on valid masks neighbor_ent_emb and relation embedding neighbor_rel_emb ; User embedding vector user_embeddings Expand it so that its dimension matches the neighbor relationship embedding to form a vector user_embeded , whose dimensions are [ batch_size,num_paths,emb_dim ]; Constructing attention input attention_input , the expanded user vector user_embeded Embedding with neighbor relations neighbor_rel_emb Splice and get the dimension Tensor ; use attention_layer Linear layer on tensor Calculate and get the attention score , whose dimensions are [ batch_size,num_paths ], It is a tensor operation function, which means removing the dimension of the tensor; The fraction corresponding to the invalid relationship is set to negative infinity, and the formula is: , and use the softmax function to convert the attention score into the attention weight ; Perform multi-hop information fusion based on the calculated attention weights , embedding neighbor entities neighbor_ent_emb Perform weighted summation to obtain the aggregated result tensor ; Configuration-based aggregator_class Parameters, embed the original item item_emb with the aggregation result tensor The combination is performed by addition, and the formula is: ; Through the linear layer self.linear_layers[0] Combined results Transformed and processed by Tanh activation function to obtain the final output output .
8. The graph recommendation method based on multi-hop path enhancement and adaptive graph structure optimization according to claim 7, characterized in that: Also includes: exist calculate_loss In the function, a function combination containing four losses is constructed, namely the basic recommendation loss rec_loss , label smoothing regularization loss ls_loss , embedding vector regularization loss l2_loss and ranking optimization loss rank_loss , and their mathematical expressions are: ,in, is the total number of samples, is the sigmoid function, is the label before smoothing, indicating that user i interacts with entity or relationship j. is the smoothed label; , , is the smoothing parameter; , is the regularization coefficient, , is the total number of user-positive sample pairs, is a positive sample entity, is a negative sample entity, To represent the user Positive samples The predicted interaction score of is a user Entities that have actually interacted are positive samples. To represent the user For negative samples The predicted interaction score of is a user Entities that have not been interacted with are generated by negative sampling and belong to negative samples; Based on the above four loss functions, the total loss function is obtained , is the basic recommendation loss weight, is the label smoothing regularization loss weight, is the embedding vector regularization loss weight, Optimize loss weights for ranking.
Citation Information
Patent Citations
Personalized recommendation method based on knowledge graph convolution algorithm
CN112488791A
Knowledge graph construction and product recommendation method and system based on user data
CN120338924A