Intent-aware recommendation method based on the fusion of knowledge graph and contrastive learning
By constructing collaborative knowledge graphs and differentiated graph neural network aggregation, combined with learnable attention mechanisms and contrastive learning, the problem of poor long-tail item recommendation effects is solved, deep coupling relationship mining of user intentions is achieved, and the accuracy and robustness of the recommendation system are improved.
Patent Information
- Application Number
- CN202511120113.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-12
- Publication Date
- 2025-10-14
- Estimated Expiration
- 2045-08-12
AI Technical Summary
Existing recommendation systems perform poorly in long-tail projects and cold start scenarios, and it is difficult to fully explore the deep coupling relationship between knowledge graphs and user dynamic intentions. Noise relationships interfere with node representation learning and affect recommendation accuracy.
By constructing a collaborative knowledge graph, adopting a differentiated graph neural network aggregation strategy to learn user and item representations, combining a learnable attention mechanism for data enhancement, generating comparative views, and expanding positive samples by fusing user embedding similarity with intent distribution similarity, optimizing contrastive learning loss, and combining Bayesian personalized ranking for joint training.
It improves the recommendation accuracy of long-tail items, enhances the model's ability to model user intent, and improves the accuracy and relevance of recommendation results.
Smart Images

Figure CN120611100B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an intent-aware recommendation method based on the fusion of knowledge graphs and contrastive learning. Background Art
[0002] In recent years, recommendation systems have become a core approach to alleviating internet information overload. With the significant advantages of graph neural networks (GNNs) in modeling graph-structured data, GNN-based graph recommendation models have gradually replaced traditional matrix factorization and deep collaborative filtering methods, becoming the mainstream paradigm. These models typically construct historical user-item interactions as a bipartite user-item graph and utilize graph convolution or graph attention mechanisms to aggregate high-order neighborhood information, thereby capturing global collaborative signals. Representative work, such as LightGCN, has demonstrated that retaining only neighborhood aggregation and linear transformations can significantly improve the expressive power of user representations by simplifying graph convolution operations. However, bipartite graphs only capture the explicit interactions between users and items, ignoring the rich attributes and semantic information on the item side (such as the director, actors, and genre of a movie, or the author, publisher, and theme of a book). This limits the model's recommendation effectiveness for long-tail items and cold-start scenarios, and makes it difficult to reveal deep semantic connections between items.
[0003] To remedy this shortcoming, researchers have attempted to introduce knowledge graphs (KGs) into recommendation systems. Knowledge graphs store a large number of entities and their relationships in the form of triples, which can provide structured background knowledge for projects and establish semantic bridges between users, projects, and external knowledge through entity links. For example, in book recommendations, a multi-hop association of "user-reading-book-author-writing-author's other books" can be established through knowledge graphs, thereby alleviating data sparsity and improving recommendation diversity. However, most existing knowledge graph-enhanced recommendation methods use KG as a static auxiliary feature, and only fuse entity information through simple embedding propagation or attention mechanisms, failing to fully explore the deep coupling relationship between KG and user dynamic intentions. In addition, in data-sparse scenarios, noisy relationships in KG may interfere with node representation learning, resulting in a decrease in the representation quality of long-tail items, which in turn affects recommendation accuracy.
[0004] Furthermore, traditional GNN-based recommendation models are susceptible to graph structural noise during training and have limited ability to represent long-tail items. Contrastive learning, a self-supervised paradigm, has been shown to enhance model robustness by constructing positive and negative sample pairs to optimize the representation space. However, existing work has largely focused on random perturbations of the user-item interaction graph (such as edge or node dropouts), failing to consider the structural characteristics of the knowledge graph and the dynamic nature of user intent. This can lead to enhanced samples potentially destroying key semantic associations or generating false positives that are unrelated to the user's true preferences. How to synergistically leverage the semantic information of the knowledge graph and the robustness of contrastive learning, while simultaneously modeling the dynamic evolution of user intent, has become a key issue that needs to be addressed in current recommendation systems.
[0005] In view of this, this application is filed. Summary of the Invention
[0006] The present invention provides an intent-aware recommendation method based on the fusion of knowledge graph and contrastive learning, which can at least partially improve the above problems.
[0007] To achieve the above object, the present invention adopts the following technical solutions:
[0008] An intent-aware recommendation method based on the fusion of knowledge graph and contrastive learning, which includes:
[0009] Obtain and preprocess the raw interaction data to construct a collaborative knowledge graph, input the collaborative knowledge graph into the recommendation module, initialize the representations of items and users using the initialization method of generating embedded representations based on IDs, and then use aggregation formulas for users and items respectively to update the representations of items and users;
[0010] Filter positive and negative samples from the updated item representations, and input the positive and negative samples and user representations into the Bayesian personalized ranking loss function to calculate the loss of the recommendation module;
[0011] After the loss calculation of the recommendation module is completed, the overall importance evaluation score of each triple in the collaborative knowledge graph is calculated. Based on the overall importance evaluation score, the edge-dropping data enhancement operation is performed to generate two data-enhanced knowledge graphs.
[0012] Aggregate neighbor information for each node on the two data-enhanced knowledge graphs, compare the similarity of the same nodes in the two data-enhanced knowledge graphs, calculate the item similarity score, and generate two data-enhanced interaction graphs as comparative views for comparative learning;
[0013] Using different graph neural network aggregation methods, we alternately learn user and item representations for contrasting views, obtain updated user and item representations, and map the updated user and item representations into a new representation space.
[0014] Based on the new representation space, the similarity of intent distributions between different users and the similarity of their embedding representations are calculated and fused to obtain a final similarity score. A threshold is set to select user pairs with high similarity scores to expand the positive samples for contrastive learning. Using these expanded positive samples, the loss for contrastive learning is calculated. This loss is then added to the loss for recommendation, and the resulting sum is used as the total loss for model training.
[0015] After training is completed, the cosine similarity is used to calculate the similarity between the user and item representations to obtain a score that predicts the possible interaction between the user and the item. The scores are sorted in descending order according to the scores, and the first preset scores are selected as the final recommendation list.
[0016] In summary, this method first constructs a collaborative knowledge graph that fuses the user-item interaction graph and the knowledge graph. It then employs differentiated graph neural network aggregation strategies to learn representations for users and items separately. The user aggregation process explicitly incorporates interaction intent embeddings dynamically composed of knowledge graph relationships, while item aggregation employs lightweight graph convolutions to focus on interaction signals. Subsequently, a learnable attention mechanism is used to evaluate the importance of knowledge graph triplets and, based on this importance, guide edge dropping, generating two enhanced knowledge graphs. The similarity of node representations in the enhanced graphs is further used as a robustness metric to guide the selective dropping of nodes in the interaction graph, forming two comparative views. In the contrastive learning phase, an innovative integrated similarity calculation framework is proposed that fuses user embedding similarity with intent distribution similarity. An adaptive threshold strategy is used to dynamically expand the set of positive samples, and differentiated aggregation methods for users and items are combined to optimize the contrastive loss. Finally, the contrastive learning loss is jointly trained with a recommendation loss based on Bayesian personalized ranking to achieve collaborative optimization of high-quality user and item representations.
[0017] In simple terms, the intent-aware recommendation method based on the fusion of knowledge graph and contrastive learning optimizes node representation by fusing knowledge graph and contrastive learning techniques, thereby improving the recommendation system's accuracy for long-tail items. At the same time, based on data augmentation, the positive sample selection in contrastive learning is expanded in combination with user intent, further strengthening the model's ability to model user intent and ultimately improving the accuracy and relevance of recommendation results. This method explores the comprehensive application of contrastive learning in knowledge graph recommendation using a variety of graph neural network aggregation methods, and deeply explores the deep-level connection between these methods and user intent; it aims to address the problem of significantly reduced long-tail item recommendation accuracy due to poor node representation quality.
[0018] Compared with existing techniques, this method offers the following advantages: 1. It proposes an improved augmentation strategy: First, the overall importance score of each triple in the knowledge graph (obtained through the score of the attention mechanism) is used to guide the edge dropout process. Second, based on the knowledge graph after preliminary augmentation, the similarity scores between nodes are used to guide the node dropout in the interaction graph. These two approaches are combined to perform data augmentation and produce a comparative view for contrastive learning. Compared to random data augmentation methods, this strategy effectively distinguishes important latent connections between the knowledge graph and the recommendation task, preventing the loss of key semantic information. 2. Based on the comparative view, different graph neural network aggregation methods are applied to user and item representations: a user aggregation method that considers the influence of user interaction intent and an item aggregation method that does not consider the influence of intent are alternately aggregated to obtain user and item representations, respectively. These representations are then fed into the contrastive learning framework as samples, improving the quality of user and item representations and, consequently, the performance of the recommendation method. 3. In the positive sample selection process for contrastive learning, we propose a comprehensive user representation similarity calculation method that combines user embedding similarity and intent distribution similarity. The comprehensive similarity score generated by this method, combined with the preset threshold, can effectively identify and select more high-quality positive samples, enrich the diversity of training data, and improve the representation and discrimination capabilities of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 This is a flow chart of an intent-aware recommendation method based on the fusion of knowledge graph and contrastive learning provided by an embodiment of the present invention;
[0020] Figure 2 This is an overall framework diagram of the intent-aware recommendation method based on the fusion of knowledge graph and contrastive learning provided by an embodiment of the present invention;
[0021] Figure 3 Schematic diagram of the training process of the intent-aware recommendation method based on the fusion of knowledge graph and contrastive learning provided by an embodiment of the present invention;
[0022] Figure 4 This is a schematic diagram of edge discarding of a knowledge graph in an intent-aware recommendation method based on the fusion of knowledge graph and contrastive learning provided by an embodiment of the present invention;
[0023] Figure 5 This is a schematic diagram of node discarding in an interaction graph in an intent-aware recommendation method based on the fusion of knowledge graph and contrastive learning provided by an embodiment of the present invention;
[0024] Figure 6 This is a schematic diagram of positive sample expansion in the intent-aware recommendation method based on the fusion of knowledge graph and contrastive learning provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0025] 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.
[0026] refer to Figure 1 As shown, the first embodiment of the present invention discloses an intent-aware recommendation method based on the fusion of knowledge graph and contrastive learning. The method can be executed by an intent-aware recommendation device based on the fusion of knowledge graph and contrastive learning (hereinafter referred to as the recommendation device), and in particular, executed by one or more processors in the recommendation device to implement the following method:
[0027] S1, obtain the original interaction data, pre-process the original interaction data, build a collaborative knowledge graph, input the collaborative knowledge graph into the recommendation module, process it according to the initialization method of ID generation embedding representation, and obtain the representation of users and items;
[0028] Specifically, step S1 further includes: obtaining original interaction data, preprocessing the original interaction data, generating an initial user-item interaction graph and a knowledge graph, and composing according to the initial user-item interaction graph and the knowledge graph to construct a collaborative knowledge graph;
[0029] According to the initialization method of ID-generated embedded representation, each head entity, relationship and tail entity, as well as user entity and item entity in the collaborative knowledge graph are processed to generate a d-dimensional vector representation, where each entity, relationship and user representation is assigned a unique vector value, and the user representation is , items are represented as , the entity is represented as , the relationship is expressed as , for d dimensional real vector space. Unless otherwise specified in this article, the vectors appearing in the formulas are column vectors.
[0030] Specifically, for each user / item ID, an initial representation vector is generated through Xavier uniform initialization. All generated vector representations are traversed, and the current vector is regenerated when a duplicate is detected until the current vector is unique. Ultimately, the initial vector representation assigned by ID is globally unique. The vector generated by Xavier uniform initialization is specifically: , is the initialized vector representation, is the total number of IDs (total number of users or total number of items), is a continuous uniform distribution on the closed interval [a,b].
[0031] After obtaining the initial representations of users and items, different aggregation formulas are used to aggregate the user representations and item representations in the collaborative knowledge graph to update the representations. Specifically, the item representation aggregation formula is used to obtain the item representation. , the formula for item representation aggregation is: , is the item representation of the k-th layer aggregation, is the first-order neighbor set of the item, is an entity in the knowledge graph, The entity representation in the knowledge graph after the k-1th layer aggregation, r is the relationship in the knowledge graph;
[0032] The user representation is obtained by adopting the user representation aggregation formula considering the user's interaction intention , where the formula for user representation aggregation is: , , , represents the initial user that has not been aggregated. is the user representation of the k-th layer aggregation, is the number of aggregation layers, is the set of interaction behaviors of user u through intention ( Contains intent-item pairs , each pair correspond( ),( ) for user u through interaction intention For items to interact), For the user's intention, is the i-th item, is the personalized attention weight of user u for intent q, is the embedded representation of the interaction intention q, is the Hadamard product, is the item representation in the knowledge graph after k-1 layer aggregation, is an exponential function with base e, Indicates user intent The transpose of Intent Set Any user intention in (including q itself), is the user's interaction intention set for the item, is the set of all relations in the knowledge graph, is a trainable scalar parameter, is any relation in the relation set R, For any triple relationship A trainable scalar parameter corresponding to the intent q, is the embedding representation of relation r.
[0033] In this example, the raw interaction records in the dataset are first uniformly preprocessed to generate an initial user-item interaction graph and knowledge graph. For example, low-confidence records with ratings below a preset number of times are removed, and noisy users and items with fewer than a preset number of interactions are filtered out. This ensures the reliability of the training signal while avoiding gradient oscillation caused by excessive cold-start users.
[0034] The system then combines each entry into the initial user-item interaction graph and knowledge graph, leveraging rich semantic information to form a collaborative knowledge graph (CKG). Within this CKG, each head entity, relation, and tail entity, as well as user and item entities, are initialized with a d-dimensional vector representation using the same embedding representation generated by ID. Based on this, a variety of graph neural network aggregation formulas are employed to update the user and item representations separately.
[0035] It should be noted that intent is shared by all users, but its importance varies for different users. In addition, each interaction intent is a semantic combination of various relationships in the knowledge graph. It should be noted that interaction intent is randomly initialized at the beginning of training, but is updated according to the above formula during subsequent training.
[0036] The recommendation module uses an item representation aggregation formula (i.e. Figure 2 Item representations are obtained using the GNNv3 in
[15] . During training, the two aggregation methods are alternated to obtain the final user and item representations. It should be noted that in the recommendation module, the aggregation operation at each layer is performed in an alternating manner, first aggregating items and then aggregating users. That is, items are first aggregated to update item representations, and then users are aggregated based on the updated item representations to update user representations. This alternating aggregation method ensures effective information dissemination between items and users.
[0037] S2, filters out positive and negative samples from the updated item representation, and inputs the positive and negative samples and user representation into the Bayesian Personalized Ranking (BPR) loss function to calculate the loss;
[0038] Specifically, step S2 further includes: selecting item representations that the user has interacted with as positive samples, and randomly selecting multiple item representations that the user has not interacted with as negative samples;
[0039] The user representation, positive samples, and negative samples are input into the Bayesian personalized ranking loss function to calculate the loss of the recommendation module. The formula is: , User u’s preference for item i is greater than item j, is the set of triplets of all users, positive samples and negative samples, is the sigmoid function, is the predicted preference score of user u for the i-th item, is the predicted preference score of user u for the jth item;
[0040] The InfoNCE Loss function is used to process the interaction intention to ensure the independence of the user's interaction intention. Its formula is: , is the cosine similarity, is the temperature parameter, For user intent Embedding representation of .
[0041] In this embodiment, the obtained representations are selected from items with which the user has interacted as positive samples, and representations of items with which the user has not interacted are randomly sampled as negative samples. The user representations and the corresponding positive and negative samples are then input into a Bayesian personalized ranking loss function for optimization. The predicted preference score in the formula is obtained by using the inner product of vectors.
[0042] S3, after the loss calculation of the recommendation module is completed, the overall importance evaluation score of each triple in the collaborative knowledge graph is calculated, and the edge-dropping data enhancement operation is performed based on the overall importance evaluation score to generate two data-enhanced knowledge graphs;
[0043] Each triple in the collaborative knowledge graph is evaluated to determine its importance in the entire collaborative knowledge graph. The evaluation formula is: , , is the head entity in a single triple, is the tail entity in a single triple, is any tail entity among all triples with h as the head entity, are all learnable weight matrices, for The real matrix space of , is any relation among all triples with h as the head entity, is the embedding representation of the head entity, is the embedding representation of the tail entity, is the degree of the head entity, is the embedding dimension, are all triples with h as the head entity, is the final overall importance assessment score, Transpose of the vector;
[0044] According to the final overall importance evaluation score, the relationship of the triple with a lower score is given a higher removal probability. Based on the removal probability, data is discarded to enhance the data and generate two enhanced knowledge graphs KG'1 and KG'2. The removal probability formula is: .
[0045] In this example, a learnable attention mechanism is used to weight each triple in a complex knowledge graph to assess its importance. A normalization function is then used to calculate a local importance score. This local importance score is then multiplied by the number of neighbors of the head entity to determine the overall importance of the triple in the entire knowledge graph. Finally, based on these overall importance scores, edge-dropping data augmentation is performed to generate two data-augmented knowledge graphs.
[0046] Specifically, we need to further calculate the loss of the contrastive learning module. To this end, we first need to perform data augmentation on the original knowledge graph and the user-item interaction graph. It should be noted that although the recommendation module (located in Figure 2 The upper right part of the data) is logically parallel to the loss calculation of the contrastive learning module, but in actual code implementation, it needs to be executed in a serial order (i.e., the loss calculation of the recommendation module is performed first and then the loss calculation of the contrastive learning module). In simple terms, the work of data augmentation is to first evaluate the importance of each triple (head entity, relationship, tail entity) in the knowledge graph in the entire knowledge graph. This means that for those relationships that are considered to contribute less to the recommendation task of the overall model, they will have a greater chance of being removed (such as Figure 4 Through this edge-dropping data augmentation strategy, two enhanced knowledge graphs are generated.
[0047] S4, aggregates neighbor information for each node on the two data-enhanced knowledge graphs, compares the similarity of the same nodes in the two data-enhanced knowledge graphs, calculates the item similarity score, and generates two data-enhanced interaction graphs as comparative views for comparative learning;
[0048] Specifically, step S4 further includes: using the aggregation formula to calculate the two enhanced knowledge graphs KG'1 and KG'2 respectively, and updating the representation of the nodes. The formula is: , , , is the formula for aggregating entities in the knowledge graph, which is used to aggregate the entities in the knowledge graph KG'1 and the knowledge graph KG'2. is the embedding representation of two identical items in the knowledge graph KG'1, is the embedding representation of two identical items in the knowledge graph KG'2, is the new embedding representation obtained after aggregating items in the knowledge graph KG'1. is the new embedding representation obtained after aggregating items in the knowledge graph KG'2. is the item similarity score, which is used to measure the similarity between the new embedding representations obtained by aggregating the representations of the same item in two enhanced graphs;
[0049] Based on the item similarity score, the data enhancement operation of discarding the item nodes in the interaction graph is performed, and the nodes with high item representation quality are retained. Two enhanced interaction graphs are generated and used as the comparison view in contrastive learning. The formula for the discard probability of the item node in the interaction graph is: , is the similarity score of the i-th item.
[0050] In this embodiment, this similarity score reflects the sensitivity of the node to noise. This score is used to guide the selective discarding of nodes in the interaction graph, thereby generating two data-enhanced interaction graphs. These two enhanced interaction graphs will serve as the comparative views for contrastive learning in this method (i.e. Figure 2 Contrast view in Figure 1 and contrast Figure 2 Specifically, we first calculate the similarity score to measure the similarity between the new embedding representations obtained by aggregating the representations of the same item in the two enhanced graphs; the size of the similarity score reflects that the item representation is less sensitive to changes in structural information and has a higher quality. The data enhancement strategy of discarding item nodes in the interaction graph based on the similarity score (such as Figure 5 As shown in Figure 2. Since the similarity score reflects the quality of the item representation, we retain as many nodes with high scores as possible. Based on this similarity score, nodes in the interaction graph can be discarded. It should be noted that the item representations obtained by aggregation before this step will be retained and used as the embedding representation of the corresponding item nodes in the two compared views.
[0051] S5 uses different graph neural network aggregation methods to alternately learn user and item representations for the contrasting views, obtains updated user and item representations, and maps the updated user and item representations to the new representation space;
[0052] Specifically, step S5 further includes: alternately calculating the aggregation formula on the two compared views, and respectively calculating the updated user representation and item representation, wherein the item aggregation formula is used to perform aggregation calculation on the item representation, and the formula is: , is the encoding representation of the i-th item after propagation through the k-th layer, is the set of items that user u has interacted with, is the set of users connected to the i-th item, is the user representation after k-1 layer aggregation in the comparison view;
[0053] Use the user aggregation formula to perform aggregation calculation on the user representation to update the user representation. The formula is: ;
[0054] Among them, the L2 normalization formula is used after the aggregation of each layer to limit the modulus length of each layer output to 1 to avoid numerical instability during the propagation process. The formula is: , The user or item embedding representation output by the aggregation operation of this layer, is the normalized output vector, is the minimum positive value;
[0055] After obtaining multi-layer aggregation information, the average aggregation of each layer is used as the final representation, and the formula is: , , is the final embedding representation of the user, is the final embedding representation of the item, is the total number of aggregation layers of users or items, is the embedded representation after aggregation of users in the k-th layer, It is the embedding representation after aggregation of items in the k-th layer;
[0056] Through two different multi-layer perceptrons, the final embedding representation of the user and the final embedding representation of the item are mapped to the latent space required for contrastive learning in order to decouple feature redundant information and enhance the effect of model training. The mapping formula of the user representation is: , is the activation function with a slope of 0.2, 、 are all weight matrices, 、 are bias vectors, is the aggregated representation of the user, To perform multi-layer perceptron mapping on the user representation vector, generate the user latent vector ;
[0057] The mapping formula for item representation is: , is the representation of the aggregated items, Perform multi-layer perceptron mapping on the item representation vector to generate the item latent vector , and use the mapped user representation and item representation as contrastive learning samples in the contrastive learning loss function;
[0058] The representation of interaction intent is mapped through MLP to obtain a representation space that highlights its core features. The formula is: , , is the layer normalization operation, is the user's interaction intention matrix, The number of user interaction intentions set for the current data. is the interaction intention matrix after mapping, is the output vector of a layer in MLP, is the learnable parameter vector, is the mean, is the variance, is the learnable parameter vector.
[0059] In this embodiment, the user's interaction intention is introduced into the user representation learning process, and this intention is represented by a weighted combination of the relationships in the knowledge graph. This method can more accurately reflect the user's preferences. For the representation of items, the LightGCN method is used for aggregation. This method focuses on extracting the feature information of items from the interaction data to generate high-quality representations of items. Finally, after the aggregation operation is completed, these representations have the opportunity to be selected as positive samples based on the positive sample expansion strategy. This new space can better highlight the core features. This design can not only effectively capture the user's complex behavior patterns, but also improve the accuracy of item representation, thereby enhancing the overall performance of the model.
[0060] Specifically, after obtaining the contrast view, the aggregation formula is applied alternately on the two contrast views to calculate the user representation and the item representation respectively. Among them, x in the L2 normalization formula is the user or item embedding representation output by the aggregation operation of this layer; the minimum positive value can be 10 -9 , used for numerical stability. The user aggregation and item aggregation can be aggregated multiple times. After obtaining multiple layers of aggregation information, the average of each layer of aggregation is used as the final representation.
[0061] After obtaining the final representations of users and items, they are mapped into the latent space required for contrastive learning via two different multi-layer perceptrons (MLPs). These mapped representations, rather than the pre-mapped representations, are used as samples in the contrastive learning loss function. This allows the model to ignore superficial variations introduced by data augmentation and focus on the essential characteristics of users and items. This design enables the model to learn more robust and high-quality representations.
[0062] See also Figure 6 ,S6, based on the new representation space, calculate the similarity of the intention distribution between different users and the similarity of the embedding representation of different users, fuse them to obtain the final similarity score, and use the threshold setting method to select user pairs with high similarity scores as extended positive samples for model training;
[0063] Specifically, step S6 further includes: calculating the similarity between the user and the interaction intention to quantify the association strength between the user and each intention, and the formula is: , is the user-intention similarity matrix, is the current training batch size, For all users, The mapped interaction intention matrix The transpose of
[0064] The user-intention similarity matrix S is softmax normalized in the row direction, and its formula is: , is the user intention weight matrix A The elements in , m is the matrix row subscript, n is the matrix column subscript, is an element in the matrix S;
[0065] Calculate the similarity of intent distribution between different users , is the row vector of the mth row in matrix A, is the row vector transpose of the nth row in matrix A, 、 They are and The L2 norm of Score the similarity of intent distribution between two users m and n;
[0066] The formula for obtaining the similarity of embedding representations of different users is: , and are the embedding representations of user I and user J respectively, 、 They are and The L2 norm of Similarity scores for embedding representations of different users;
[0067] Score the similarity of intent distribution between two users The standardization formula is: , is the minimum similarity score of intent distribution in the current training batch, is the maximum similarity score of intent distribution in the current training batch, is the normalized intent distribution similarity score;
[0068] Similarity scores of embedding representations for different users The standardization formula is: , is the embedding representation similarity score for the current training batch, is the maximum similarity score of the embedding representation in the current training batch, Represent the similarity score for the normalized embedding;
[0069] Score the similarity of intent distribution between two users The standardization formula is: , is the minimum similarity score of intent distribution in the current training batch, is the maximum similarity score of intent distribution in the current training batch, is the normalized intent distribution similarity score;
[0070] Use the hyperparameter T as the threshold and the number of training rounds to expand the selection of positive samples for contrastive learning. The formula is: , where when the similarity score of a sample is greater than T, it is considered as a positive user sample;
[0071] In the early stages of training, the hyperparameter epoch_nums is used to limit the model to only use contrastive views in the first epoch_nums rounds of training. Figure 1 Compared with Figure 2 The same user representation in is used as a user positive sample and input into the user contrastive learning loss of the contrastive learning module, whose formula is: , is the embedding representation of the negative sample corresponding to user i, For users in the comparison view Figure 1 The embedding representation in For users to compare Figure 2 Embedded representation in ;
[0072] The item contrastive learning loss formula is: , For all items collection, is the embedding representation of the negative sample of the item, For item e in the comparison view Figure 1 The embedding representation in For item e in the comparison view Figure 2 Embedded representation in ;
[0073] According to the user contrast learning loss and item contrast learning loss, the total loss of the contrast learning module is: ;
[0074] The total loss of the model is obtained based on the total loss of the contrastive learning module and the recommended loss: , , is the total loss of the model, is the BPR loss, 、 are all weight hyperparameters, The loss of independence of user interaction intentions, is the regularization loss of the embedding representation of users and items, Embedding representation for users, is the embedding representation of the positive sample items in the BPR loss, is the item embedding representation of the negative sample in the BPR loss, is the square of the L2 norm;
[0075] The contrastive learning module and the recommendation module are jointly trained to optimize the overall model and obtain high-quality representations of users and items until the model output reaches the preset standard and the training is completed.
[0076] In this embodiment, when calculating the contrastive loss for user representations, the similarity between user embeddings within the current batch is measured, while the overlap in the distribution of user interaction intentions is also considered. These two similarity scores are dynamically fused using hyperparameters to form a comprehensive user similarity score. Based on this, a threshold is set to select highly similar user pairs as extended positive samples.
[0077] From these mapped embedding representations, some are selected as comparative learning samples for users and items. In traditional self-supervised recommendation learning, the same user nodes in the two comparative views are usually selected as positive samples for comparative learning. However, the strategy of selecting the same users in the two comparative views as positive samples has certain limitations: it does not explicitly consider the preference similarity between users. Users with similar preferences should have high similarity in the representation space, so these user pairs should also be included in the category of positive samples. This method expands the selection of positive samples to improve the effect of comparative learning. It uses a method that fuses the intent distribution similarity between different users with the embedding representation similarity.
[0078] First, the interaction intent representation is mapped through an MLP to obtain a representation space that more prominently highlights its core features. To quantify the strength of the association between the user and each intent, the similarity between the user and the interaction intent is calculated. Softmax normalization is performed along the rows, where the values in each row of the user intent weight matrix reflect the user's weight for each interaction intent. The row vector of the mth row in matrix A is the intent weight vector for user m in the current training batch. The transposed row vector of the nth row in matrix A is the intent weight vector for user n in the current training batch.
[0079] Obtain the similarity of the embedding representations of different users. The user embedding representations are shared with the recommendation module, meaning that the training of the recommendation module affects the user representations here. To unify the numerical scales of the two similarities, the two scores are normalized and then combined to obtain the final similarity score.
[0080] At the same time, in order to adapt to different stages of the training process, a dynamic adjustment strategy is designed: in the early stages of training (before a specific round), each user is considered a positive sample only with their corresponding representation in different comparison views; in the later stages of training, the positive sample set for each user is dynamically increased based on the fusion similarity matrix and the preset threshold. This approach not only enhances the stability of the model in the early stages of training, but also improves the effect of contrastive learning by introducing more high-quality positive samples as training progresses, thereby optimizing the representation ability. When the similarity score of a sample is greater than T, it will be considered a positive sample of the user (such as Figure 6 ).
[0081] S7, after the training is completed, the cosine similarity is used to calculate the similarity between the user and item representations, and a score is obtained to predict the possible interaction between the user and the item. The items are sorted according to the score, and the preset scores are selected as the final recommendation list.
[0082] Specifically, in this embodiment, after training, for any user to be recommended, their final user vector and all item vectors in the candidate set are fed simultaneously into the GPU to calculate cosine similarity, resulting in a continuous score. This score is geometrically represented by the cosine value of the angle between the user and item vectors in a unified latent space. The smaller the angle, the higher the degree of both semantic and collaborative match. To balance real-time response and ranking accuracy, a segmented Top-K strategy is employed: the top K items are selected as the final recommendation list.
[0083] In order to verify the effectiveness of the model and its solution method proposed in this method, the model is tested and evaluated.
[0084] First, the primary application of this method is the Top-K recommendation task. Therefore, the evaluation metrics used are recall and Normalized Discounted Cumulative Gain (NDCG). These two metrics are important criteria for evaluating the performance of recommendation systems. The former focuses on the completeness of the recommendation results, while the latter emphasizes the ranking quality of the recommendation results. The following details these metrics in terms of their definitions and calculation methods.
[0085] Recall measures the proportion of items that the recommendation system successfully recalls from all "real relevant" items, reflecting the completeness of the recommendation, that is, how many items the user actually needs are covered by the recommendation system. For a single user, the calculation formula is: ,in, The Top-k list generated for recommendation to user u, is the set of related items actually needed by user u (real labels), Indicates the number of elements in the collection.
[0086] NDCG is an indicator that considers the quality of recommendation result ranking. Its core idea is that related items that are closer to the front should be given higher weights, while the influence of related items in the back should be reduced through a "discount factor", and different recommendation lists should be made comparable through normalization. For a single user, the corresponding formula is: , , ,in, is the relevance score of the predicted location result, ranging from 0 to 1 (0 for irrelevant and 1 for relevant), It is the relevance score of the ideal sorting (real related items in descending order). DCG reflects whether the items with high relevance are displayed first. DCG is the DCG value when all related items are arranged in the ideal order.
[0087] This method uses the MovieLens-1M and Book-Crossing datasets, both renowned benchmarks in the field of recommender systems, representing classic data sources for movie and book recommendations, respectively. Specifically, the MovieLens-1M dataset only retains interactions with a score of 3 or higher to ensure high-quality interaction data (low-rated interactions may not reflect true user preferences). For the Book-Crossing dataset, all interaction data is retained, given its sparse nature. Table 1 shows basic statistics for these two datasets.
[0088] Table 1 Basic statistical information of the dataset:
[0089]
[0090] The experimental evaluation aims to assess the effectiveness of the knowledge graph recommendation model proposed in this method on various datasets. Specifically, two public datasets, MovieLens-1M and Book-Crossing, were selected. Recall and NDCG were used as evaluation metrics, and the recommendation list length was set to 20. Table 2 presents a comparison of the experimental results of this embodiment's method with existing methods.
[0091] Table 2 Performance comparison of various knowledge graph recommendation methods:
[0092]
[0093] Experimental results show that our approach outperforms other baseline methods in all scenarios. This result fully validates the effectiveness of our approach. Due to the diverse sparsity, features, and recommendation scenarios of knowledge graphs, the evaluation datasets exhibit diversity. This research strongly demonstrates the versatility and flexibility of our approach.
[0094] In summary, this method first constructs a collaborative knowledge graph that fuses the user-item interaction graph and the knowledge graph. It then employs differentiated graph neural network aggregation strategies to learn representations for users and items separately. The user aggregation process explicitly incorporates interaction intent embeddings dynamically composed of knowledge graph relationships, while item aggregation employs lightweight graph convolutions to focus on interaction signals. Subsequently, a learnable attention mechanism is used to assess the importance of knowledge graph triplets and, based on this importance, guide edge dropping, generating two enhanced knowledge graphs. The similarity of node representations in the enhanced graphs is further used as a robustness metric to guide the selective dropping of nodes in the interaction graph, resulting in two contrasting views. In the contrastive learning phase, an innovative integrated similarity calculation framework is proposed that fuses user embedding similarity with intent distribution similarity. An adaptive threshold strategy is used to dynamically expand the set of positive samples, and differentiated aggregation methods for users and items are combined to optimize the contrastive loss. Finally, the contrastive learning loss is jointly trained with a recommendation loss based on Bayesian personalized ranking to achieve collaborative optimization of high-quality user and item representations. It aims to solve the problems in existing technologies such as poor representation quality of long-tail items, insufficient user intent modeling, and limited recommendation accuracy caused by knowledge graph noise interference.
[0095] 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. An intention-aware recommendation method based on the fusion of knowledge graph and contrastive learning, characterized by: include: Obtain and preprocess the raw interaction data to construct a collaborative knowledge graph, input the collaborative knowledge graph into the recommendation module, initialize the representations of items and users using the initialization method of generating embedded representations based on IDs, and then use aggregation formulas for users and items respectively to update the representations of items and users; Filter positive and negative samples from the updated item representations, and input the positive and negative samples and user representations into the Bayesian personalized ranking loss function to calculate the loss of the recommendation module; After the loss calculation of the recommendation module is completed, the overall importance evaluation score of each triple in the collaborative knowledge graph is calculated. Based on the overall importance evaluation score, the edge-dropping data enhancement operation is performed to generate two data-enhanced knowledge graphs. Aggregate neighbor information for each node on the two data-enhanced knowledge graphs, compare the similarity of the same nodes in the two data-enhanced knowledge graphs, calculate the item similarity score, and generate two data-enhanced interaction graphs as comparative views for comparative learning; Using different graph neural network aggregation methods, we alternately learn user and item representations for contrasting views, obtain updated user and item representations, and map the updated user and item representations into a new representation space. Based on the new representation space, the similarity of intent distributions between different users and the similarity of their embedded representations are calculated and fused to obtain a final similarity score. A threshold is set to select user pairs with high similarity scores to expand the positive samples for contrastive learning. These expanded positive samples are used to calculate the loss of the contrastive learning part. Subsequently, this loss is added to the loss of the recommendation part, and the resulting sum is used as the total loss for model training. After training is completed, the cosine similarity is used to calculate the similarity between the user and item representations to obtain a score that predicts the possible interaction between the user and the item. The scores are sorted in descending order according to the scores, and the first preset scores are selected as the final recommendation list.
2. The intention-aware recommendation method based on the fusion of knowledge graph and contrastive learning according to claim 1 is characterized in that: Obtain the original interaction data, pre-process the original interaction data, build a collaborative knowledge graph, input the collaborative knowledge graph into the recommendation module, process it according to the initialization method of ID generation embedding representation, and obtain the initial representation of users and items. Specifically: Obtain the original interaction data, pre-process the original interaction data, generate the initial user-item interaction graph and knowledge graph, and then compose them based on the initial user-item interaction graph and knowledge graph to construct a collaborative knowledge graph; According to the initialization method of ID-generated embedded representation, each head entity, relationship and tail entity, as well as user entity and item entity in the collaborative knowledge graph are processed to generate a d-dimensional vector representation, where each entity, relationship and user representation is assigned a unique vector value, and the user representation is , items are represented as , the entity is represented as , the relationship is expressed as , for d dimensional real vector space; Specifically, for each user / item ID, an initial representation vector is generated through Xavier uniform initialization. All generated vector representations are traversed, and the current vector is regenerated when a duplicate is detected until the current vector is unique. Ultimately, the initial vector representation assigned by ID is globally unique. The vector generated by Xavier uniform initialization is specifically as follows: , is the initialized vector representation, is the total number of IDs, is a continuous uniform distribution on the closed interval [a,b].
3. The intention-aware recommendation method based on the fusion of knowledge graph and contrastive learning according to claim 2 is characterized in that: Different aggregation formulas are used to aggregate the user representation and item representation in the collaborative knowledge graph to update the representation, specifically: After obtaining the initial user and item representations, the item representation aggregation formula is used to obtain the item representation , the formula for item representation aggregation is: , is the item representation of the k-th layer aggregation, is the first-order neighbor set of the item, is an entity in the knowledge graph, is the entity representation in the knowledge graph after the k-1th layer aggregation, and r is the relationship in the knowledge graph; The user representation is obtained by adopting the user representation aggregation formula considering the user's interaction intention , where the formula for user representation aggregation is: , , , represents the initial user that has not been aggregated. is the user representation of the k-th layer aggregation, is the number of aggregation layers, is the set of interaction behaviors of user u through intention, Contains intent-item pairs , each pair correspond( ),( ) for user u through interaction intent For items To interact, For the user's intention, is the i-th item, is the personalized attention weight of user u for intent q, is the embedded representation of the interaction intention q, is the Hadamard product, is the item representation in the knowledge graph after k-1 layer aggregation, is an exponential function with base e, Indicates user intent The transpose of Intent Set Any user intention in , including q itself, is the user's interaction intention set for the item, is the set of all relations in the knowledge graph, is a trainable scalar parameter, is any relation in the relation set R, For any triple relationship A trainable scalar parameter corresponding to the intent q, is the embedding representation of relation r.
4. The intention-aware recommendation method based on the fusion of knowledge graph and contrastive learning according to claim 3 is characterized in that: Positive and negative samples are filtered out from the updated item representations, and the positive and negative samples and user representations are input into the Bayesian personalized ranking loss function to calculate the loss of the recommendation module. Specifically: Select the item representations that the user has interacted with as positive samples, and randomly select multiple item representations that the user has not interacted with as negative samples; The user representation, positive samples, and negative samples are input into the Bayesian personalized ranking loss function to calculate the loss of the recommendation module. The formula is: , User u’s preference for item i is greater than item j, is the set of triplets of all users, positive samples and negative samples, is the sigmoid function, is the predicted preference score of user u for the i-th item, is the predicted preference score of user u for the jth item; The InfoNCE Loss function is used to process the interaction intention to ensure the independence of the user's interaction intention. Its formula is: , is the cosine similarity, is the temperature parameter, For user intent Embedding representation of .
5. The intention-aware recommendation method based on the fusion of knowledge graph and contrastive learning according to claim 4 is characterized in that: After the optimization is completed, the overall importance evaluation score of each triple in the collaborative knowledge graph is calculated. Based on the overall importance evaluation score, the edge-dropping data enhancement operation is performed to generate two data-enhanced knowledge graphs, specifically: Each triple in the collaborative knowledge graph is evaluated to determine its importance in the entire collaborative knowledge graph. The evaluation formula is: , , is the head entity in a single triple, is the tail entity in a single triple, is any tail entity among all triples with h as the head entity, are all learnable weight matrices, for The real matrix space of , is any relation among all triples with h as the head entity, is the embedding representation of the head entity, is the embedding representation of the tail entity, is the degree of the head entity, is the embedding dimension, are all triples with h as the head entity, is the final overall importance assessment score, Transpose of the vector; According to the final overall importance evaluation score, the relationship of the triple with a lower score is given a higher removal probability. Based on the removal probability, data is discarded to enhance the data and generate two enhanced knowledge graphs KG'1 and KG'2. The removal probability formula is: .
6. The intention-aware recommendation method based on the fusion of knowledge graph and contrastive learning according to claim 5 is characterized in that: We aggregate neighbor information for each node on the two data-enhanced knowledge graphs, compare the similarity of the same nodes in the two data-enhanced knowledge graphs, calculate the item similarity score, and generate two data-enhanced interaction graphs as comparative views for comparative learning. Specifically: The aggregation formula is used to calculate the two enhanced knowledge graphs KG'1 and KG'2 respectively to update the node representation. The formula is: , , , is the formula for aggregating entities in the knowledge graph, which is used to aggregate the entities in the knowledge graph KG'1 and the knowledge graph KG'2. is the embedding representation of two identical items in the knowledge graph KG'1, is the embedding representation of two identical items in the knowledge graph KG'2, is the new embedding representation obtained after aggregating items in the knowledge graph KG'1. is the new embedding representation obtained after aggregating items in the knowledge graph KG'2. is the item similarity score, which is used to measure the similarity between the new embedding representations obtained by aggregating the representations of the same item in two enhanced graphs; Based on the item similarity score, the data enhancement operation of discarding the item nodes in the interaction graph is performed, and the nodes with high item representation quality are retained. Two enhanced interaction graphs are generated and used as the comparison view in contrastive learning. The formula for the discard probability of the item node in the interaction graph is: , is the similarity score of the i-th item.
7. The intention-aware recommendation method based on the fusion of knowledge graph and contrastive learning according to claim 6 is characterized in that: Using different graph neural network aggregation methods, we alternately aggregate the user and item representations of the contrasting views to obtain updated user and item representations, and then map the updated user and item representations to the new representation space. Specifically: Alternately calculate the aggregation formula for the two comparison views to calculate the updated user representation and item representation respectively. The item aggregation formula is used to aggregate the item representation. The formula is: , is the encoding representation of the i-th item after aggregation at the k-th layer, is the set of items that user u has interacted with, is the set of users connected to the i-th item, is the user representation after k-1 layer aggregation in the comparison view; Use the user aggregation formula to perform aggregation calculation on the user representation to update the user representation. The formula is: ; Among them, the L2 normalization formula is used after the aggregation of each layer to limit the modulus length of each layer output to 1 to avoid numerical instability during the propagation process. The formula is: , The user or item embedding representation output by the aggregation operation of this layer, is the normalized output vector, is the minimum positive value; After obtaining multi-layer aggregation information, the average aggregation of each layer is used as the final representation, and the formula is: , , is the final embedding representation of the user, is the final embedding representation of the item, is the total number of aggregation layers of users or items, is the embedded representation after aggregation of users in the k-th layer, It is the embedding representation after aggregation of items in the k-th layer; Through two different multi-layer perceptrons, the final embedding representation of the user and the final embedding representation of the item are mapped to the latent space required for contrastive learning in order to decouple feature redundant information and enhance the effect of model training. The mapping formula of the user representation is: , is the activation function with a slope of 0.2, 、 are all weight matrices, 、 are bias vectors, is the aggregated representation of the user, To perform multi-layer perceptron mapping on the user representation vector, generate the user latent vector ; The mapping formula for item representation is: , is the representation of the aggregated items, To perform multi-layer perceptron mapping on the item representation vector, generate the item latent vector , and use the mapped user representation and item representation as contrastive learning samples in the contrastive learning loss function; The representation of interaction intent is mapped through MLP to obtain a representation space that highlights its core features. The formula is: , , is the layer normalization operation, is the user's interaction intention matrix, The number of user interaction intentions set for the current data. is the interaction intention matrix after mapping, is the output vector of a layer in MLP, is the learnable parameter vector, is the mean, is the variance, is the learnable parameter vector.
8. The intention-aware recommendation method based on the fusion of knowledge graph and contrastive learning according to claim 7 is characterized in that: Based on the new representation space, we calculate the similarity of intent distribution between different users and the similarity of embedding representations of different users, and fuse them to obtain the final similarity score, which is: Calculate the similarity between the user and the interaction intention to quantify the strength of the association between the user and each intention. The formula is: , is the user-intention similarity matrix, is the current training batch size, For all users, The mapped interaction intention matrix The transpose of The user-intention similarity matrix S is softmax normalized in the row direction, and its formula is: , is the user intention weight matrix A The elements in , m is the matrix row subscript, n is the matrix column subscript, is an element in the matrix S; Calculate the similarity of intent distribution between different users , is the row vector of the mth row in matrix A, is the row vector transpose of the nth row in matrix A, 、 They are and The L2 norm of Score the similarity of intent distribution between two users m and n; The formula for obtaining the similarity of embedding representations of different users is: , and are the embedding representations of user I and user J respectively, 、 They are and The L2 norm of Similarity scores for embedding representations of different users; Score the similarity of intent distribution between two users The standardization formula is: , is the minimum similarity score of intent distribution in the current training batch, is the maximum similarity score of intent distribution in the current training batch, is the normalized intent distribution similarity score; Similarity scores of embedding representations for different users The standardization formula is: , is the embedding representation similarity score for the current training batch, is the maximum similarity score of the embedding representation in the current training batch, Represent the similarity score for the normalized embedding; Fusion normalized intent distribution similarity score And the normalized embedding represents the similarity score , the formula is: , is the weight hyperparameter, is the final similarity score.
9. The intention-aware recommendation method based on the fusion of knowledge graph and contrastive learning according to claim 8 is characterized in that: The threshold is set to select users with high similarity scores as extended positive samples for model training. Specifically: Use the hyperparameter T as the threshold and the number of training rounds to expand the selection of positive samples for contrastive learning. The formula is: , where when the similarity score of a sample is greater than T, it is regarded as a positive user sample; In the early stages of training, the hyperparameter epoch_nums is used to restrict the model to only use the same user representations in comparison view 1 and comparison view 2 as user positive samples in the first epoch_nums rounds of training, and input them into the user contrastive learning loss of the contrastive learning module, which is formulated as: , is the embedding representation of the negative sample corresponding to user i, is the embedding representation of user i in comparison view 1, is the embedding representation of user j in comparison view 2; The item contrastive learning loss formula is: , For all items collection, is the embedding representation of the negative sample of the item, is the embedding representation of item e in comparison view 1, is the embedding representation of item e in comparison view 2; According to the user contrast learning loss and item contrast learning loss, the total loss of the contrast learning module is: ; The total loss of the model is obtained based on the total loss of the contrastive learning module and the recommended loss: , , is the total loss of the model, is the BPR loss, 、 are all weight hyperparameters, The loss of independence of user interaction intentions, is the regularization loss of the embedding representation of users and items, Embedding representation for users, is the embedding representation of the positive sample items in the BPR loss, is the item embedding representation of the negative sample in the BPR loss, is the square of the L2 norm; The contrastive learning module and the recommendation module are jointly trained to optimize the overall model and obtain high-quality representations of users and items until the model output reaches the preset standard and the training is completed.
Citation Information
Patent Citations
Knowledge perception-based graph self-supervised learning recommendation method
CN117634600A
Knowledge perception recommendation method based on comparative learning
CN118627606A