Self-attention sequence recommendation method, system and device fusing time information
By incorporating time-based information into a self-attention sequence recommendation model, and combining product and timestamp sequences for data augmentation and multiple self-attention calculations, the problem of low product recommendation accuracy in existing technologies is solved, thereby improving user satisfaction and recommendation accuracy.
Patent Information
- Application Number
- CN202210973525.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-15
- Publication Date
- 2026-02-27
- Estimated Expiration
- 2042-08-15
Smart Images

Figure CN115249175B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the field of personalized recommendation, and particularly relates to a self-attention sequence recommendation method fusing time information, a system and equipment. BACKGROUND
[0002] With the continuous development of information technology, the Internet has become an integral part of people's daily life today. People will engage in various activities on the Internet every day, such as watching movies, shopping, reading news, etc. In the Internet era, people are exposed to more information in a month than in a year without the Internet. But with more and more information on the Internet, people find it more and more difficult to find the most suitable ones from the vast amount of information on the Internet, for example, when you log in to a video website to watch a movie to relax, but you don't know which one meets your taste. The emergence of the recommendation system is to solve this "information overload" problem, which can predict the user's needs and recommend the most likely content for the user to like, and alleviate the annoyance of people making choices from the vast amount of information.
[0003] The sequence recommendation problem can be regarded as learning a model strategy in the time dimension to predict the items that the user will be interested in according to the user's past behavior history. For sequence recommendation, the current mainstream methods include RNN, GRU, self-attention network, etc.
[0004] But in the past self-attention-based sequence recommendation methods, little consideration is given to time information, only the relative position of elements in the sequence is considered, and no accurate timestamp granularity is considered. Time contains a wealth of information, and different time intervals contain different information. Considering only the relative position will ignore these information. At the same time, in the process of information aggregation in self-attention calculation, not all goods in the sequence can provide useful information for the goods elements to be aggregated, and the goods farther apart may bring noise information, so selective aggregation in the process of self-attention calculation is of certain effect.
[0005] Therefore, how to improve the accuracy of the goods recommendation based on the sequence recommendation method to improve user satisfaction is a problem to be solved in the field. SUMMARY
[0006] The application aims at the defects of the prior art, and provides a self-attention sequence recommendation method, system and device fusing time information.
[0007] To achieve the above object, the application adopts the following technical scheme:
[0008] A self-attention sequence recommendation method fusing time information, characterized in that it comprises the following steps:
[0009] S1, constructing a self-attention sequence recommendation model fusing time information, specifically:
[0010] S11, data augmentation on a user's historical interaction sequence, wherein the historical interaction sequence comprises a commodity sequence (i1, i2,..., i n ) and a corresponding timestamp sequence (t1, t2,..., t n ), and the commodity sequence and the timestamp sequence are used to perform data augmentation on the continuous subsequence containing the first item, to obtain an extended user's historical interaction sequence;
[0011] S12, for each commodity sequence in the extended user's historical interaction sequence, calculating the time interval between each commodity and the last commodity according to the corresponding timestamp sequence, denoted as (t 1n , t 2n , t 3n ,..., t (n-1)n , t nn ), which is taken as the corresponding time interval information contained in the corresponding commodity sequence, wherein t 1n represents the time stamp interval difference between the first element and the n-th element of the input sequence;
[0012] S13, using an embedding layer to convert the commodity sequence and the time interval information into embedding vectors of the same dimension, adding a virtual element at the end of the embedding vector, and performing encoding representation, to obtain the embedding representation E=(e1, e2,..., e n , e a ) of the commodity sequence and the embedding representation P=(p1, p2,..., p n , p a ) of the time interval information, wherein a is the subscript of the virtual commodity.
[0013] S14. Connect the embedding of the product sequence with the embedding of the time interval information to generate a new embedding representation of the product X = (x1, x2, ..., x...). n x a ), where x i =Concat(e i p i Concat() represents a join operation, x i ∈R d ;
[0014] S15. The new embedded representation X of the product is input into a multi-self-attention module composed of multiple self-attention blocks. After passing through the last self-attention block, the output sequence (h1, h2, ..., h...) is obtained. n h a ), where h i This represents the user's interest over a time period centered on the i-th item with a radius of Δt, where i = 1, ..., n, h. a Embedded for storing aggregated information in virtual goods;
[0015] Each of the self-attention blocks includes the following steps:
[0016] (1) Perform self-attention calculation on the new embedded representation X of the product, specifically:
[0017] First, calculate three vectors Q, K, and V based on X, and then map X to three spaces: query, key, and value.
[0018] Q = XW Q
[0019] K = XW K
[0020] V = XW V
[0021] Among them, W Q W K W V ∈R d×d These are learnable parameters, where R is a symbol representing a dimension, and the superscript d×d indicates that the first dimension of the parameter matrix is d, and the second dimension is also d;
[0022] Secondly, restricted self-attention calculations are performed using Q, K, and V:
[0023]
[0024] Wherein, S represents the output of local self-attention, d represents the dimension of embedding vector; Attention() represents the local self-attention operation, SA() is an alias of Attention() operation; Softmax() is a mapping function that maps a vector into a probability distribution vector, and the sum of each probability is 1, that is, the normalized exponential function; d is the dimension of embedding vector;
[0025] In the process of self-attention calculation, in Q i and K j , the interval between the corresponding timestamps t i and t j is limited within a certain time range, that is, |t i -t j |≤Δt, Δt is a learnable parameter, wherein Q i represents the target node in the query space, and K j represents the neighbor node in the key space;
[0026] (2) The S obtained after the self-attention operation is passed through two layers of point-wise feedforward networks:
[0027] F1=FFN(S)=RELU(SW 1 +b 1 )W 2 +b 2
[0028] F2=FFN(F1)=RELU(F1W 1 +b 1 )W 2 +b 2
[0029] Wherein, W 1 , W 2 ∈R d×d , b 1 , b 2 ∈R d are all learnable parameters; FFN() represents a fully connected layer with RELU() as the activation function; S represents the output of self-attention, F1 represents the output of the first layer of feedforward network, and F2 represents the output of the second layer of feedforward network;
[0030] (3) Layer Normalization, residual connection and Dropout operation are added to the self-attention layer and the feedforward layer in the self-attention block, as shown below:
[0031] G(X)=X+Dropout(G(LayerNorm(X)))
[0032]
[0033] where G generally represents a self-attention operation or a pre-feedforward layer operation, X represents an input when a certain operation is performed; LayerNorm() represents a layer normalization operation, which is added before the input operation to accelerate model learning; Dropout() operation inactivates neurons with a certain probability during the training process, which is added before the output operation to prevent overfitting; represents an inner product; μ and σ 2 represent the mean and variance of X; and and represent a scale factor and a bias term, which are trainable parameters; ∈ is a constant;
[0034] Step S15 specifically comprises: inputting the new embedding representation X of the commodity into the first self-attention block to obtain a first output result, inputting the first output result into the second self-attention block for calculation, and calculating until the last self-attention block is calculated, wherein the output result of the last self-attention block is the output sequence of the multiple self-attention module, and the specific process is as follows:
[0035]
[0036] F1 (b) =FFN(S (b) )
[0037]
[0038] where b represents the bth self-attention block, there are L self-attention blocks in total, and L is a hyperparameter; S (b) represents the output of the self-attention in the bth self-attention block, F1 (b) represents the output of the first layer pre-feedforward network in the bth self-attention block, represents the output of the second layer pre-feedforward network in the bth self-attention block; the input of the first self-attention block is X=(x1, x2,..., x n , x a ), and the output of the last self-attention block is recorded as (h1, h2,..., h n , h a ); the output of the second layer pre-feedforward network in the self-attention block will be used as the input of the next self-attention block;
[0039] S16, performing attention-based aggregation on the output sequence to obtain the final interest representation h of the user, and the specific steps comprise: calculating the corresponding weight and aggregating the representation:
[0040]
[0041]
[0042] wherein, h i represents the interest representation of the user in the time period with the i-th commodity as the center and Δt as the radius; α i represents h i corresponding weight; all h i are aggregated with weights as the final interest representation, denoted as h.
[0043] S17, inner product of the aggregated final interest representation h and the embedding matrix of the candidate commodity is performed to obtain the probability of interaction of the candidate commodity, and a recommendation result is generated according to the probability, specifically:
[0044]
[0045] wherein, M represents the embedding matrix of the candidate commodity, represents the probability of interaction of the candidate commodity;
[0046] S2, the fusion time information self-attention sequence recommendation model is trained by using the historical interaction sequence of the user in the obtained data set, and a trained fusion time information self-attention sequence recommendation model is obtained.
[0047] S3, the historical interaction sequence of the user to be recommended is obtained, and the historical interaction sequence of the user to be recommended is input into the trained fusion time information self-attention sequence recommendation model, a target recommendation commodity is obtained, and the target recommendation commodity is recommended to the user.
[0048] Further, in step S11, the data augmentation is performed using the continuous subsequence containing the first item of the commodity sequence and the time stamp sequence, specifically including: for the commodity sequence (i1, i2, ……i n ), the continuous subsequence containing the first item is (i1, i2), (i1, i2, i3), (i1, i2, i3, i4), ……, (i1, i2, ……i n-1 ); for the time stamp sequence (t1, t2, ……t n ), the continuous subsequence containing the first item is (t1, t2), (t1, t2, t3), (t1, t2, t3, t4), ……, (t1, t2, ……t n-1 ).
[0049] Further, in step S2, the fusion time information self-attention sequence recommendation model is trained according to the recommendation result using cross entropy as a loss function, and the loss function is:
[0050]
[0051] wherein, m represents the total number of candidate commodities.
[0052] A self-attention sequence recommendation system that integrates time information, characterized in that the product recommendation system executes the above-mentioned self-attention sequence recommendation method that integrates time information, including: a sequence recommendation model construction module, a sequence recommendation model training module, and a product recommendation module;
[0053] The sequence recommendation model construction module constructs a self-attention sequence recommendation model that integrates time information.
[0054] The sequence recommendation model training module uses the historical interaction sequences of users in the acquired dataset to train the self-attention sequence recommendation model that integrates time information, thereby obtaining a trained self-attention sequence recommendation model that integrates time information.
[0055] The product recommendation module obtains the historical interaction sequence of the user to be recommended, inputs the historical interaction sequence of the user to be recommended into the trained self-attention sequence recommendation model that integrates time information, obtains the target recommended product, and recommends the target recommended product to the user.
[0056] The present invention also proposes a computer device, the device including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the above-described method.
[0057] This invention discloses a self-attention sequence recommendation method, system, and device that integrates time information. The self-attention sequence recommendation method of this invention connects the embedded representation of time interval information with the product embedding to form a product embedding with time information. Furthermore, it performs multi-attention calculations using multiple self-attention blocks in the self-attention sequence recommendation model that integrates time information, thereby uncovering more complex and deeper information. This fundamentally solves the problems of low product recommendation accuracy and low user satisfaction in existing sequence-based recommendation methods.
[0058] Compared with existing technologies, it has the following beneficial effects:
[0059] 1. The self-attention sequence recommendation method of the present invention integrates time information. For each product sequence in the expanded user's historical interaction sequence, the time interval between each product and the last product is calculated based on the corresponding timestamp sequence. The embedded representation of the time interval information is connected with the product embedding to form a product embedding with time information. This self-attention sequence recommendation method that integrates time information improves the accuracy of product recommendation based on sequence recommendation methods and enhances user satisfaction.
[0060] 2. The fusion time information self-attention sequence recommendation method of the present application, the fusion time information self-attention sequence recommendation model comprises a multiple self-attention module composed of multiple self-attention blocks, multiple attention calculations are performed through the multiple self-attention blocks, more complex and deeper information can be mined, and the product recommendation accuracy is improved, and the user experience is improved.
[0061] 3. The fusion time information self-attention sequence recommendation method of the present application, in each self-attention block of the fusion time information self-attention sequence recommendation model, three different learnable mapping matrices are used to map the product embedding with time information into three vectors and perform self-attention calculation, and certain restrictions are performed during the calculation process, so that when the embedding is updated by information aggregation, the elements far apart are discarded, the noise information is filtered, and the product recommendation accuracy based on the sequence recommendation method is further improved.
[0062] 4. The fusion time information self-attention sequence recommendation method of the present application, in each self-attention block of the fusion time information self-attention sequence recommendation model, based on the feedforward network, the recommendation model is given more nonlinearity, so that the recommendation model has better representation ability; residual connection, Layer Normalization and Dropout operation are used to make the model more stable, and problems such as overfitting, gradient disappearance and long training time caused by deepening of the network are alleviated, and the product recommendation accuracy is improved.
[0063] The fusion time information self-attention sequence recommendation method, system and device of the present application connect the embedding representation of the time interval information with the product embedding to form product embedding with time information, and perform multiple attention calculations through multiple self-attention blocks in the fusion time information self-attention sequence recommendation model to mine more complex and deeper information, improve the accuracy of product recommendation based on the sequence recommendation method, and improve the user experience. BRIEF DESCRIPTION OF DRAWINGS
[0064] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0065] Figure 1 The fusion time information self-attention sequence recommendation method provided by the embodiment of the present application is shown in the figure.
[0066] Figure 2 The fusion time information self-attention sequence recommendation model provided by the embodiment of the present application is shown in the figure.
[0067] Figure 3 The embedding representation generation step of the time interval information provided for the embodiment of the present application is shown in the schematic diagram.
[0068] Figure 4 The structure diagram of the self-attention block provided for the embodiment of the present application is shown in the schematic diagram.
[0069] Figure 5 The local aggregation of the self-attention calculation provided for the embodiment of the present application is shown in the schematic diagram.
[0070] Figure 6 The weighted summation of the self-attention calculation result provided for the embodiment of the present application is shown in the schematic diagram.
[0071] Figure 7 The self-attention sequence recommendation system that fuses time information provided for the embodiment of the present application is shown in the schematic diagram. DETAILED DESCRIPTION
[0072] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present application.
[0073] It should be understood that when used in the specification and the appended claims, the terms "comprise" and "include" indicate the presence of the described features, integers, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0074] The present application will be further described below with reference to the drawings and specific embodiments, but is not limited by the present application.
[0075] It should also be understood that the terms used in the specification of the present application are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in the specification and the appended claims of the present application, the singular forms "a", "an" and "the" are intended to include the plural forms unless the context clearly indicates otherwise.
[0076] It should be further understood that the term "and / or" used in the specification and the appended claims of the present application means any combination of one or more of the associated listed items and all possible combinations, and includes these combinations.
[0077] The present application is a self-attention sequence recommendation method that fuses time information. As shown in Figure 1As shown, the self-attention sequence recommendation method fusing time information includes the following steps S1 to S3.
[0078] S1, a self-attention sequence recommendation model fusing time information is constructed, and a schematic diagram of the self-attention sequence recommendation model fusing time information is as shown in the figure. Figure 2 The self-attention sequence recommendation model fusing time information includes an embedding layer, a time sequence encoding module, an embedding connection module, a multiple self-attention module including multiple self-attention blocks, an aggregation module, and a prediction module.
[0079] Specifically,
[0080] S11, data augmentation is performed on a historical interaction sequence of a user, wherein the historical interaction sequence of the user includes a commodity sequence (i1, i2,... i n ) and a corresponding timestamp sequence (t1, t2,... t n ), and a continuous subsequence including a first item of the commodity sequence and the timestamp sequence is used for data augmentation to obtain an extended historical interaction sequence of the user.
[0081] Let U represent a user set and I represent a commodity set, a historical interaction sequence of a user includes a commodity sequence (i1, i2,... i n ) and a corresponding timestamp sequence (t1, t2,... t n ). Wherein each item of the commodity sequence is a commodity number or a commodity name.
[0082] The use of the continuous subsequence including the first item of the commodity sequence and the timestamp sequence for data augmentation specifically includes: for the commodity sequence (i1, i2,... i n ), the continuous subsequence including the first item is (i1, i2), (i1, i2, i3), (i1, i2, i3, i4),..., (i1, i2,... i n-1 ).
[0083] For the timestamp sequence (t1, t2,... t n ), the same corresponding operation is also performed, and the corresponding continuous subsequence is calculated to form a pair of inputs with the subsequence of the commodity. For the timestamp sequence (t1, t2,... t n ), the continuous subsequence including the first item is (t1, t2), (t1, t2, t3), (t1, t2, t3, t4),..., (t1, t2,... t n-1 ). The historical interaction sequences of all users are inputted after the above operation.
[0084] S12, for each commodity sequence in the extended user's historical interaction sequence, calculate the time interval between each commodity and the last commodity according to the corresponding timestamp sequence, denoted as (t 1n , t 2n , t 3n ,..., t (n-1)n , t nn ), which is included in the corresponding time interval information in the corresponding commodity sequence, wherein t 1n represents the time stamp interval difference between the first element and the n-th element of the input sequence.
[0085] wherein, for each commodity sequence in the extended user's historical interaction sequence, the time interval between each commodity and the last commodity is calculated according to the corresponding timestamp sequence, and the unit is day (i.e. divided by the length of a day).
[0086] Specifically, the commodity sequence (i1, i2,..., i n ) has a corresponding timestamp sequence (t1, t2,..., t n ), the interval difference of the corresponding timestamp is calculated, and the interval difference calculated above is expressed in days as (t 1n , t 2n , t 3n ,..., t (n-1)n , t nn ), which is included in the corresponding time interval information in the corresponding commodity sequence, wherein t 1n represents the time stamp interval difference between the first element and the n-th element (i.e. the last element of the input sequence).
[0087] S13, using an embedding layer, converting the commodity sequence and the time interval information into embedding vectors of the same dimension, adding a virtual element at the end of the embedding vector, and performing encoding representation to obtain the embedding representation E = (e1, e2,..., e n , e a ) of the commodity sequence and the embedding representation P = (p1, p2,..., p n , p a ) of the time interval information, wherein a is the subscript of the virtual commodity. The generation steps of the embedding representation of the time interval information are shown in Figure 3 .
[0088] wherein, in order to obtain the user's preference information, a virtual commodity element is added at the end of each sequence to save the aggregated information in the subsequent self-attention operation, and the subscript of the virtual commodity is a, and in order to synchronize the subsequent calculation, a virtual element is also added at the end of the corresponding time interval sequence, which specifically includes:
[0089] For the item sequence, the last one with id plus 1 as a virtual element is added at the end and encoded representation, the embedding representation of item sequence is denoted as
[0090] E=(e1,e2,......,e n ,e a )
[0091] For the time interval information corresponding to the item sequence, a virtual element is also added at the end to synchronize the calculation, the virtual element is t nn plus 1, and then encoded representation, the embedding representation is denoted as
[0092] P=(p1,p2,......,p n ,p a )。
[0093] S14, concatenate the embedding of the item sequence and the embedding of the time interval information to generate a new embedding representation of the item X=(x1, x2,..., x n , x a ), where x i =Concat(e i , p i ), Concat() represents the concatenation operation, x i ∈R d , where R is a symbol representing the dimension, and the superscript d represents the dimension;
[0094] S15, input the new embedding representation of the item X into a multi-attention module composed of multiple self-attention blocks, and after the last self-attention block, an output sequence (h1, h2,..., h n , h a ) is obtained, where h i represents the interest representation of the user within a time period centered on the i-th item with a radius of Δt, i=1,..., n, and h a is a virtual item embedding used to save aggregated information.
[0095] The structure of the self-attention block is shown in Figure 4 , and the schematic diagram of self-attention calculation of local aggregation in the self-attention block is shown in Figure 5 . In each of the self-attention blocks, the following steps are included:
[0096] (1) Calculate the self-attention of the new embedding representation of the item X, specifically:
[0097] First, according to X, three vectors Q, K, V are calculated (i.e. X is mapped to query, key, value three spaces):
[0098] Q = XW Q
[0099] K = XW K
[0100] V = XW V
[0101] where W Q , W K , W V ∈R d×d are learnable parameters, where R is a symbol representing the dimension, and the superscript dxd indicates that the first dimension of the parameter matrix is d, and the second dimension is also d;
[0102] The above uses three different learnable mapping matrices to map the new embedding representation X of the commodity to three vectors Q, K and V and perform self-attention calculation.
[0103] Second, use Q, K, V to perform limited self-attention calculation:
[0104]
[0105] where S represents the output of local self-attention, d represents the dimension of the embedding vector; Attention() represents the local self-attention operation, SA() is understood as an alias of Attention(); Softmax() is a mapping function that maps a vector to a probability distribution vector, and the sum of each probability is 1, that is, the normalized exponential function; d is the dimension of the embedding vector.
[0106] It should be noted that when performing self-attention calculation, from life experience, not every element in the sequence can provide useful information for updating the embedding, some may even bring noise information, and adjacent elements in the sequence often have certain connections, while elements far apart are more likely to contain information with large differences. In order to avoid noise information as much as possible when updating the embedding, a certain restriction is performed in the process of self-attention operation. Specifically, when Q i and K j are calculated, the interval between the corresponding timestamps t i and t j is limited to a certain time range, i.e. |t i -t j |≤Δt, Δt is a learnable parameter, where Q i represents the target node in the query space, K jThe neighbor nodes in the key space (the neighbors also include the self in the key space).
[0107] The local self-attention is aggregated by Q, K, and V, and is essentially still aggregating neighbor information for the X sequence. The aggregation process is shown in the accompanying Figure 5 , Figure 5 In the above, the upper embedding represents Q (the node in the query space), and the lower embedding represents K (the node in the key space). The node in Q only considers the nodes in K that are within a certain distance from the node in Q. i The nodes K that are within a time interval of no more than Δt j Aggregation is performed, i.e., in the X sequence, commodity i only aggregates neighbors (including commodity i itself) within a range centered on commodity i and with a radius of Δt.
[0108] (2) The S obtained after the self-attention operation is passed through two layers of point-wise feedforward networks,
[0109] F1=FFN(S)=RELU(SW 1 +b 1 )W 2 +b 2
[0110] F2=FFN(F1)=RELU(F1W 1 +b 1 )W 2 +b 2
[0111] where W 1 , W 2 ∈R d×d , b 1 , b 2 ∈R d are all learnable parameters; FFN() represents a fully connected layer with RELU() as the activation function; S represents the output of the self-attention, F1 represents the output of the first layer of the feedforward network, and F2 represents the output of the second layer of the feedforward network.
[0112] In order to give the model more nonlinearity and make the model have better representation ability, the result S after the self-attention operation is passed through two layers of point-wise feedforward networks.
[0113] (3) Layer Normalization, residual connection, and Dropout operations are added to the self-attention layer and the feedforward layer in the self-attention block, as shown below:
[0114] G(X)=X+Dropout(G(LayerNorm(X)))
[0115]
[0116] where G generally represents a self-attention operation or an operation of a pre- feedback layer, X generally represents an input when a certain operation is performed; LayerNorm() represents a layer normalization operation, which is added before the input operation to accelerate model learning. The Dropout() operation inactivates neurons with a certain probability during the training process, and is added before the output operation to prevent overfitting; in the LayerNorm formula, represents an inner product; μ and σ 2 represent the mean and variance of X; α and β represent a scale factor and a bias term, which are trainable parameters; ∈ is a very small constant.
[0117] In order to make the recommendation model more stable, alleviate the problems of overfitting, gradient disappearance and long training time caused by deepening the network, Layer Normalization, residual connection and Dropout operation are added to the self-attention layer and the pre-feedback layer in the self-attention block.
[0118] In order to dig deeper and more complex information, multiple self-attention blocks are used for multiple self-attention calculation. Specifically, the new embedding representation X of the goods is input into the first self-attention block to obtain the first output result, and the first output result is input into the second self-attention block for calculation, until the calculation of the last self-attention block is completed, and the output result of the last self-attention block is the output sequence of the multiple self-attention module.
[0119] The output of the pre-feedback network is again passed through multiple self-attention blocks, specifically:
[0120]
[0121] F1 (b) =FFN(S (b) )
[0122]
[0123] where b represents the bth self-attention block, and there are L self-attention blocks, and L is a hyperparameter; S (b) represents the output of the self-attention in the bth self-attention block, F1 (b) represents the output of the first layer of the pre-feedback network in the bth self-attention block, represents the output of the second layer of the pre-feedback network in the bth self-attention block; the input of the first self-attention block is X = (x1, x2,..., x n , x a ), and the output of the last self-attention block is recorded as (h1, h2,..., h n , h aThe output of the second-layer prefeedback network in the self-attention block will be used as the input of the next self-attention block.
[0124] S16. Aggregate the output sequence with attention to obtain the user's final interest representation h. Specific steps include: calculating the corresponding weights and aggregating the representation.
[0125]
[0126]
[0127] Among them, h i This represents the user's interest within a time period centered on the i-th item and with a radius of Δt; α i h i The corresponding weights.
[0128] Considering that recommendations are primarily based on the user's recent interests, we utilize the last element h with index 'a'. a As a reference for the query, for all previous h i Perform weighted aggregation, α i h i The corresponding weights, denoted as h, are used as the final interest representation.
[0129] h represents the final embedded representation of each product after passing through multiple self-attention blocks, since local information is aggregated every time a self-attention block is passed. The subscript h i This can be understood as representing the user's interests within a time period centered on the i-th item and with a radius of Δt. Considering that the user's recent interests are the primary recommendation reference, we use the last item with index 'a' as the query, and then search for all previous items h. i We perform weighted aggregation to represent user interests and preferences, which is then used as the final interest representation, denoted as h.
[0130] A diagram illustrating the weighted summation of the self-attention calculation results via the aggregation module is shown below. Figure 6 As shown.
[0131] S17. The final interest representation h after aggregation is multiplied by the embedding matrix of the candidate products to obtain the probability that the candidate products will be interacted with. Recommendation results are then generated based on these probabilities, specifically:
[0132]
[0133] Where M represents the embedding matrix of candidate products, This represents the probability that a candidate product will be interacted with.
[0134] S2, training the self-attention sequence recommendation model fusing time information by using the historical interaction sequence of the user in the obtained data set, to obtain a trained self-attention sequence recommendation model fusing time information.
[0135] In an embodiment, a data set is obtained, the self-attention sequence recommendation model fusing time information is trained by using the obtained data set, and the training is stopped when the parameters of the recommendation model reach convergence. The data set includes a collection of all user data, including user information and historical interaction sequence of each user, wherein the historical interaction sequence includes a product sequence interacted by the user and a corresponding timestamp sequence.
[0136] In another embodiment, a data set is obtained, the obtained data set is divided into a training set, a validation set and a test set, the self-attention sequence recommendation model fusing time information is trained by using the training set, and the recommendation model is verified and tested by using the validation set and the test set.
[0137] Specifically, the self-attention sequence recommendation model fusing time information is trained according to the recommendation result by using cross-entropy as a loss function, and the loss function is as follows:
[0138]
[0139] Wherein, m represents the total number of candidate products.
[0140] S3, obtaining the historical interaction sequence of the user to be recommended, inputting the historical interaction sequence of the user to be recommended into the trained self-attention sequence recommendation model fusing time information, obtaining a target recommended product, and recommending the target recommended product to the user.
[0141] Specifically, the historical interaction sequence of the user to be recommended also contains a product sequence and a corresponding timestamp sequence.
[0142] Figure 7 A self-attention sequence recommendation system fusing time information is provided by the embodiment of the application. As shown in the figure, the self-attention sequence recommendation system fusing time information includes a sequence recommendation model construction module, a sequence recommendation model training module and a product recommendation module. Figure 7
[0143] The sequence recommendation model construction module constructs a self-attention sequence recommendation model fusing time information.
[0144] The sequence recommendation model training module trains the self-attention sequence recommendation model fusing time information by using the historical interaction sequence of the user in the obtained data set, to obtain a trained self-attention sequence recommendation model fusing time information.
[0145] The commodity recommendation module acquires a historical interaction sequence of a user to be recommended, inputs the historical interaction sequence of the user to be recommended into the trained self-attention sequence recommendation model fusing time information, obtains a target recommended commodity, and recommends the target recommended commodity to the user.
[0146] The self-attention sequence recommendation system fusing time information can be implemented in the form of a computer program, which can run on a computer device.
[0147] The computer device can be a server, which can be a standalone server or a server cluster composed of multiple servers.
[0148] The computer device includes a processor, a memory and a network interface connected through a system bus, wherein the memory can include a non-volatile storage medium and an internal memory.
[0149] The non-volatile storage medium can store an operating system and a computer program. The computer program includes program instructions that, when executed, can cause the processor to perform a self-attention sequence recommendation method fusing time information.
[0150] The processor is used to provide computing and control capabilities to support the operation of the entire computer device.
[0151] The internal memory provides an environment for the running of the computer program in the non-volatile storage medium, which, when executed by the processor, can cause the processor to perform a self-attention sequence recommendation method fusing time information.
[0152] The network interface is used for network communication with other devices. Those skilled in the art can understand that the above computer device structure is only part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different component arrangement.
[0153] The processor is used to run the computer program stored in the memory, which implements the self-attention sequence recommendation method fusing time information as described in embodiment one.
[0154] It should be understood that, in the embodiments of the present application, the processor can be a central processing unit (CPU), and the processor can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.
[0155] It can be understood by those skilled in the art that all or part of the processes in the method of the above-mentioned embodiments can be completed by a computer program instructing related hardware. The computer program includes program instructions, and the computer program can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the above-mentioned embodiment of the method.
[0156] The present application also provides a storage medium. The storage medium can be a computer-readable storage medium. The storage medium stores a computer program, wherein the computer program is executed by a processor to make the processor execute the self-attention sequence recommendation method of fusing time information according to the embodiment one.
[0157] The storage medium can be a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk, and various computer-readable storage media that can store program codes.
[0158] It can be understood by those skilled in the art that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be realized in electronic hardware, computer software or a combination of both. In order to clearly illustrate the interchangeability of hardware and software, the components and steps of the examples have been described in the above description in general terms. Whether the functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. A person skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0159] In several embodiments provided by the present application, it should be understood that the disclosed apparatus and method can be implemented in other manners. For example, the described apparatus embodiments are merely schematic. For example, the division of the units is merely a logical function division. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In this way, the inventive idea can be implemented.
[0160] The steps in the method embodiments of the present application can be adjusted, combined and deleted in sequence according to actual needs. The units in the apparatus embodiments of the present application can be combined, divided and deleted according to actual needs. In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit.
[0161] The integrated unit, if realized in the form of a software functional unit and sold or used as an independent product, can be stored in a storage medium. Based on such understanding, the technical solutions of the present application essentially or the part that contributes to the prior art, or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a plurality of instructions for causing a computer device (which can be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.
[0162] Note that the above are merely preferred embodiments of the present application and the technical principles applied. Those skilled in the art will understand that the present application is not limited to the specific embodiments described herein, and those skilled in the art can make various obvious changes, re-adjustments and substitutions without departing from the scope of the present application. Therefore, although the present application has been described in more detail through the above embodiments, the present application is not limited to the above embodiments, and can include more other equivalent embodiments without departing from the concept of the present application, and the scope of the present application is determined by the scope of the appended claims.
Claims
1. A fusion time information self-attention sequence recommendation method, characterized in that, The method comprises the steps of: S1, constructing a self-attention sequence recommendation model fusing time information, specifically: S11, data augmentation is performed on a historical interaction sequence of a user, wherein the historical interaction sequence comprises a commodity sequence (i1, i2,..., i n ) and a corresponding timestamp sequence (t1, t2,..., t n ), and a continuous subsequence containing a first item of the commodity sequence and the timestamp sequence is used for data augmentation to obtain an extended historical interaction sequence of the user; S12, for each commodity sequence in the extended user's historical interaction sequence, calculate the time interval between each commodity and the last commodity according to the corresponding timestamp sequence, denoted as (t 1n , t 2n , t 3n ,..., t (n-1)n , t nn ), which is the corresponding time interval information contained in the corresponding commodity sequence, wherein t 1n represents the time interval difference between the first element and the n th element of the input sequence; S13. Using an embedding layer, the product sequence and the time interval information are transformed into an embedding vector of the same dimension. A dummy element is added to the end of the embedding vector and encoded to obtain the embedding representation of the product sequence E = (e1, e2, ..., e...). n e a The embedded representation of the time interval information is P = (p1, p2, ..., p...). n p a ), where a is the subscript of the virtual product; S14, concatenating the embedding of the commodity sequence with the embedding of the time interval information, generating a new embedding representation of commodities X = (x1, x2,..., x n , a where x i = Concat(e i , p i ), Concat() denotes the concatenation operation, x i ∈ R d ; S15. The new embedded representation X of the product is input into a multi-self-attention module composed of multiple self-attention blocks. After passing through the last self-attention block, the output sequence (h1, h2, ..., h...) is obtained. n ,h a ), where h i This represents the user's interest within a time period centered on the i-th item, with a radius of Δt, where i = 1, ..., n, h. a Embedded for storing aggregated information in virtual goods; In each of the self-attention blocks, the following steps are included: (1) performing self-attention calculation on the new embedding representation X of the commodity, specifically: First, calculate Q, K, and V vectors according to X, and map X to query, key, and value spaces: Q = XW Q K = XW K V = XW V where W Q ,W K ,W V ∈R d×d is a learnable parameter, where R is a notation representing dimension, and the superscript d x d means that the first dimension of the parameter matrix is d, and the second dimension is also d. Second, perform limited self-attention calculation using Q, K, and V: Where S represents the output of local self-attention, d represents the dimension of the embedding vector; Attention() represents the local self-attention operation, SA() is an alias of the Attention() operation; Softmax() is a mapping function that maps a vector to a probability distribution vector, and the sum of each probability is 1, which is a normalized exponential function; d is the dimension of the embedding vector; During the self-attention calculation process, in Q i and K j When performing the calculation, the corresponding timestamp t i and t j The interval is limited to a certain time range, i.e., |t i -t j |≤Δt, where Δt is a learnable parameter, and Q i K represents the target node in the query space. j Represents the neighbor nodes in the key space; (2) passing S obtained after the self-attention operation through two layers of point-wise feedforward networks: F1 = FFN(S) = RELU(SW 1 + b 1 )W 2 + b 2 F2 = FFN(F1) = RELU(F1W 1 + b 1 )W 2 + b 2 where W 1 , W 2 ∈ R d×d , b 1 ∈ R 2 ∈ R d are all learnable parameters; FFN() represents a fully connected layer with RELU() as the activation function; S represents the output of self-attention, F1 represents the output of the first layer of feed-forward network, and F2 represents the output of the second layer of feed-forward network. (3) adding Layer Normalization, residual connection, and Dropout operation to the self-attention layer and feedforward layer in the self-attention block, specifically as follows: G(X) = X + Dropout(G(LayerNorm(X))) where G generally represents an operation of self-attention or a pre-feedback layer, X represents an input when a certain operation is performed; LayerNorm() represents a layer normalization operation, which is added before the input operation to accelerate model learning; the Dropout() operation inactivates neurons with a certain probability during the training process, is added before the output operation, and prevents overfitting; and represents an inner product; μ and σ 2 represent the mean and variance of X; and α and β represent a scale factor and a bias term, which are trainable parameters; and ∈ is a constant; Step S15 specifically includes: inputting the new embedding representation X of the commodity into the first self-attention block to obtain a first output result, inputting the first output result into the second self-attention block for calculation, and calculating until the last self-attention block is calculated. The output result of the last self-attention block is the output sequence of the multi-layer self-attention module, specifically as follows: wherein b represents the b-th self-attention block, there are L self-attention blocks in total, and L is a hyper-parameter; S (b) represents the output of the self-attention in the b-th self-attention block, represents the output of the first layer feed-forward network in the b-th self-attention block, represents the output of the second layer feed-forward network in the b-th self-attention block; the input of the first self-attention block is X = (x1, x2, …, x n a ), and the output of the last self-attention block is recorded as (h1, h2, …, h n a ); the output of the second layer feed-forward network in the self-attention block will be used as the input of the next self-attention block; S16, aggregating the output sequence with attention to obtain the final interest representation h of the user, the specific steps including: calculating the corresponding weight and aggregating the representation: where h i represents the interest representation of the user in the time period with the i-th item as the center and △t as the radius; α i represents h i corresponding weight; and all h i are aggregated with weights as the final interest representation, denoted as h. S17, performing inner product of the aggregated final interest representation h and the embedding matrix of the candidate commodity to obtain the probability of interaction of the candidate commodity, and generating a recommendation result according to the probability, specifically: wherein M represents an embedding matrix of the candidate commodity, represents a probability that the candidate commodity is interacted; S2, training the self-attention sequence recommendation model fusing time information using the obtained historical interaction sequence of the user in the data set, to obtain a trained self-attention sequence recommendation model fusing time information; S3, obtaining the historical interaction sequence of the user to be recommended, and inputting the historical interaction sequence of the user to be recommended into the trained self-attention sequence recommendation model fusing time information, to obtain a target recommended commodity, and recommending the target recommended commodity to the user.
2. The method of claim 1, wherein, In step S11, the data is augmented using the continuous subsequences of the commodity sequence and the timestamp sequence containing the first item, specifically including: for the commodity sequence (i1, i2, ……i n ), the continuous subsequences containing the first item are (i1, i2), (i1, i2, i3), (i1, i2, i3, i4), ……, (i1, i2, ……i n-1 ); for the timestamp sequence (t1, t2, ……t n ), the continuous subsequences containing the first item are (t1, t2), (t1, t2, t3), (t1, t2, t3, t4), ……, (t1, t2, ……t n-1 ).
3. The method of claim 1, wherein, In step S2, the self-attention sequence recommendation model fusing time information is trained using cross-entropy as a loss function according to the recommendation result, and the loss function is: Where m represents the total number of candidate commodities.
4. A self-attention sequence recommendation system that fuses temporal information, characterized by, The recommendation system performs the self-attention sequence recommendation method fusing time information according to claim 1, including a sequence recommendation model construction module, a sequence recommendation model training module, and a commodity recommendation module; The sequence recommendation model construction module constructs a self-attention sequence recommendation model fusing time information; the sequence recommendation model training module trains the self-attention sequence recommendation model fusing time information by using the historical interaction sequences of users in the obtained data set, and obtains a trained self-attention sequence recommendation model fusing time information; The commodity recommendation module obtains the historical interaction sequence of a user to be recommended, inputs the historical interaction sequence of the user to be recommended into the trained self-attention sequence recommendation model fusing time information, obtains a target recommended commodity, and recommends the target recommended commodity to the user.
5. A computer device, comprising: The device comprises a memory and a processor, the memory stores a computer program, and the processor implements the method of any one of claims 1 to 3 when executing the computer program.
Citation Information
Patent Citations
Commodity recommendation model for relieving data sparsity and commodity cold start
CN113139850A