Multi-task conversational sequence recommendation method based on graph contrastive learning and bidirectional transformer
By employing a multi-task session sequence recommendation method based on graph contrastive learning and bidirectional Transformer, this approach addresses the issues of short-term user preferences and new user recommendations in existing technologies, achieving higher recommendation accuracy and data acquisition efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NANJING TECH UNIV
- Filing Date
- 2023-10-20
- Publication Date
- 2026-07-21
Smart Images

Figure CN117609599B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of information recommendation technology, specifically to a multi-task session sequence recommendation method based on graph contrastive learning and bidirectional Transformer. Background Technology
[0002] Recommendation technology is a method for users to quickly and effectively filter out objects that match their preferences from a massive amount of data. It is widely used in various Internet services and plays an important role in e-commerce, advertising, and social media.
[0003] Existing research on recommender systems primarily focuses on leveraging historical user-item interaction data (direct or indirect user actions such as clicks and favorites) to understand long-term user behavior and static item preferences. However, this approach has several limitations: First, a user's choice of items depends not only on their long-term historical preferences but also on their short-term recent preferences and time-sensitive contexts; considering only historical interaction data ignores the dynamic nature of user preferences. Second, it's impossible to collect historical preference data from new users who haven't logged into the platform. Third, with increasing concerns about online privacy, obtaining long-term user data is becoming increasingly difficult. To address these issues, research and development on conversation-based recommender systems has recently emerged and attracted growing attention.
[0004] Conversation-based recommendation also has an inherent problem: it doesn't consider user information within the recommendation system, resulting in limited available information. Some studies have considered leveraging user micro-operations, but these either only consider micro-operations or ignore the feature differences between items and operations, failing to fully realize the advantages of micro-operation behavior in conversational recommendation. Summary of the Invention
[0005] This invention proposes a multi-task session sequence recommendation method based on graph contrastive learning and bidirectional Transformer. The aim is to separate the more specific micro-operations in user interactions beyond macro-level items. By modeling both macro-level item sequences and micro-operation sequences separately, it captures users' fine-grained interests and preferences, thereby improving the accuracy of the recommendation system. The method includes the following steps:
[0006] S1: Split the user's historical interaction sequence to obtain the item sequence and operation sequence, and initialize the embedding matrix for each;
[0007] S2: Model the item sequence using GNN and graph contrastive learning to obtain the learned item embeddings;
[0008] S3: Use a bidirectional Transformer to model the operation sequence and obtain the learned operation embeddings;
[0009] S4: Concatenate the item and operation embeddings, input them into the MLP layer, and obtain the prediction score through the softmax operation;
[0010] S5: Construct loss functions separately, and combine them using a multi-task learning strategy for joint optimization.
[0011] Based on the above, the specific steps of S1 are as follows:
[0012] S11: Decompose the user's historical interaction sequence, breaking down each user interaction with a specific item into the item and the specific action. Performing this transformation on a given interaction sequence yields an item sequence and an action sequence, such as:
[0013] (Computer, computer, mobile phone, mobile phone, mobile phone, headphones, mouse, mouse)
[0014] (Click to read reviews, click to add to cart, click to purchase, click to add to favorites)
[0015] The lengths of the project sequence and the operation sequence should be the same.
[0016] S12: Then initialize the embedding matrices for the item set and operation set respectively, for use in subsequent query embeddings.
[0017] Based on the above, the specific steps of S2 are as follows:
[0018] S21: Construct a weighted item transformation graph of the item sequence. Remove all consecutive repeating items from the sequence to obtain a traditional item sequence S. I ′={i1,i2,…i k}, where i k (k≤L) form the nodes in the graph, (i k-1 i k An edge is formed between two points, representing a user in session S who, at the macro-level of the project and without considering micro-operations, clicked on item i. k-1 Then, I clicked on project i. k This forms the basic structure of the weighted project transformation graph. Then, for each project i... k ∈S I ′, if in the diagram There exists an edge in project i t and i (t+h) If the edges are in between, then the updated edge weights are w(i). t i t+h )←w(i t i t+h Add 1 / h to the new edge weight, where h ∈ {1, 2, 3}, representing the distance between the two items. After repeating the above process for all item sequences, a weighted item transition graph is obtained. Weighted Project Transformation Diagram Two nodes i i and i j The normalized edge weights between them are expressed mathematically as follows:
[0019]
[0020] Where deg(·) represents The degree of the nodes in the array.
[0021] S22: Construct two enhanced views for the interaction sequence S through data augmentation. The construction method is as follows: treat each node v∈S in S as the center node, set the sampling depth M to 2, and set the sampling size N to 20 in each step to progressively sample its position in the weighted item transformation graph. In the neighbor sampling process, only nodes are sampled uniformly without considering edge weights. Then, the edges between sampled nodes and their corresponding weighted item transformation graphs are retained. The weights in the sequence S I By employing graph-based augmentation, two augmented views can be obtained in both cases. and Here I′ S E′ S A′ S They are The node set, edge set, and adjacency matrix; I″ S ,E″ S ,A″ S They are G′ is the set of nodes, the set of edges, and the adjacency matrix. S and G″ S It is a weighted project transformation diagram. Subgraphs.
[0022] S23: Encoded using two graph neural networks (GNNs) with shared parameters. and The mathematical expressions for information propagation and aggregation in the t-th layer of a graph neural network are as follows:
[0023]
[0024]
[0025] This indicates that project i i The feature representation obtained after feature aggregation with neighboring nodes. This involves combining the aggregated features with the features of the node itself to form a new feature representation. These two operations are used to update node information. express in i i The neighborhood group, In the t-th GNN layer, the i-th... i Item representation, initial layer The i-th item is obtained by looking up the item embedding matrix. i The term indicates that Aggregate(·) is the aggregation center node v. i The function that incorporates neighborhood information, Combine(·), is a function that updates node embeddings by combining neighborhood information.
[0026] exist After multiple layers of information propagation, the embedding of the node in the last GNN layer S is represented as follows: This is an enhanced representation of S based on Similarly, an enhanced representation of another interaction sequence S can be obtained from the enhanced view G.
[0027] S23: Graph contrastive learning is used as an auxiliary learning objective for item sequences to ensure that representations obtained from augmented views of the same sequence are similar, while representations obtained from augmented views of different sequences are dissimilar. Its loss function... It is expressed as follows:
[0028]
[0029] in By respectively at H′ S and H″ S The mean pooling is performed to obtain z″. K This is obtained by performing the same operation on views of different sequences. cos(·,·) is the cosine similarity function, and τ is a hyperparameter, which is set to 0.5 empirically in the experiment;
[0030] S24: The learned H′ S and H″ S Connecting them together yields the final learned item embedding matrix.
[0031] Based on the above, the specific steps of S3 are as follows:
[0032] S31: The operation sequence is fed into the embedding layer and converted into an embedding vector. The conversion method is as follows: In the embedding layer, the embedding matrix is manipulated. and position embedding matrix Combined together to construct a hidden representation of the operation sequence Here, L represents the maximum sequence length of the model, d represents the hidden dimension, and given an operation... Its hidden representation The mathematical expression is as follows:
[0033]
[0034] For a given S O Operations in Its initial embedding It is obtained by searching the embedding matrix O.
[0035] S32: Encode the operation sequence using Transformer. Embed the positional information... Stacked together to form a matrix As a hidden representation of the entire sequence. Suppose we have... O 0 The transmission is performed through a bidirectional Transformer block at layer L, and the specific steps are as follows:
[0036]
[0037] Hidden representation from the last layer L The output is taken as the final output of the bidirectional Transformer encoder.
[0038] S33: Introduce a fill-in-the-blank task to train the bidirectional Transformer. For each iteration step, given the operation sequence S... O , sequence S O All operations are randomly replaced with masking markers [mask] according to a ratio ρ, and the position index of the masked item is represented by I. The model needs to reconstruct the masked items. The loss function for the fill-in-the-blank task as the main training objective is defined as follows:
[0039]
[0040] Where σ is the sigmoid function, and the probability P(·) is defined as follows:
[0041] P(o) = W P h t +b P
[0042] in It is a weight matrix. It is a bias term. This represents the probability of the true target value. A randomly selected negative sample The goal is to maximize the probability of the true value and minimize the probability of the negative sample.
[0043] Based on the above, the specific steps of S4 are as follows:
[0044] S41: Concatenate the learned operation embeddings and item embeddings to obtain the final session representation. Its mathematical expression is as follows:
[0045]
[0046] This indicates concatenation operations. Through this process, even if the item sequences in two sessions are the same, different operation sequences will generate different representations, which can capture more personalized user interests and intentions.
[0047] S42: The final session representation is fed as a whole into a multi-head perceptron layer (MLP), followed by a softmax operation to compute the score that may be the next recommendation.
[0048]
[0049] Based on the above, the specific steps of S5 are as follows:
[0050] S51: The loss function for predicting the next recommendation is defined as:
[0051]
[0052] Where S represents the set of sequences, and D represents the set of items. sj This indicates that if item j is the next item in session s, then...
[0053] y = 1, otherwise y = 0; This indicates the predicted score that item j in session s might be used as the next recommendation.
[0054] S52: By combining all the above loss functions using a multi-task learning strategy, the overall loss function of the model is obtained as follows:
[0055]
[0056] Where α, β, and λ are hyperparameters that balance the weights of each loss and the strength of L2 regularization; Θ is the set of model parameters.
[0057] This invention proposes a multi-task session sequence recommendation method based on graph contrastive learning and bidirectional Transformer, addressing the issues from three perspectives: separating user micro-operations, modeling item sequences and operation sequences separately, and jointly optimizing using a multi-task learning strategy. Compared to existing technologies, the advantages of this invention are:
[0058] 1. Compared with traditional sequence recommendation, this invention is a session-based sequence recommendation that does not contain sensitive user information, making it easier and cheaper to obtain data in practice.
[0059] 2. Compared with traditional sequence recommendation, this invention takes into account the specific operations in user interaction, models them according to their characteristics, and mines the more granular interests and preferences of users hidden behind specific operational behaviors, thereby improving the accuracy of recommendations.
[0060] 3. A multi-task learning strategy is adopted, which introduces a contrastive learning task and a fill-in-the-blank task as auxiliary learning objectives in addition to the conventional learning objectives, thereby enhancing the overall learning effect of the model. Attached Figure Description
[0061] Figure 1 This is a flowchart illustrating a multi-task session sequence recommendation method based on graph contrast learning and bidirectional Transformer in an embodiment of the present invention. Detailed Implementation
[0062] The technical solution of the present invention will be further described below with reference to the accompanying drawings and specific embodiments.
[0063] 1. Training dataset
[0064] This invention uses the Trivago Dataset as an example, which comes from the globally renowned hotel search platform trivago. It contains user actions related to hotels, including "interactive item images," "interactive item information," "interactive item ratings," and "interactive item transactions." This paper removes operation types whose values do not contain items, such as "search destination" and "filter selection," retaining only the last six specific operation types. To verify the model's effectiveness, items appearing less than 5 times in the Trivago dataset are filtered out, and 70%, 10%, and 20% are used as the training, validation, and test sets, respectively; the last item in each session is used as the true value predicted by the model. Furthermore, sessions containing only one item in the training and test sets are also removed. After preprocessing, the training, validation, and test sets contain 260,877, 37,027, and 74,770 session sequences, respectively. There are 183,561 macro-items and 5,726,369 micro-operations, respectively.
[0065] 2. Split the user's historical interaction sequence to obtain the item sequence and operation sequence, and initialize the embedding matrix for each.
[0066] Training data is obtained from the above dataset. The user interaction sequence is split to obtain the item sequence and the operation sequence. The item set and operation set are then initialized with embedding, which includes the following steps:
[0067] Step 1: Process the user interaction sequence. Break down each user interaction with hotel items into items and specific actions, resulting in a sequence of items. and a sequence of operations As input data for the entire model, proceed to step two.
[0068] Step 2: To facilitate computer processing of high-dimensional sparse data, the item set and operation set are embedded by randomly initializing an item embedding matrix and an operation embedding matrix of dimension d, respectively. The model input is then: an item sequence. and operation sequence It can be converted into two embedding matrices by looking up a table. and
[0069] 3. Modeling the project sequence
[0070] Modeling the item sequence using GNN and graph contrastive learning to obtain the learned item embeddings involves the following steps:
[0071] Step 1: Construct a weighted transformation diagram of the project, based on the project sequence. For example, since an item often appears repeatedly in a sequence of items, such as in... Figure 1 The item sequence of session s1 in the graph is {i1,i1,i1,i2,i2}. Therefore, to construct a better graph, we first remove consecutively repeated items from the sequence, resulting in a traditional item sequence S. I′ ={i1,i2,…i k}, where i k (k≤L) form the nodes in the graph, (i k-1 i k An edge is formed between two points, representing a user in session S who, at the macro-level of the project and without considering micro-operations, clicked on item i. k-1 Then, I clicked on project i. k This forms the basic structure of the weighted project transformation graph. Then, for each project i... k ∈S I′ If in the diagram There exists an edge in project i t and i(t+h) If the edges are in between, then the updated edge weights are w(i). t i t+h )←w(i t i t+h Add 1 / h to the new edge weight, where h ∈ {1, 2, 3}, representing the distance between the two items. After repeating the above process for all item sequences, a weighted item transition graph is obtained. Weighted Project Transformation Diagram Two nodes i i and i j The normalized edge weights between them are expressed mathematically as follows:
[0072]
[0073] Where deg(·) represents The degree of the nodes in the array. After repeating the above process for all item sequences, a weighted item transition graph is obtained, and then proceed to step two;
[0074] Step 2: Obtain the weighted project transformation diagram Subsequently, two enhanced views are constructed for the interaction sequence S through data augmentation. Each node v∈S in S is considered a central node, and the sampling depth M is empirically set to 2, with the sampling size N set to 20 at each step to progressively sample its position within the sequence. The neighbors in the sample are considered. During the sampling process, only nodes are sampled uniformly, without considering edge weights. Then, the edges between the sampled nodes and their neighbors in the sample are retained. The weights in the sequence S. For each sequence S I By employing graph-based augmentation, two augmented views can be obtained in both cases. and Proceed to step three;
[0075] Step 3: Encode using two graph neural networks (GNNs) with shared parameters. and by For example, the information propagation and aggregation in the t-th layer of a graph neural network are as follows:
[0076]
[0077]
[0078] This indicates that project i i The feature representation obtained after feature aggregation with neighboring nodes. This involves combining the aggregated features with the features of the node itself to form a new feature representation. These two operations are used to update node information. express in i i The neighborhood group, In the t-th GNN layer, the i-th... i Item representation, initial layer The i-th item is obtained by looking up the item embedding matrix. i The term indicates that Aggregate(·) is the aggregation center node v. i The function `Combine(·)` combines neighborhood information to update node embeddings; similarly, an enhanced representation of another interaction sequence `S` can be obtained from the enhanced view `G`. Proceed to step four.
[0079] Step 4: Utilize graph contrastive learning as an auxiliary learning objective for the project sequence to ensure that representations obtained from augmented view views of the same sequence are similar, while representations obtained from augmented view views of different sequences are dissimilar.
[0080]
[0081] in By respectively at H′ s and H″ S The result is obtained by performing mean pooling. cos(·,·) is the cosine similarity function, and τ is a hyperparameter, which is set to 0.5 empirically in the experiment. Proceed to step five;
[0082] Step 5: Transfer the learned H′ S and H″ S Connecting them together yields the final learned item embedding matrix.
[0083] 4. Modeling the operation sequence
[0084] The operation sequence is modeled using a bidirectional Transformer to obtain the learned operation embeddings, which includes the following steps:
[0085] Step 1: Feed the operation sequence into the embedding layer to convert it into an embedding vector. The conversion method is as follows: In the embedding layer, operate on the embedding matrix. and position embedding matrix These are combined to construct a hidden representation of the operation sequence. Here, L represents the maximum sequence length of the model, and d represents the hidden dimension. Given an operation... Its input can be represented as follows:
[0086]
[0087] For a given S O Operations in Its initial embedding It is obtained by searching the embedding matrix O. Proceed to step two;
[0088] Step 2: Introduce a fill-in-the-blank task to train the bidirectional Transformer. For each iteration step, given the operation sequence S... O , sequence S O All operations are randomly replaced with masking markers [mask] according to a ratio ρ, and the position index of the masked item is represented by I. The model needs to reconstruct the masked items. The loss function for the fill-in-the-blank task as the main training objective is defined as follows:
[0089]
[0090] Where σ is the sigmoid function, and the probability P(·) is defined as follows:
[0091] P(o) = W P h t +b P
[0092] in It is a weight matrix. It is a bias term. This represents the probability of the true target value. A randomly selected negative sample The goal is to maximize the probability of the true value and minimize the probability of the negative sample.
[0093] 5. Obtain the final prediction score;
[0094] The project and operation embeddings are concatenated and input into an MLP layer. The prediction score is obtained through a softmax operation, which includes the following steps:
[0095] Step 1: Concatenate the learned operation embeddings and project embeddings to obtain the final conversation representation. Its mathematical expression is as follows:
[0096]
[0097] This indicates a concatenation operation. Through this process, even if the item sequences in two sessions are the same, different representations will be generated due to different operation sequences. This can capture more personalized user interests and intentions, leading to step two.
[0098] Step 2: Obtain the final representation of the session sequence s Then, it is compared with the embedding of candidate item j. j The input is fed into a multi-head perceptron layer MLP, then a softmax operation is performed to calculate the score that could be the next recommendation.
[0099]
[0100] 6. Construct the loss function and optimization model
[0101] The loss functions are constructed separately, and then combined using a multi-task learning strategy for joint optimization, which includes the following steps.
[0102] Step 1: The loss function for predicting the next recommendation is defined as:
[0103]
[0104] Proceed to step two;
[0105] Step 2: Combine all the above loss functions using a multi-task learning strategy to obtain the overall loss function of the model as follows:
[0106]
[0107] Where α, β, and λ are hyperparameters that balance the weights of each loss and the strength of L2 regularization; Θ is the set of model parameters.
Claims
1. A multi-task session sequence recommendation method based on graph contrastive learning and bidirectional Transformer, characterized in that, Includes the following steps: S1: Split the user's historical interaction sequence to obtain the item sequence and operation sequence, and initialize the embedding matrix for each; S2: Model the item sequence using GNN and graph contrastive learning to obtain the learned item embeddings; S3: Use a bidirectional Transformer to model the operation sequence and obtain the learned operation embeddings; S4: Concatenate the item and action embeddings, input them into the MLP layer, and obtain the prediction score through softmax operation. Actions include clicking and reading comments. Click to add to cart and purchase; click to add to favorites; S5: Construct loss functions separately, and combine them using a multi-task learning strategy for joint optimization; The specific steps of S2 are as follows: S21: Construct a weighted project transformation graph of the project sequence. : Remove all consecutive repeating items from the sequence to obtain a traditional item sequence. , among them The nodes that make up the graph An edge between two points represents the user in a session. In the context of macro-level projects without considering micro-level operations, after clicking on a project... Then, I clicked on the project. ; After that, for each project If in the diagram There exists an edge in the project and If the edges are in between, then the updated edge weights are... Set the weight of the new edge to ,in , indicating the distance between two items, for After repeating the above process for all item sequences, a weighted item transition graph is obtained. Weighted project conversion diagram Two nodes and The normalized edge weights between them are expressed mathematically as follows: in, express The degree of the nodes in the array; S22: Construct two enhanced views for the interaction sequence S through data augmentation. The construction method is as follows: for each node in S... Treating it as the central node, the sampling depth M is set to 2, and the sampling size N is set to 20 in each step to progressively sample its position in the weighted item transformation graph. In the neighbor sampling process, only nodes are sampled uniformly without considering edge weights. Then, the edges between sampled nodes and their corresponding weighted item transformation graphs are retained. The weights in the sequence, for each sequence By employing graph-based augmentation, two augmented views can be obtained in both cases. and ; here , , They are The node set, edge set, and adjacency matrix; They are The node set, edge set, and adjacency matrix. and It is a weighted project transformation diagram. Subgraph; S23: Encoding via two graph neural networks (GNNs) with shared parameters The mathematical expressions for information propagation and aggregation in the t-th layer of a graph neural network are as follows: Indicates the project The feature representation obtained after feature aggregation with neighboring nodes. This means combining the aggregated features with the features of its own node layer to form a new feature representation. Through these two steps, the node information is updated. express middle The neighborhood group, In the t-th GNN layer, the first... Item representation, initial layer The first one is obtained by looking up the item embedding matrix. The item indicates that, It is the aggregation center node A function of neighborhood information It is a function that combines neighborhood information to update node embeddings; exist After multi-layer information propagation, the embedding of the node in the last GNN layer S is represented as follows: This is the enhanced representation of S based on... Similarly, an enhanced representation of another interaction sequence S can be obtained from the enhanced view G. ; S23: Utilize graph contrastive learning as an auxiliary learning objective for item sequences to ensure that representations obtained from augmented views of the same sequence are similar, while representations obtained from augmented views of different sequences are dissimilar. Its loss function... It is expressed as follows: in , By respectively in and The result is obtained by performing mean pooling. These are obtained by performing the same operation on views from different sequences. It is the cosine similarity function. It is a hyperparameter, which was set to 0.5 based on experience in the experiment; S24: After learning and Connecting them together yields the final learned item embedding matrix. .
2. The multi-task session sequence recommendation method based on graph contrastive learning and bidirectional Transformer according to claim 1, characterized in that, The specific steps of S1 are as follows: S11: Decompose the user's historical interaction sequence, breaking down each user interaction with a certain item into the item and the specific operation behavior; performing this transformation on a certain interaction sequence will yield an item sequence and an operation sequence, and the lengths of the item sequence and the operation sequence should be the same; S12: Then initialize the embedding matrices for the item set and operation set respectively, for use in subsequent query embeddings.
3. The multi-task session sequence recommendation method based on graph contrastive learning and bidirectional Transformer according to claim 1, characterized in that, The specific steps of S3 are as follows: S31: The operation sequence is fed into the embedding layer and converted into an embedding vector. The conversion method is as follows: In the embedding layer, the embedding matrix is manipulated. and position embedding matrix Combined together to construct a hidden representation of the operation sequence Here, L represents the maximum sequence length of the model, d represents the hidden dimension, and given an operation... Its hidden representation The mathematical expression is as follows: For a Operations in Its initial embedding Embedded matrix through lookup operation What was obtained ; S32: Encode the operation sequence using Transformer; embed the positional information into the sequence. Stacked together to form a matrix As a hidden representation of the entire sequence, suppose we have ,Will The transmission is performed through a bidirectional Transformer block at layer L, and the specific steps are as follows: Hidden representation from the last layer L The output is taken as the final output of the bidirectional Transformer encoder; S33: Introduce a fill-in-the-blank task to train the bidirectional Transformer; for each iteration step, given the sequence of operations... ,sequence All operations in the code are randomly replaced with mask markers [mask] according to a certain ratio, and the position index of the masked item is represented as... The model needs to reconstruct the masked items, and the loss function for the fill-in-the-blank task as the main training objective is defined as follows: Where is the sigmoid function, and the probability is... The definition is as follows: in It is a weight matrix. It is a bias term. This represents the probability of the true target value. A randomly selected negative sample The goal is to maximize the probability of the true value and minimize the probability of the negative sample.
4. The multi-task session sequence recommendation method based on graph contrastive learning and bidirectional Transformer according to claim 1, characterized in that, The specific steps of S4 are as follows: S41: Concatenate the learned operation embeddings and item embeddings to obtain the final session representation. Its mathematical expression is as follows: in Indicates the first [number] after splicing Micro-behavior, Indicates the sequence of items in Projects that are constantly interactive Indicates in The specific operations performed on the interactive project at any given time. This indicates concatenation operations. Through this process, even if the item sequences in two sessions are the same, different representations will be generated due to different operation sequences. This can capture users' more personalized interests and intentions. S42: Obtain the session sequence The final expression Then, it was compared with the candidate projects. Embedded The input is fed into a multi-head perceptron layer MLP, then a softmax operation is performed to calculate the score that could be the next recommendation. : 。 5. The multi-task session sequence recommendation method based on graph contrastive learning and bidirectional Transformer according to claim 1, characterized in that, The specific steps of S5 are as follows: S51: The loss function for predicting the next recommendation is defined as: Where S represents the set of sequences and D represents the set of items. Indicates if project It is a conversation When the next project is completed, ,otherwise ; Representing a session Medium-sized projects This may be used as the predicted score for the next recommendation; S52: By combining all the above loss functions using a multi-task learning strategy, the overall loss function of the model is obtained as follows: in , , It is to balance the weights of each loss and Hyperparameters of regularization strength; It is a set of model parameters.