Contrast loss recommendation method and device based on attention mechanism optimized embedding weight
By introducing an attention mechanism into the recommender system to optimize the contrastive loss method for embedding weights, the problem that hypergraph models cannot distinguish the importance of nodes is solved, the performance and user experience of the recommender system are improved, and more accurate user-item interaction capture and recommendation are achieved.
Patent Information
- Application Number
- CN202511079868.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-04
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2045-08-04
AI Technical Summary
Existing hypergraph models cannot effectively distinguish the importance of different nodes in hyperedges in recommendation systems, leading to information loss and affecting the accuracy and user experience of recommendation systems.
A contrastive loss recommendation method based on attention mechanism to optimize embedding weights is adopted. By constructing a uniform initialization module, a linear transformation and attention module, and a segmentation and preference recommendation module, and combining the hypergraph embedding matrix and attention mechanism, the embedding weights are dynamically adjusted to optimize the model's ability to distinguish between positive and negative samples.
It significantly improves the performance and user experience of the recommendation system, enabling it to more accurately capture key aspects of user-item interactions, thereby enhancing the accuracy of the recommendation system and user satisfaction.
Smart Images

Figure CN120580032B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of personalized recommendation, more particularly, to a contrast loss recommendation method and device based on attention mechanism optimized embedding weight. BACKGROUND
[0002] With the development and popularization of the Internet, the amount of information users face has shown an explosive growth. In this case, it is difficult for users to quickly find the products they are interested in. The personalized recommendation system filters out the content matching the user's interest from the vast amount of information by analyzing the interaction behavior between the user and the item, greatly improving the efficiency of information acquisition. The personalized recommendation system has become an important tool to solve the problem of information overload.
[0003] In the field of e-commerce, personalized product recommendations are provided based on the user's browsing history and purchase records, thereby improving sales and user satisfaction. In social media platforms, content of interest to users is recommended based on their interests, social relationships, and interaction behavior. In content streaming platforms, a series of interactive information such as user viewing history, historical ratings, and song listening records are used to improve the user's viewing experience. The personalized recommendation system provides customized content and services by analyzing the interaction behavior of users and items and user preferences, improving user experience and satisfaction. At the same time, the personalized recommendation system also increases sales and user stickiness for enterprises, optimizes ad placement, and helps enterprises gain an advantage in fierce market competition. With the continuous progress of technology and the continuous improvement and innovation of the recommendation system, the personalized recommendation system will play an increasingly important role in the future and bring greater business value and competitive advantage.
[0004] Many recent studies explore the use of graphs to represent high-order collaborative relationships in graph-enhanced collaborative filtering models. Graph neural networks have also become effective components for representing user-item relationships in recommendation system modeling. Inspired by the generalization ability of hypergraphs to model complex high-order dependencies, a series of recommendation systems have been developed recently that can capture and construct hypergraph structures and unified node and hyperedge connections. However, existing hypergraph models, while able to capture multi-order relationships between items and users, often fail to distinguish the importance of different nodes in hyperedges. And in hypergraph neural networks, nodes become similar after multiple layers of traditional graph convolution, resulting in information loss. These will result in the inability of previous recommendation systems to fully grasp the user's interaction behavior, leading to unsatisfactory results for user recommendations. SUMMARY
[0005] The present application aims to provide a contrast loss recommendation method and device based on attention mechanism optimized embedding weight, which can improve the performance of the recommendation system and user experience.
[0006] The application provides a contrast loss recommendation method based on attention mechanism optimization embedding weight, comprising the following steps: S1: obtaining relevant data of users and items, dividing the relevant data of the users and the items to obtain a training set and a test set; the relevant data of the users and the items includes user feature data, item feature data, positive feedback data and negative feedback data; S2: constructing a recommendation model, training the recommendation model by using the training set to obtain a trained recommendation model; the recommendation model includes a uniform initialization module, a linear transformation and attention module, a segmentation and preference recommendation module; S3: according to the test set, using the trained recommendation model to obtain an item recommendation list of each user.
[0007] Further, the step S2 of the contrast loss recommendation method based on attention mechanism optimization embedding weight specifically comprises: S21: constructing a uniform initialization module, which is used to obtain a user initial embedding matrix, an item initial embedding matrix, a user hypergraph embedding matrix and an item hypergraph embedding matrix by using a uniform initialization method according to the user feature data and the item feature data; S22: constructing a linear transformation and attention module, which is used to obtain a final embedding matrix by using a linear transformation method and an attention mechanism according to the user initial embedding matrix, the item initial embedding matrix, the user hypergraph embedding matrix and the item hypergraph embedding matrix; S23: constructing a segmentation and preference recommendation module, which is used to obtain a user embedding matrix and an item embedding matrix by segmenting the final embedding matrix, and obtain an item recommendation list of each user according to the user embedding matrix and the item embedding matrix; S24: obtaining a recommendation model according to the uniform initialization module, the linear transformation and attention module and the segmentation and preference recommendation module; S25: constructing a loss function, training the recommendation model by using the loss function according to the training set to obtain a trained recommendation model.
[0008] Further, the step S21 of the contrast loss recommendation method based on attention mechanism optimization embedding weight specifically comprises: constructing a uniform initialization module, which is used to obtain a user initial embedding matrix, an item initial embedding matrix, a user hypergraph embedding matrix and an item hypergraph embedding matrix by using a uniform initialization method according to the user feature data and the item feature data, as shown in the formula:
[0009] , ,
[0010] ,
[0011] , ,
[0012] , ,
[0013] wherein, and denote the set of users and items respectively, is the embedding dimension, denotes the number of hyper-edges, denotes the number of users, denotes the number of items, denotes the uniform initialization method, denotes the user initial embedding matrix, denotes the item initial embedding matrix, denotes the user hypergraph embedding matrix, denotes the item hypergraph embedding matrix.
[0014] Further, the step S22 of the above-mentioned contrastive loss recommendation method for optimizing embedding weights based on an attention mechanism specifically comprises: S221, constructing an attention score module, which is configured to obtain user attention scores and item attention scores by using a linear transformation method according to the user initial embedding matrix and the item initial embedding matrix; S222, constructing an attention weight module, which is configured to obtain user attention weights and item attention weights by normalizing the user attention scores and the item attention scores; S223, constructing a user-item hypergraph embedding module, which is configured to obtain a user-item hypergraph embedding matrix according to the user attention weights, the item attention weights, the user hypergraph embedding matrix and the item hypergraph embedding matrix; S224, constructing a fusion module, which is configured to obtain a final embedding matrix according to the user-item hypergraph embedding matrix, the user initial embedding matrix and the item initial embedding matrix; S225, obtaining a linear transformation and an attention module according to the attention score module, the attention weight module, the user-item hypergraph embedding module and the fusion module.
[0015] Further, the step S221 of the above-mentioned contrastive loss recommendation method for optimizing embedding weights based on an attention mechanism specifically comprises: constructing an attention score module, which is configured to obtain user attention scores and item attention scores by using a linear transformation method and an attention mechanism, as shown in the following formula:
[0016] , ,
[0017] , ,
[0018] wherein, is a user attention score, is an intermediate variable, is a user attention mechanism weight matrix, is a user linear transformation matrix, is a user initial embedding matrix, is a user bias vector; is an item attention score, is an intermediate variable, is an item attention mechanism weight matrix, is an item linear transformation matrix, is an item initial embedding matrix, is an item bias vector.
[0019] Further, the step S222 of the above-mentioned contrastive loss recommendation method based on attention mechanism optimization embedding weight specifically comprises: constructing an attention weight module, which is configured to: normalize the user attention score and the item attention score to obtain a user attention weight and an item attention weight, as shown in the following formula:
[0020] ,
[0021] ,
[0022] wherein, represents the attention weight of the user on the i-th attention head, represents the original attention score of the user on the i-th attention head, is the number of attention heads, represents the attention weight of the item on the i-th attention head, represents the original attention score of the item on the i-th attention head. Further, the step S223 of the above-mentioned contrastive loss recommendation method based on attention mechanism optimization embedding weight specifically comprises: constructing a user-item hypergraph embedding module, which is configured to: obtain a user-item hypergraph embedding matrix according to the user attention weight, the item attention weight, the user hypergraph embedding matrix and the item hypergraph embedding matrix, as shown in the following formula: ,
[0023]
[0024] ,
[0025] ,
[0026] ,
[0027] wherein, a user-item hypergraph embedding matrix, a connection function, a user hypergraph interaction information matrix, an item hypergraph interaction information matrix, a user attention weight, representing the relative importance of the user in the interaction, an item attention weight, representing the relative importance of the item in the interaction, a user hypergraph embedding matrix, representing the hypergraph dependency matrix of the user, an item hypergraph embedding matrix, representing the hypergraph dependency matrix of the item.
[0028] Further, the step S23 of the above-mentioned contrastive loss recommendation method based on attention mechanism optimization embedding weight specifically comprises: S231: constructing a segmentation module, for: performing a segmentation operation on the final embedding matrix to obtain a user embedding matrix and an item embedding matrix; S232: constructing a preference score module, for: according to the user embedding matrix and the item embedding matrix, using matrix multiplication to obtain the preference score of the user to the item; S233: constructing a ranking module, for: according to the preference score of the user to the item, ranking each item to obtain an item recommendation list of each user; S234: obtaining a segmentation and preference recommendation module according to the segmentation module, the preference score module and the ranking module.
[0029] Further, the loss function of the above-mentioned contrastive loss recommendation method based on attention mechanism optimization embedding weight is as follows:
[0030]
[0031] , ,
[0032] , ,
[0033] wherein, is a loss function, is a positive sample loss function, is a negative sample loss, is an averaging function, and is a temperature coefficient, represents calculating the Euclidean distance between the user embedding vector and the positive sample item embedding vector to measure their similarity, represents the embedding vector of the user, represents the embedding vector of the item in the positive sample, represents calculating the Euclidean distance between the user embedding vector and the negative sample item embedding vector to measure their difference, an embedding vector representing a user, an embedding vector representing an item in a negative sample.
[0034] The application further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the contrastive loss recommendation method based on the attention mechanism and optimized embedding weight.
[0035] The application provides a contrastive loss recommendation method based on the attention mechanism and optimized embedding weight, which has the following beneficial effects:
[0036] The application can effectively represent and capture high-order collaborative relationships between users and items by introducing a hypergraph embedding matrix; the application can more accurately capture key parts in user and item interactions by dynamically adjusting embedding weights through the combination of hypergraphs and the attention mechanism, specifically, the application obtains attention scores by processing embedding vectors of items and users, and obtains hypergraph interaction information of users and items by multiplying the attention weights and the hypergraph embedding matrix; the application optimizes the ability of the model to distinguish between positive samples and negative samples by introducing a positive and negative sample contrastive loss function, and solves the problem that existing personalized recommendation systems cannot distinguish the importance of different nodes in hyperedges when using a hypergraph model, thereby better capturing high-order collaborative relationships and significantly improving the performance and user experience of the recommendation system. BRIEF DESCRIPTION OF DRAWINGS
[0037] The application will be further described below in conjunction with the drawings and embodiments, wherein:
[0038] Figure 1 is a flowchart of the contrastive loss recommendation method based on the attention mechanism and optimized embedding weight provided by the application;
[0039] Figure 2 is a schematic diagram of the uniform initialization module of the recommendation model provided by the application;
[0040] Figure 3 is a schematic diagram of the linear transformation and attention module of the recommendation model provided by the application;
[0041] Figure 4 is a schematic diagram of the segmentation and preference recommendation module of the recommendation model provided by the application;
[0042] Figure 5 is a structural block diagram of the computer device provided by the application. DETAILED DESCRIPTION
[0043] In order to have a clearer understanding of the technical features, objectives and effects of the present application, the specific embodiments of the present application will now be described in detail with reference to the accompanying drawings.
[0044] Figure 1 A schematic diagram of the contrast loss recommendation method based on attention mechanism optimization of embedding weight of the present embodiment is shown.
[0045] In the present embodiment, the contrast loss recommendation method based on attention mechanism optimization of embedding weight comprises the following steps:
[0046] S1: Obtain the relevant data of users and items, divide the relevant data of users and items to obtain a training set and a test set; the relevant data of users and items includes user feature data, item feature data, positive feedback data and negative feedback data;
[0047] Specifically, according to the user feature data, the item feature data and the positive feedback data, the negative feedback data is obtained by using a negative sampling method;
[0048] Specifically, the relevant data of users and items is obtained from a data file, which includes user feature data, item feature data and positive feedback data; it contains basic information of users, behavior data of users, such as browsing records and interaction behavior information between users and items; the positive feedback data contains positive interaction information between users and items, and the negative feedback data represents negative or no interaction relationship between users and items; since the negative feedback is usually less in actual data, the negative feedback is generated by a negative sampling method; for example, Figure 2 A schematic diagram of a uniform initialization module of a recommendation model is shown, in which the user item feature data is the relevant data of users and items;
[0049] S2: Construct a recommendation model, train the recommendation model using the training set to obtain a trained recommendation model; the recommendation model includes a uniform initialization module, a linear transformation and an attention module, and a segmentation and preference recommendation module;
[0050] S21: Construct a uniform initialization module, which is configured to: according to the user feature data and the item feature data, obtain a user initial embedding matrix, an item initial embedding matrix, a user hypergraph embedding matrix and an item hypergraph embedding matrix by using a uniform initialization method;
[0051] Specifically, as shown in Figure 2 A schematic diagram of a uniform initialization module of a recommendation model is shown, step S21 includes: constructing a uniform initialization module, which is configured to: according to the user feature data and the item feature data, obtain a user initial embedding matrix, an item initial embedding matrix, a user hypergraph embedding matrix and an item hypergraph embedding matrix by using a uniform initialization method, as shown in the formula:
[0052] , ,
[0053] ,
[0054] , ,
[0055] , ,
[0056] wherein, and denote the set of users and items respectively, is the embedding dimension, denotes the number of hyper-edges, denotes the number of users, denotes the number of items, denotes the uniform initialization method, denotes the user initial embedding matrix, denotes the item initial embedding matrix, denotes the user hypergraph embedding matrix, denotes the item hypergraph embedding matrix;
[0057] S22: constructing a linear transformation and attention module, for: according to the user initial embedding matrix, the item initial embedding matrix, the user hypergraph embedding matrix and the item hypergraph embedding matrix, using linear transformation method and attention mechanism processing, obtaining the final embedding matrix;
[0058] Specifically, as Figure 3 is a schematic diagram of the linear transformation and attention module of the recommendation model; step S22 includes:
[0059] S221: constructing an attention score module, for: according to the user initial embedding matrix and the item initial embedding matrix, using linear transformation method, obtaining user attention score and item attention score;
[0060] Specifically, step S221 includes: constructing an attention score module, for: according to the user initial embedding matrix and the item initial embedding matrix, using linear transformation method and attention mechanism processing, obtaining user attention score and item attention score, as formula:
[0061] , ,
[0062] , ,
[0063] in, User attention score As an intermediate variable, The user's attention mechanism weight matrix For the user's linear transformation matrix, For the user's initial embedding matrix, It is the user's bias vector; For item attention score, As an intermediate variable, It is the attention mechanism weight matrix of the items. Let be the linear transformation matrix of the item. For the initial embedding matrix of the items, It is the bias vector of the item;
[0064] S222: Construct an attention weight module, used to: normalize the user attention score and the item attention score to obtain the user attention weight and the item attention weight;
[0065] Specifically, step S222 includes: constructing an attention weight module, used to: normalize the user attention score and the item attention score to obtain the user attention weight and the item attention weight, as shown in the formula:
[0066] ,
[0067] ,
[0068] in, Indicates the user's position in the first month. The attention weight of each person's attention. Indicates user number The original attention score of each attention head. For the number of attention heads, Indicates the item in the 1st month The attention weight of each person's attention. Indicates the item is in the next order. The original attention score of each attention head;
[0069] S223: Construct a user-item hypergraph embedding module, used to: obtain the user-item hypergraph embedding matrix based on the user attention weight, the item attention weight, the user hypergraph embedding matrix, and the item hypergraph embedding matrix;
[0070] Specifically, step S223 comprises: constructing a user-item hypergraph embedding module, configured to: obtain a user-item hypergraph embedding matrix according to the user attention weight, the item attention weight, the user hypergraph embedding matrix and the item hypergraph embedding matrix, as shown in the following formula:
[0071] ,
[0072] ,
[0073] ,
[0074] wherein, is the user-item hypergraph embedding matrix, is a connection function, is a user hypergraph interaction information matrix, is an item hypergraph interaction information matrix, is a user attention weight, representing the relative importance of the user in the interaction, is an item attention weight, representing the relative importance of the user in the interaction, is a user hypergraph embedding matrix, representing the hypergraph dependency matrix of the user, is an item hypergraph embedding matrix, representing the hypergraph dependency matrix of the user;
[0075] S224: constructing a fusion module, configured to: obtain a final embedding matrix according to the user-item hypergraph embedding matrix, the user initial embedding matrix and the item initial embedding matrix;
[0076] Specifically, the user-item hypergraph interaction information is fused into the final embedding matrix , as shown in the following formula:
[0077]
[0078] wherein, E is the embedding matrix obtained by connecting the user initial embedding matrix and the item initial embedding matrix after initialization;
[0079] S225: obtaining a linear transformation and attention module according to the attention score module, the attention weight module, the user-item hypergraph embedding module and the fusion module;
[0080] S23: constructing a segmentation and preference recommendation module, configured to: segment the final embedding matrix to obtain a user embedding matrix and an item embedding matrix; and obtaining an item recommendation list of each user according to the user embedding matrix and the item embedding matrix;
[0081] Specifically, as Figure 4A schematic diagram of the segmentation and preference recommendation module of the recommendation model is shown, and step S23 includes:
[0082] S231: a segmentation module is constructed, configured to: perform a segmentation operation on the final embedding matrix to obtain a user embedding matrix and an item embedding matrix;
[0083] S232: a preference score module is constructed, configured to: according to the user embedding matrix and the item embedding matrix, obtain the preference score of the user for the item by using matrix multiplication;
[0084] Specifically, according to the user embedding matrix and the item embedding matrix, the inner product of a specific user for all items is calculated by matrix multiplication, and a mask is also applied to ensure that the preference score of the item that has been interacted is greatly reduced, so that it will not appear in the user's recommendation list;
[0085] S233: a ranking module is constructed, configured to: according to the preference score of the user for the item, rank each item to obtain an item recommendation list for each user;
[0086] S234: according to the segmentation module, the preference score module and the ranking module, a segmentation and preference recommendation module is obtained;
[0087] S24: according to the uniform initialization module, the linear transformation and attention module and the segmentation and preference recommendation module, a recommendation model is obtained;
[0088] S25: a loss function is constructed, and the recommendation model is trained by using the loss function according to the training set to obtain a trained recommendation model;
[0089] Specifically, the loss function is as follows:
[0090]
[0091] , ,
[0092] , ,
[0093] wherein, is the loss function, is the positive sample loss function, is the negative sample loss, is the average function, and T is the temperature coefficient, represents the Euclidean distance between the user embedding vector and the positive sample item embedding vector to measure their similarity, represents the embedding vector of the user, represents the embedding vector of the item in the positive sample, represents the Euclidean distance between the user embedding vector and the negative sample item embedding vector to measure the difference between them, represents the embedding vector of the user, represents the embedding vector of the item in the negative sample;
[0094] S3: According to the test set, the trained recommendation model is used to obtain the item recommendation list of each user.
[0095] In some embodiments, the contrastive loss recommendation method based on the attention mechanism to optimize the embedding weight described above can also be implemented in the following way.
[0096] In this embodiment, the contrastive loss recommendation method based on the attention mechanism to optimize the embedding weight includes: by linearly changing the embedding vectors of users and items, transpose to calculate the attention score; by normalizing the attention score, multiplying the hypergraph embedding matrix by the attention weight to obtain the hypergraph interaction information of users and items; by fusing the hypergraph interaction information into the final embedding matrix; by separating the enriched embedding matrix to obtain the embedding vectors of users and items, calculating the prediction score of the user-item pair, and obtaining the item recommendation list of each user; by extracting the weight vector and embedding vector of the positive sample and negative sample from the embedding matrix to calculate the loss, back propagation, and optimize the model parameters.
[0097] In this embodiment, the contrastive loss recommendation method based on the attention mechanism to optimize the embedding weight includes the following steps:
[0098] Step 1: Obtain the relevant data of users and items from the data file, the relevant data including the feature data of users and items, the positive feedback data between users and items, and the negative feedback generated by negative sampling;
[0099] Specifically, the feature data of users and items is obtained from the corresponding data file, which contains the basic information of users, the behavior data of users, such as browsing records, and the interaction behavior information between users and items; the positive feedback data contains the positive interaction information between users and items; the negative feedback data represents the negative or no interaction relationship between users and items; since the negative feedback in actual data is usually less, the negative feedback is generated by negative sampling method;
[0100] Step 2: Initialize the obtained user information and item feature data to generate the embedding vectors of users and items;
[0101] Specifically, the specific steps of step 2 are:
[0102] Let and represent the set of users and items, respectively, and be initialized by the uniform initialization method, let and to represent the user and item embeddings, and the specific expression is:
[0103] The initialization embedding matrix of the user is:
[0104]
[0105] wherein, represents a set of users, wherein is the embedding dimension, represents a uniform initialization method, represents the embedding matrix of the user:
[0106]
[0107] wherein, represents a set of items, wherein is the embedding dimension, represents a uniform initialization method, represents the embedding matrix of the item;
[0108] Let and represent the hypergraph dependency matrix of the user and the item, and the specific expression is:
[0109] The hypergraph embedding matrix of the user is:
[0110]
[0111] wherein represents the number of hyperedges, represents a uniform initialization method, represents the hypergraph embedding matrix of the user
[0112] The hypergraph embedding matrix of the item is:
[0113]
[0114] wherein represents the number of hyperedges, represents a uniform initialization method, represents the hypergraph embedding matrix of the user;
[0115] Step 3: Linear transformation and attention mechanism processing are performed on the embedding vectors of the user and the item, and the hypergraph interaction information is fused into the final embedding matrix.
[0116] The specific steps of further step 3 are:
[0117] Step 31: Linear transformation is performed on the user embedding vector and the item embedding vector information to capture high-order features, and the transpose is calculated to obtain the attention score;
[0118] Specifically, the user embedding vector and the item embedding vector are linearly transformed, and the specific calculation formula is:
[0119] The user attention score calculation formula is:
[0120]
[0121]
[0122] wherein, is the linear transformation matrix of the user, is the bias vector, is the weight matrix of the attention mechanism, is the attention score of the user;
[0123] The user attention score calculation formula is:
[0124]
[0125]
[0126] wherein, is the linear transformation matrix of the item, is the bias vector, is the weight matrix of the attention mechanism, is the attention score of the item;
[0127] Step 32: Normalization is performed on the attention score to convert the attention score into a weight;
[0128] Specifically, the function is used to perform normalization on the attention score, and represent the relative importance of the user and the item in the hypergraph embedding, respectively;
[0129] The user attention weight calculation formula is:
[0130]
[0131] wherein, represents the original attention score of the user on the th attention head, is the number of attention heads;
[0132] The item attention weight calculation formula is:
[0133]
[0134] wherein, denotes the original attention score of the item on the i-th attention head, denotes the number of attention heads; the original attention score is converted into a probability distribution, and the attention weight and can reflect the relative importance of each user and item in the interaction;
[0135] Step 33: multiply the hypergraph embedding matrix by the attention weight to obtain the hypergraph interaction information of the user and the item, and splice the user and item hypergraph interaction information;
[0136] The calculation formula of the hypergraph interaction information of the user is:
[0137]
[0138] wherein denotes the relative importance of the user in the interaction, denotes the hypergraph dependency matrix of the user;
[0139] The calculation formula of the hypergraph interaction information of the item is:
[0140]
[0141] wherein denotes the relative importance of the user in the interaction, denotes the hypergraph dependency matrix of the user;
[0142] Splice the interaction information of the user and the item to obtain the hypergraph interaction information of the user and the item:
[0143]
[0144] Step 34: fuse the hypergraph interaction information of the user and the item into the final embedding matrix;
[0145] Specifically, the hypergraph interaction information of the user and the item is fused into the final embedding matrix , and the specific formula is:
[0146]
[0147] Step 4: separate the embedding vectors into user and item embedding vectors, calculate the preference score of the user to the item, sort the items according to the preference score, and obtain the item recommendation list of each user;
[0148] Further, step 4 is specifically:
[0149] Step 41: Obtain the embedding vectors of users and items;
[0150] Specifically, the final embedding matrix is segmented to obtain user embedding vectors and item embedding vectors.
[0151] Step 42: Calculate the preference score of the user for the item;
[0152] Specifically, the inner product of the specific user for all items is calculated by matrix multiplication through the obtained embedding vectors of users and items, and an application mask is also used to ensure that the preference score of the item that has been interacted is greatly reduced, so as to not appear in the user's recommendation list.
[0153] Step 43: For each item, sort according to the preference score to obtain the top K recommended item list;
[0154] Step 5: Extract the weight vector and embedding vector of the positive and negative samples through the embedding weight matrix and the embedding matrix, use the vectors for the loss function, and optimize the model parameters combined with the loss of positive and negative samples;
[0155] Step 5 specifically: minimize the distance between the user embedding vector and the positive sample item embedding vector to learn more relevant user-positive sample item pairs; the calculation formula of the positive sample loss function is:
[0156]
[0157]
[0158] wherein, represents the embedding vector of the user, represents the embedding vector of the item in the positive sample, represents the Euclidean distance between the user embedding vector and the positive sample item embedding vector to measure their similarity, is an average function, is a temperature coefficient, positive sample loss
[0159] The calculation formula of the negative sample loss function is:
[0160]
[0161]
[0162] wherein, represents the embedding vector of the user, represents the embedding vector of the item in the negative sample, representing the Euclidean distance between the user embedding vector and the negative sample item embedding vector to measure the difference between them, is an averaging function, is a temperature coefficient, negative sample sample loss;
[0163] The optimizer updates the model parameters through the sum of the positive sample loss and the negative sample loss.
[0164] The embodiment provides a computer readable storage medium, and a computer program is stored on the computer readable storage medium. The computer program is executed by a processor to implement the steps of the comparative loss recommendation method based on attention mechanism optimization of embedding weight described above. The storage medium can be a disk, an optical disc, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), etc. The storage medium can also include a combination of the above-mentioned types of memories.
[0165] The embodiment provides a computer device, which includes a memory, a processor and a computer program stored on the memory and executable on the processor. When the processor executes the program, the steps of the comparative loss recommendation method based on attention mechanism optimization of embedding weight described above are implemented.
[0166] As Figure 5As shown, the computer device can include at least one processor 121, such as a CPU (Central Processing Unit), at least one communication interface 123, a memory 124, at least one communication bus 122. Among them, the communication bus 122 is used to realize the connection communication between the components. Among them, the communication interface 123 can include a display, a keyboard, and the optional communication interface 123 can also include a standard wired interface, a wireless interface. The memory 124 can be a high-speed RAM memory (Random Access Memory), or a non-volatile memory, such as at least one disk memory. The memory 124 can also be at least one storage device located away from the aforementioned processor 121. Among them, the memory 124 stores an application program, and the processor 121 calls the program code stored in the memory 124 for executing any of the above method steps. Among them, the communication bus 122 can be a peripheral component interconnect (peripheral component interconnect, abbreviated as PCI) bus or an extended industry standard architecture (extended industry standard architecture, abbreviated as EISA) bus, etc. The communication bus 122 can be divided into an address bus, a data bus, a control bus, etc. For convenience of representation, Figure 5The bus 123 is used to connect the above-mentioned elements in the system 120, and only one line is used to represent the bus 123, but it does not mean that there is only one bus or only one type of bus. Among them, the memory 124 can include volatile memory such as random-access memory (RAM); the memory can also include non-volatile memory such as flash memory, a hard disk drive (HDD) or a solid-state drive (SSD); the memory 124 can also include a combination of the above-mentioned types of memory. Among them, the processor 121 can be a central processing unit (CPU), a network processor (NP) or a combination of CPU and NP. Among them, the processor 121 can further include a hardware chip. The above-mentioned hardware chip can be an application-specific integrated circuit (ASIC), a programmable logic device (PLD) or a combination thereof. The above-mentioned PLD can be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof. Optionally, the memory 124 is also used to store program instructions. The processor 121 can call the program instructions to implement the contrast loss recommendation method based on attention mechanism optimization embedding weight as in the embodiment.
[0167] The embodiments of the present application are described above in combination with the drawings, but the present application is not limited to the above-mentioned specific embodiments, and the above-mentioned specific embodiments are only illustrative and not restrictive. Those skilled in the art can make many forms under the inspiration of the present application without departing from the purpose of the present application and the scope protected by the claims, and these all belong to the protection of the present application.
Claims
1. A contrastive loss recommendation method based on attention mechanism to optimize embedding weights, characterized in that, Includes the following steps: S1: Obtain relevant data on users and items, and divide the relevant data on users and items to obtain a training set and a test set; the relevant data on users and items includes user feature data, item feature data, positive feedback data, and negative feedback data; S2: Construct a recommendation model, and train the recommendation model using the training set to obtain a trained recommendation model; the recommendation model includes a uniform initialization module, a linear transformation and attention module, and a segmentation and preference recommendation module; S3: Based on the test set, use the trained recommendation model to obtain a list of recommended items for each user; Step S2 specifically includes: S21: Construct a uniform initialization module, used to: obtain the user initial embedding matrix, the item initial embedding matrix, the user hypergraph embedding matrix, and the item hypergraph embedding matrix using a uniform initialization method based on the user feature data and the item feature data; S22: Construct a linear transformation and attention module, used to: process the user initial embedding matrix, the item initial embedding matrix, the user hypergraph embedding matrix and the item hypergraph embedding matrix using a linear transformation method and an attention mechanism to obtain the final embedding matrix; S23: Construct a segmentation and preference recommendation module, used to: segment the final embedding matrix to obtain a user embedding matrix and an item embedding matrix; and obtain an item recommendation list for each user based on the user embedding matrix and the item embedding matrix. S24: Based on the uniform initialization module, the linear transformation and attention module, and the segmentation and preference recommendation module, a recommendation model is obtained; S25: Construct a loss function, and train the recommendation model using the loss function based on the training set to obtain a trained recommendation model; Step S22 specifically includes: S221: Construct an attention score module, used to: obtain user attention score and item attention score by using a linear transformation method based on the user initial embedding matrix and the item initial embedding matrix; S222: Construct an attention weight module, used to: normalize the user attention score and the item attention score to obtain the user attention weight and the item attention weight; S223: Construct a user-item hypergraph embedding module, used to: obtain the user-item hypergraph embedding matrix based on the user attention weight, the item attention weight, the user hypergraph embedding matrix, and the item hypergraph embedding matrix; S224: Construct a fusion module, used to: obtain the final embedding matrix based on the user-item hypergraph embedding matrix, the user initial embedding matrix, and the item initial embedding matrix; S225: Based on the attention score module, the attention weight module, the user item hypergraph embedding module, and the fusion module, obtain the linear transformation and the attention module; Step S221 specifically includes: constructing an attention score module, used to: process the user's initial embedding matrix and the item's initial embedding matrix using a linear transformation method and an attention mechanism to obtain the user's attention score and the item's attention score, as shown in the formula: , , , , in, User attention score As an intermediate variable, The user's attention mechanism weight matrix For the user's linear transformation matrix, For the user's initial embedding matrix, It is the user's bias vector; For item attention score, As an intermediate variable, It is the attention mechanism weight matrix of the items. Let be the linear transformation matrix of the item. For the initial embedding matrix of the items, It is the bias vector of the item; Step S222 specifically includes: constructing an attention weight module, used to: normalize the user attention score and the item attention score to obtain the user attention weight and the item attention weight, as shown in the formula: , , in, Indicates the user's position in the first month. The attention weight of each person's attention. Indicates user number The original attention score of each attention head. For the number of attention heads, Indicates the item in the 1st month The attention weight of each person's attention. Indicates the item in the 1st month The original attention score of each attention head; The loss function is as follows: , , , , in, For loss function, For positive samples, the loss function is... For negative sample loss, To find the average function, T is the temperature coefficient. This means calculating the Euclidean distance between user embedding vectors and positive sample item embedding vectors to measure their similarity. Represents the user's embedding vector. This represents the embedding vector of an item in a positive sample. This means calculating the Euclidean distance between the user embedding vector and the negative sample item embedding vector to measure the difference between them. Represents the user's embedding vector. This represents the embedding vector of an item in a negative sample.
2. The contrastive loss recommendation method based on attention mechanism to optimize embedding weights according to claim 1, characterized in that, Step S21 specifically includes: constructing a uniform initialization module, which is used to: obtain the initial user embedding matrix, the initial item embedding matrix, the user hypergraph embedding matrix, and the item hypergraph embedding matrix using a uniform initialization method based on the user feature data and the item feature data, as shown in the formula: , , , , , , , in, and These represent sets of users and sets of items, respectively. It is the embedded dimension. Indicates the number of superedges. Indicates the number of users. Indicates the quantity of items. This indicates a uniform initialization method. Represents the user's initial embedding matrix. Represents the initial embedding matrix of the items. Represents the user hypergraph embedding matrix. This represents the item hypergraph embedding matrix.
3. The contrastive loss recommendation method based on attention mechanism to optimize embedding weights according to claim 1, characterized in that, Step S223 specifically includes: constructing a user-item hypergraph embedding module, used to: obtain the user-item hypergraph embedding matrix based on the user attention weight, the item attention weight, the user hypergraph embedding matrix, and the item hypergraph embedding matrix, as shown in the formula: , , , in, Embed a matrix for the user item hypergraph. For the join function, For users' hypergraph interaction information matrix, For the hypergraph interaction information matrix of items, User attention weight represents the relative importance of a user during the interaction. Item attention weight represents the relative importance of a user in the interaction. The hypergraph embedding matrix represents the user's hypergraph dependency matrix. Let be the item hypergraph embedding matrix, and let represent the user's hypergraph dependency matrix.
4. The contrastive loss recommendation method based on attention mechanism to optimize embedding weights according to claim 1, characterized in that, Step S23 specifically includes: S231: Construct a segmentation module, used to: perform segmentation operations on the final embedding matrix to obtain a user embedding matrix and an item embedding matrix; S232: Construct a preference scoring module, used to: obtain the user's preference score for an item by matrix multiplication based on the user embedding matrix and the item embedding matrix; S233: Construct a sorting module, used to: sort each item according to the user's preference score for the item, and obtain an item recommendation list for each user; S234: Based on the segmentation module, the preference scoring module, and the sorting module, a segmentation and preference recommendation module is obtained.
5. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the contrastive loss recommendation method based on attention mechanism to optimize embedding weights as described in any one of claims 1-4.
Citation Information
Patent Citations
Sequence recommendation method and device based on hypergraph neural network
CN115082147A
Session type recommendation method and system applying multi-channel dynamic hypergraph
CN117788119A