# User Dynamic Preference Construction Method Based on Behavior Sequence

Authors: Mingshi Luo; Xiaoli Zhang; Jiao Li; Peipei Duan; Shengnan Lu
Journal: Scientific Programming
 (2022)

---

## Abstract

People’s needs are constantly changing, and the performance of traditional recommendation algorithms is no longer enough to meet the demand. Considering that users’ preferences change with time, the users’ behavior sequence hides the evolution and change law of users’ preferences, so mining the dependence of the users’ behavior sequence is extremely important to predict users’ dynamic preferences. From the perspective of constructing users’ dynamic preferences, this paper proposes a users’ dynamic preference model based on users’ behavior sequences. Firstly, the user’s interest model is divided into short-term and long-term interest models. The short-term interest reflects the user’s current preference, and the long-term interest refers to the user’s interest from all his historical behaviors, representing the user’s consistent and stable preference. Users’ dynamic preference is obtained by integrating short-term interest and long-term interest, which solves the problem that the user’s preference cannot reflect the change in the user’s interest in real-time. We use the public Amazon review dataset to test the model we propose in the paper. Our model achieves the best performance, with a maximum performance improvement of 15.21% compared with the basic model (BPR, NCF) and 2.04% compared with the sequence model (GRU4REC, Caser, etc.), which proves that the user’s dynamic preference model can effectively predict the user’s dynamic preference. Users’ dynamic preferences are helpful in predicting users’ real-time preferences, especially in the field of recommendation.


---

## Body

## 1. Introduction

With the high development of the Internet, various applications of mobile terminals cover almost all aspects of our life. The recommendation system provides personalized recommendation services according to users’ preferences, making terminal services more intelligent. Users’ preferences vary at different times for the same item. At the same time, the association relationship between items changes over time, resulting in users’ preferences for associated items changing over time. Therefore, it is difficult to capture users’ dynamic preferences in real time. These items interacted by users sorted by time are user’s behavior sequences. The users’ behavior sequence is the implicit feedback of the change of user’s preference over time. Therefore, mining the characteristics of the user’s behavior sequence is extremely important to predicting the user’s preference. The recommendation algorithm based on user’s behavior sequence is sequence recommendation. The classic collaborative filtering recommendation algorithm [1] is a kind of algorithm that predicts users’ ratings of items based on a user-item interaction matrix. It only considers the interaction relationship between users and individual items and does not consider the impact of the user’s behavior sequence on the user’s preferences from a global perspective.In recent years, with the rapid development of deep learning, recommendation algorithm based on deep learning has attracted the attention of many scholars. Compared with the traditional recommendation model, the deep learning recommendation model can better extract potential features of items and users and mine more information hidden in the user’s behavior sequence. For many unstructured data reflecting user preferences, such as images, texts, and videos, deep learning can realize end-to-end feature extraction, to integrate these features into the representation of users or items. For the unstructured data of the user’s behavior sequence, deep learning can better mine sequence dependence characteristics and predict the user’s dynamic preference more accurately.Early deep learning recommendation models mainly combine Automatic Encoder [2] or Restricted Boltzmann Machine [3] (RBM) with Collaborative Filtering. For example, Salakhutdinov et al. proposed a Collaborative Filtering recommendation model based on RBM [4], and Phung et al. proposed a collaborative filtering model based on the Ordinal Boltzmann Machine [5]. Both models calculate the user’s score on items by reconstructing the user-item score matrix and infer the user’s preference for items according to the score. However, the influence of the user’s behavior sequence on user preference is not fully considered. Considering the similarity between the user’s behavior sequence and natural language sequence in establishing sequence dependence, Hidasi et al. [6] proposed a short-term behavior sequence recommendation model based on RNN, which is the first work to apply RNN to sequence recommendation and takes the user’s behavior sequence as input to predict the next item in the user’s behavior sequence. Hidasi et al. proposed a P-RNN model [7], which integrates the features of items, such as item ID and text features, to establish the user’s behavior sequence model. Chairatanakul et al. [8] combined the RNN model with the translation model to establish high-order dependencies between items. The sequence recommendation model based on RNN only constructs static dependence characteristics of the user’s behavior sequence, without considering that the dependence between items will change over time. To build a dynamic user preference model, Sun et al. [9] used capsule network to build users’ dynamic preferences, and Alibaba proposed DIN [10] model. Considering that different items in users’ behavior sequence have different contributions to users’ preferences, the DIN model uses the attention mechanism to calculate the weight to obtain a deep interest model. Considering that users’ interests are constantly evolving and changing, Alibaba improved the DIN model, proposed DIEN [11] model, and designed the interest evolution layer to accurately express the dynamic changes in users’ interests.The above models have the following problems: (1) when constructing the user’s dynamic preference, the influence of time interval or consumption cycle on the user’s preference is not considered; that is, in the process of constructing the behavior sequence dependence, the time factor is not integrated into the sequence modeling; (2) without considering the sparsity of sequence data, similar to the user-item matrix, the user’s behavior sequence data still has the problem of data sparsity. To solve the above two problems, this paper proposes users’ dynamic preference model based on the user’s behavior sequence. The user’s dynamic preference is divided into short-term interest and long-term interest. Short-term interest reflects the user’s current preference. Long-term interest represents the user’s consistent and stable preference. The short-term interest of users is obtained by constructing three dependencies: local dependency, global dependency, and sequence dependency. The introduction of global dependency can well alleviate the problem of sparse sequence data. When constructing the user’s long-term interest model, the Hawkes process is combined with the self-attention model, and the time factor is introduced into the construction of sequence dependence. Finally, the user’s dynamic preference model is obtained by integrating short-term interest and long-term interest, which solves the problem that the user’s preference model can not reflect the change in user’s interest in real-time, and the user’s preference model in the time dimension is established.For this paper, the main contributions are as follows:(1)
User’s dynamic preference model is built, and the influence mechanism of the user’s behavior sequence on user preference is established. The user’s dynamic preference model is divided into the short-term interest model and long-term interest model, and the influence relationship between long-term interest and short-term interest is established.(2)
By introducing neighbor users’ behavior information, the problem of sparse sequence data is alleviated. The behavior of users will be affected by neighbor users, and neighbor users are introduced into short-term interest modeling to alleviate the problem of data sparsity.(3)
Combining the Hawkes process model with the self-attention model, time is introduced into sequence modeling. Introducing the Hawkes process model not only establishes the sequence dependence, but also integrates the influence of the time factor on preference.(4)
Real data sets are used to verify the effectiveness and the progressiveness of the proposed model.


## 2. Related Work

### 2.1. Recommendation Algorithm Based on Deep Learning

With the development of deep learning, deep learning algorithm, which has huge advantages in feature extraction, has been more and more used in recommendation system. The recommendation system is a matching model, which matches users with items according to the characteristics of users and items, so the accurate extraction of features can effectively improve the accuracy of recommendation. Traditional feature extraction methods rely on manual and experience, while deep learning can realize end-to-end automatic feature extraction, which has great advantages over traditional feature extraction. In order to learn the interaction feature of items, Zhang et al. proposed FNN [12] model to pretrain the DNN model by embedding item representation with the trained factor decomposition model FM; Qu et al. proposed the PNN [13]model, which adds feature product cross-layer between the embedding layer and the full connection layer to complete the cross between features. To extract high-order interaction features and low-order interaction features at the same time, Google proposed the Wide and deep [14] model. The Wide and deep model has achieved good results in actual industrial scenes, but manual feature extraction is still required for low-order features. In order to solve this problem, Guo et al. proposed Deep FM [15] model, abandoned manual feature engineering, and combined deep learning with factor decomposition machine FM to realize end-to-end learning, taking into account high-order and low-order interactive features. Considering that a deep neural network can approximate any continuous function, that is, it can simulate the interaction characteristics of any order, He et al. proposed NCF [16], using a multilayer perceptron to learn the interaction characteristics of higher-order instead of a factor decomposition model. Considering that different features have different weights on the representation of items, many scholars introduce the attention mechanism into the deep recommendation system. The attention mechanism comes from human vision. People always pay attention to important places and ignore unimportant information when watching objects. He et al. proposed the AFM [17] model to obtain the contribution weight of each interaction feature of the item through the attention mechanism. In addition to individual features and interaction features, the user’s interaction sequence features are also key to predicting the user’s dynamic preferences. Almost all the above works ignore the user’s behavior sequence features, and this paper will introduce the related work of sequence recommendation next.


### 2.2. Sequence Recommendation

Users’ preferences change over time. Capturing the rule of preference change is extremely important to predict the dynamic evolution of preferences. The user’s behavior reflects the user’s preference, and the user’s behavior sequence reflects the change of preference. Therefore, mining the dependence characteristics of behavior sequences can effectively predict the user’s dynamic preference. Wang et al. [18] established a dynamic model of user preference changing with time by constructing the substitution relationship and complementary relationship between items and fitting the attenuation law of these two relationships with time by using the normal distribution. For repeated consumption items, the consumption cycle is mostly different. Adaptive capture of this cycle can effectively predict the changes in users’ preferences. Wang et al. [19] studied the time dynamics of repeated consumption of different items, combined Collaborative filtering with the Hawkes process [20], and established short-term and long-term time dynamics models. Li et al. [21] considered time when modeling users’ dynamic preferences, proposed an improved GRU model, added time to the GRU model, combined it with the attention mechanism to calculate the weight of long-term interest and short-term interest, and finally used the improved GRU to obtain users’ final preferences. According to the user’s behavior sequence to capture the user’s dynamic preference, the user’s dynamic preference is associated with time, which can predict the user’s preference in real-time and then improve the accuracy and real-time performance of the recommendation system.


## 2.1. Recommendation Algorithm Based on Deep Learning

With the development of deep learning, deep learning algorithm, which has huge advantages in feature extraction, has been more and more used in recommendation system. The recommendation system is a matching model, which matches users with items according to the characteristics of users and items, so the accurate extraction of features can effectively improve the accuracy of recommendation. Traditional feature extraction methods rely on manual and experience, while deep learning can realize end-to-end automatic feature extraction, which has great advantages over traditional feature extraction. In order to learn the interaction feature of items, Zhang et al. proposed FNN [12] model to pretrain the DNN model by embedding item representation with the trained factor decomposition model FM; Qu et al. proposed the PNN [13]model, which adds feature product cross-layer between the embedding layer and the full connection layer to complete the cross between features. To extract high-order interaction features and low-order interaction features at the same time, Google proposed the Wide and deep [14] model. The Wide and deep model has achieved good results in actual industrial scenes, but manual feature extraction is still required for low-order features. In order to solve this problem, Guo et al. proposed Deep FM [15] model, abandoned manual feature engineering, and combined deep learning with factor decomposition machine FM to realize end-to-end learning, taking into account high-order and low-order interactive features. Considering that a deep neural network can approximate any continuous function, that is, it can simulate the interaction characteristics of any order, He et al. proposed NCF [16], using a multilayer perceptron to learn the interaction characteristics of higher-order instead of a factor decomposition model. Considering that different features have different weights on the representation of items, many scholars introduce the attention mechanism into the deep recommendation system. The attention mechanism comes from human vision. People always pay attention to important places and ignore unimportant information when watching objects. He et al. proposed the AFM [17] model to obtain the contribution weight of each interaction feature of the item through the attention mechanism. In addition to individual features and interaction features, the user’s interaction sequence features are also key to predicting the user’s dynamic preferences. Almost all the above works ignore the user’s behavior sequence features, and this paper will introduce the related work of sequence recommendation next.


## 2.2. Sequence Recommendation

Users’ preferences change over time. Capturing the rule of preference change is extremely important to predict the dynamic evolution of preferences. The user’s behavior reflects the user’s preference, and the user’s behavior sequence reflects the change of preference. Therefore, mining the dependence characteristics of behavior sequences can effectively predict the user’s dynamic preference. Wang et al. [18] established a dynamic model of user preference changing with time by constructing the substitution relationship and complementary relationship between items and fitting the attenuation law of these two relationships with time by using the normal distribution. For repeated consumption items, the consumption cycle is mostly different. Adaptive capture of this cycle can effectively predict the changes in users’ preferences. Wang et al. [19] studied the time dynamics of repeated consumption of different items, combined Collaborative filtering with the Hawkes process [20], and established short-term and long-term time dynamics models. Li et al. [21] considered time when modeling users’ dynamic preferences, proposed an improved GRU model, added time to the GRU model, combined it with the attention mechanism to calculate the weight of long-term interest and short-term interest, and finally used the improved GRU to obtain users’ final preferences. According to the user’s behavior sequence to capture the user’s dynamic preference, the user’s dynamic preference is associated with time, which can predict the user’s preference in real-time and then improve the accuracy and real-time performance of the recommendation system.


## 3. User’s Dynamic Preference Model

Before introducing the user’s dynamic preference model in detail, we first define the variables related to the model. User set is defined asU=u1,u2,…un, item set is defined as V=v1,v2,…vn, user’s behavior sequence is defined as SLu=S1u,S2u…Snu, Siu=b1,b2,…bm refers to the behavior subsequence of user u, Siu∈SLu, bi=vi,ti,ei, vi∈V is an interactive item of the user u at the time ti, and ei is the context environment. The context environment can be the current season, date, user location, etc. Given the user’s click sequence SLu at time t, the user’s dynamic preference model can predict the probability of items at time t + 1 and recommend the Top-k items to the user according to the probability.The structure of the user dynamic preference model proposed in this paper is shown in Figure1. The model is mainly composed of two parts: the user’s short-term interest model and the long-term interest model. The short-term interest model is responsible for capturing users’ current preferences, and the long-term interest model obtains users’ stable preferences by modeling users’ historical behavior sequence, integrating users’ short-term interests and long-term interests to get user’s dynamic preferences.Figure 1
Model architecture.


### 3.1. Short-Term Interest Model

When users buy or search for something on the Internet, users’ short-term behavior have a strong purpose; that is, the items the user interacts with have a clear scope and strong purpose. Users’ short-term interactive items will also have some uncertainty; that is, the user’s behavior record may contain many kinds of items, and corresponding user’ behaviors are also diverse, such as clicking, collecting, sharing, and purchasing. All kinds of user’s behaviors can be regarded as implicit feedback of user’s preferences. At the same time, the user’s behavior sequence contains complex dependencies, such as local dependence, global dependence, and sequence dependence. From a local perspective, users’ short-term behavior is only determined by user’s interests, that is, local dependence. From a global perspective, users’ short-term behavior will also be affected by other users, because users will refer to other users’ behavior, that is, global dependence, for example, referring to other users’ comments on the item to determine the user’s consumption behavior or deciding whether to buy something according to whether your friends buy something. Therefore, this paper models the user’s short-term sequence dependence from three angles, that is, local dependence, global dependence, and sequence dependence, and the user’s short-term preference model is obtained by fusing the above three dependencies.


#### 3.1.1. Local Dependence Representation

Local dependence is built based on the user’s interaction graph, which contains a variety of complex jump transformation relationships between items. Select the recent interaction sequenceSiu=b1,b2,…bm to construct the user’s interaction graph. The interaction graph G=bi,ci is composed of nodes and edges, as shown in Figure 2. ci∈C , C is the edge set, and MI,MO∈RN×N are the out-degree and in-degree matrices, respectively. The out-degree and in-degree matrices represent the weight relationship, connection relationship, and jump relationship between items, as shown in Figure 2.Figure 2
G, out-degree and in-degree matrices.The nodes in the graph are represented as low latitude embedding vectorss∈Rd×1, and the node at contains local dependence and can be expressed as(1)at=ConcatMIs1,…,snWaI+bI,Mos1,…,snWao+bo.WaI,bI,Wao,bo are the parameters to be learned, WaI,Wao are the Weight parameters, and bI,bo are the bias terms.


#### 3.1.2. Global Dependency Representation

User’s behavior will be affected by other users, that is, the global dependency. In order to establish this dependency, this paper uses the idea of collaborative filtering to establish global dependency. In the interaction sequenceSiu=b1,b2,…bm, for nodes bi, multiple users are having the same interaction behavior with bi. This paper selects users who have same multiple interaction behaviors with user u to construct the neighbor matrix. However, user-item matrix is extremely sparse. Therefore, directly using the whole user-item interaction matrix to find the nearest neighbor users of user u has the problems of high computational complexity and low search efficiency. In order to solve this problem, this paper uses the Local Sensitive Hash [22] (LSH) to select K users as the neighbor users of user u and construct the neighbor matrix Mu∈RN×N according to the K neighbor users. The basic idea of LSH is that, after hashing some data in the original data, it hopes that the original adjacent data can be hashed into the same bucket with the same bucket number. After hashing all the data in the original data, a hash table is obtained, and these original data are scattered into the bucket of the hash table. The data belonging to the same bucket is probably adjacent, and irrelevant data may be hashed into the same bucket. The mapping process is shown in Figure 3. After the hash mapping transformation, the adjacent data in the original space falls into the same bucket, the query data is hashed to obtain its bucket number, then all the data in the bucket corresponding to the bucket number are taken out, and then the data adjacent to the query data can be found by linear matching.Figure 3
LSH mapping diagram.Based on the idea of hash mapping, the hash function selected by Local Sensitive Hash needs to meet the following requirement: for any two pointsx,y in high-dimensional space:Ifdx,y<=R, the probability of hx=hy is not less than P1.Ifdx,y>=cR, the probability of hx=hy is not greater than P2.wherec is greater than 1, R is a constant, P1>P2, dx,y indicates the distance between two points x,y, and hx,hy, respectively, indicate the hash mapping of x,y. The hash function satisfying the above conditions is called R,cR,P1,P2−sensitive.The process of indexing massive data using LSH and performing approximate nearest neighbor search through the index is shown in Figure4.Figure 4
LSH search process.This paper selects the mapping function according to the experiment. The neighbor matrixMu of user u is obtained through the Local Sensitive Hash. Considering the user’s interaction behaviors such as clicking, collecting, and sharing, it reflects that users have different preferences for different items, so different weight values are used to encode the items in Mu. Then, Funk SVD is used to decompose the Mu. The decomposition process is as follows:(2)Mu≈PTQ,PT∈RN×k,Q∈Rk×N.The decomposition loss function is(3)argmin∑i,jmij−qjpi2+λpi22+qj22,where mij is the element in the matrix Mu, and pi,qj are the row vector and column vector corresponding to the matrix PT,Q. The matrix PT can be regarded as the collection of each user’s preference vector, which also includes the influence between users. Therefore, this paper regards the matrix PT as the global dependence of user u. The node at′ containing local dependence and global dependence at time t can be expressed as(4)at′=ConcatMtIs1,…,snWaI+bI,Mtos1,…,snWao+bo,PTs1,…,snWap+bp.where Wap,bp is the parameter to be learned, Wap is the Weight parameter, and bp is the bias term.


#### 3.1.3. Short-Term Interest Representation

Subsections3.1.1 and 3.1.2 construct the local dependency and global dependency. Based on the local dependency and global dependency, this subsection uses Recurrent Neural Network to establish the sequence dependency. A Recurrent Neural Network (RNN) is a kind of neural network with short-term memory ability. In the Recurrent Neural Network, neuron nodes can accept not only the information of other neurons, but also their information to form a network structure with a loop. Compared with a feedforward neural network, Recurrent Neural Network is more in accord with the structure of biological neural network. In this paper, GRU is used to model short-term behavior dependence. The status update mode of GRU is(5)hs=fxs,hs−1,where xs is the current input, and hs−1 is the output of the last hidden GRU unit. The calculation process of GRU unit is as follows:(6)zs=σxs,hs−1Wz+bz,rs=σxs,hs−1Wr+br,hs′=ϕxs,hs−1⊙rsWh+bh,hs=zs⊙hs−1+1−zs⊙hs′.where Wr,Wz,Wh∈Rd×2d are the learning weight matrix, bz,br,bh are the bias terms, and ⊙ is the corresponding element product operation. σ and ϕ are the activate functions for sigmoid and tanh. zsandrs are the corresponding update gate and forgetting gate, hs′ is the candidate state gate, hs−1 is the historical state, and hs is the output state. The node hs is obtained based on the node at′ at time t and the node hs−1 at time t − 1:(7)hs=GRUat′,hs−1.Combined with all output of the GRU unit at each time, the user’s short-term interest is obtained:(8)H=h1,h2…hn.


### 3.2. Long-Term Interest Model

The user’s long-term interest changes over time and contains multiple interest points. Different interest points have different effects on user’s current interest, and the change rule of different interest points over time is also different. At the same time, they influence each other. So, building a user’s long-term interest model is more challenging. To solve this problem, by deeply studying the Hawkes process model and self-attention mechanism [20], this paper improves the Hawkes process model and combines the improved Hawkes model with the self-attention model to establish the user’s long-term preference model.


#### 3.2.1. Subsequence Embedding

In order to model the long-term interest of the user, this paper divides the user’s historical interaction sequence into several subsequences. For the interaction subsequencesSiu=b1,b2,…bm, each element bi is embedded into a low dimensional dense vector s∈Rd×1, so that the subsequence Siu can be expressed as a low dimensional embedding matrix Siu∈Rd×N, where d is the embedding dimension of the item, and N is the number of items in the Siu. Subsequences Siu can be expressed as(9)Siu=⋯s1⋯⋯s2⋯⋮⋮⋯sN⋯.In order to establish the dependency between subsequences, this paper uses a convolutional neural network (CNN) to establish the dependency between subsequences. Considering that there are different types of dependencies between items in subsequences, multiple-scale convolution kernels are used to establish different levels of dependencies. In this paper, multiple convolution kernels are designed. Assuming that thei-th convolution kernel is Fk∈dm×n, k∈1,2…n, m,n respectively represent the width and length of the convolution kernel. After convolution operation, Siu can be mapped as follows:(10)ck=σcSiu⊙Fk,where ⊙ is the corresponding convolution operation, and σc is the corresponding activation function. Different convolution kernel is used for mapping Siu to obtain different levels of dependence between subsequence items:(11)c=c1,c2⋯ck.In this paper, the most critical feature ofck is extracted by pooling operation. After pooling, subsequences containing multiple dependency features are obtained:(12)pSiu=poolingc1,poolingc2⋯poolingck.For other subsequences, the same operation is used to obtain the corresponding characterization.


#### 3.2.2. Construction of Long-Term Preference Model

For natural language sequences, modeling the complex relationship between words is the key to understanding natural language. The relationship between words includes semantic relationships and positional relationships. Self-attention [23] model greatly improves the ability of machines to understand natural language compared with the traditional natural language model. Self-attention directly establishes the weight relationship and position relationship between two words. Self-attention model is an attention core, which embeds word sequence as a low dimensional matrix X∈Rl×d, and l,d are the embedded dimensions, respectively. WQ∈Rd×z is the weight of the query matrix, WK∈Rd×z is the weight of the key matrix, and WV∈Rd×z is the weight of the value matrix. After the mapping of the three matrices, the corresponding query matrix Q, key matrix K, value matrix V are obtained, namely,(13)Q,K,V=X×WQ,X×WK,X×WV.Calculate the attention weightscore according to the query matrix Q and key matrix K, namely,(14)scoreQ,K=softmaxQKTd,d is the scale factor, in order to avoid gradient oscillation caused by too large inner product value, scoreQ,K∈RlQ×lK, where lQ,lK respectively represent the dimension values of the weight matrix. The attention matrix is obtained by multiplying the value matrix V and the weight matrix scoreQ,K:(15)AttentionQ,K,V=scoreQ,KV.In natural language, the relationship between two words will not change with time, but the user’s preference will change over time, and influence of past preference on current preference will change with time. So, the self-attention model is suitable for text sequence modeling, but not suitable for modeling of user’s long-term preference directly. In order to solve this problem, this paper combines the Hawkes process with Self-attention model to propose the time self-attention model, which considers the user’s preference changing with time. Hawkes process is a classical point process model. The point process model predicts the time and probability of an event in the future according to past historical events. Its mathematical model is as follows:(16)Prit+dt|Itu,dt=λitdt,where Itu is the corresponding historical time series, dt is the time interval, λit is the intensity function, and it+dt is the events at the time t+dt. The internal mechanism of the Hawkes process is that historical events have an incentive effect on the occurrence of future events, and the influence of historical events will be accumulated. The general form of intensity function is(17)λt=λo+∑ti<tgexct−ti,λo, gexct respectively represent the foundation strength and the incentive effects of historical events on the current, and gexct is generally defined as(18)pSiu=poolingc1,poolingc2⋯poolingck.Hawkes process believes that historical events have only an incentive effect. However historical events have both incentive and inhibitory effects on future events. At the same time,gexct artificially taking the exponential function of time cannot cover all kinds of complex situations in reality. So, this paper uses a multilayer perceptron to fit the interest incentive function gΔt,up,cp:(19)gΔt,up,cp=MLPWtΔt+Wuup+Wccp+bo,where Δt  =  tp−ti is the time interval from the time ti to the current time tp, up is the user’s preference vector at the current time, and cp is the user’s context vector at the current time, Wt , Wu and Wc are the weight parameter to be learned, and bo is the bias to be learned. The user’s preference for the item is related not only to the time interval, but also to the user’s current preference and the user’s context, and then the user’s interest density function is(20)λu,t=λi,ou,t+λi,ou,tgΔt,up,cp,where λi,ou,t the user’s historical preference. In section 3.2.1, the user’s historical interaction subsequence pSiu is obtained. The user’s historical interaction subsequence matrix is C=pS1u,pS2u,…pSiu, the corresponding query weight matrix, key weight matrix, and value weight matrix are WcQ,WcK,WcV respectively, and the corresponding query matrix Qc, key matrix Kc and value matrix Vc are(21)Qc,Kc,Vc=C×WcQ,C×WcK,C×WcV.Combining the self-attention model and the Hawkes process model, we get the time self-attention model, that is, the user’s long-term preference modelVL:(22)scoreQc,Kc=softmax1+QcKcTgΔt,up,cpd,VL=scoreQc,KcVc.


#### 3.2.3. User’s Dynamic Preference Model

This paper combines users’ short-term preferencesH=h1,h2…ht with users’ long-term preference VL=scoreQc,KcVc to obtain users’ dynamic preferences model:(23)U=concatH,VL.Given the user’s preference modelU, for candidate items vj∈V, the user’s preference prediction model is(24)y^j=softmaxMLPUvj.y^j is user’s preference probability for item vj, and MLP () is a fully connected neural network. The loss function of the prediction model is(25)minτ=∑j=1nyjlogy^j+1−yjlog1−y^j+θ2,where y^j is the predicted preference probability, yj is the actual preference probability, and θ2 is the regularization of model parameters.Taking the useru as an example, the whole build user’s dynamic preference process is as follows:Input: user’s behavior sequence, user-item matrix, user feature, item feature, context environment.Output: The Top-k item recommended to the user u.Embed an item to a vector, embed the user’s behavior subsequenceSiu to a matrix, build a user-item matrix.(1)
for each user in U=u1,u2,...undo(2)
select the subsequenceSiu=b1,b2,…bm to build the user's interaction graph、in-degree MI and out-degree matrix MO , then build the Local dependence model based on the MI,MO.(3)
for subsequenceSiu=b1,b2,…bm, use the LSH to find K neighbor users, then build the neighbor matrix Mu, build the Global dependency model based on the Mu.(4)
use the GRU to build the user’s short-term interestH based on the Local dependence model and Global dependency model.(5)
use the CNN to extract dependency features of different subsequencesSiu , convert each subsequence matrix to a vector pSiu.(6)
combine the Self-attention model withpSiu to get the user's historical preference λi,ou,t get the user’s long-term preference model VL based on the Hawkes process and λi,ou,t.(7)
connectH and VL to get the user’s dynamic preference model U.(8)
calculate the user’s preference probability for itemvj based on the U and the vj(10)
repeat(11)
define the loss function asminτ=∑j=1nyjlogy^j+1−yjlog1−y^j+θ2,.(12)
Calculate the gradient of the loss function for the weight and bias, then update weight and bias until the loss is no more updated.(13)
Final(14)
Return the Top-K items to user u.


## 3.1. Short-Term Interest Model

When users buy or search for something on the Internet, users’ short-term behavior have a strong purpose; that is, the items the user interacts with have a clear scope and strong purpose. Users’ short-term interactive items will also have some uncertainty; that is, the user’s behavior record may contain many kinds of items, and corresponding user’ behaviors are also diverse, such as clicking, collecting, sharing, and purchasing. All kinds of user’s behaviors can be regarded as implicit feedback of user’s preferences. At the same time, the user’s behavior sequence contains complex dependencies, such as local dependence, global dependence, and sequence dependence. From a local perspective, users’ short-term behavior is only determined by user’s interests, that is, local dependence. From a global perspective, users’ short-term behavior will also be affected by other users, because users will refer to other users’ behavior, that is, global dependence, for example, referring to other users’ comments on the item to determine the user’s consumption behavior or deciding whether to buy something according to whether your friends buy something. Therefore, this paper models the user’s short-term sequence dependence from three angles, that is, local dependence, global dependence, and sequence dependence, and the user’s short-term preference model is obtained by fusing the above three dependencies.


### 3.1.1. Local Dependence Representation

Local dependence is built based on the user’s interaction graph, which contains a variety of complex jump transformation relationships between items. Select the recent interaction sequenceSiu=b1,b2,…bm to construct the user’s interaction graph. The interaction graph G=bi,ci is composed of nodes and edges, as shown in Figure 2. ci∈C , C is the edge set, and MI,MO∈RN×N are the out-degree and in-degree matrices, respectively. The out-degree and in-degree matrices represent the weight relationship, connection relationship, and jump relationship between items, as shown in Figure 2.Figure 2
G, out-degree and in-degree matrices.The nodes in the graph are represented as low latitude embedding vectorss∈Rd×1, and the node at contains local dependence and can be expressed as(1)at=ConcatMIs1,…,snWaI+bI,Mos1,…,snWao+bo.WaI,bI,Wao,bo are the parameters to be learned, WaI,Wao are the Weight parameters, and bI,bo are the bias terms.


### 3.1.2. Global Dependency Representation

User’s behavior will be affected by other users, that is, the global dependency. In order to establish this dependency, this paper uses the idea of collaborative filtering to establish global dependency. In the interaction sequenceSiu=b1,b2,…bm, for nodes bi, multiple users are having the same interaction behavior with bi. This paper selects users who have same multiple interaction behaviors with user u to construct the neighbor matrix. However, user-item matrix is extremely sparse. Therefore, directly using the whole user-item interaction matrix to find the nearest neighbor users of user u has the problems of high computational complexity and low search efficiency. In order to solve this problem, this paper uses the Local Sensitive Hash [22] (LSH) to select K users as the neighbor users of user u and construct the neighbor matrix Mu∈RN×N according to the K neighbor users. The basic idea of LSH is that, after hashing some data in the original data, it hopes that the original adjacent data can be hashed into the same bucket with the same bucket number. After hashing all the data in the original data, a hash table is obtained, and these original data are scattered into the bucket of the hash table. The data belonging to the same bucket is probably adjacent, and irrelevant data may be hashed into the same bucket. The mapping process is shown in Figure 3. After the hash mapping transformation, the adjacent data in the original space falls into the same bucket, the query data is hashed to obtain its bucket number, then all the data in the bucket corresponding to the bucket number are taken out, and then the data adjacent to the query data can be found by linear matching.Figure 3
LSH mapping diagram.Based on the idea of hash mapping, the hash function selected by Local Sensitive Hash needs to meet the following requirement: for any two pointsx,y in high-dimensional space:Ifdx,y<=R, the probability of hx=hy is not less than P1.Ifdx,y>=cR, the probability of hx=hy is not greater than P2.wherec is greater than 1, R is a constant, P1>P2, dx,y indicates the distance between two points x,y, and hx,hy, respectively, indicate the hash mapping of x,y. The hash function satisfying the above conditions is called R,cR,P1,P2−sensitive.The process of indexing massive data using LSH and performing approximate nearest neighbor search through the index is shown in Figure4.Figure 4
LSH search process.This paper selects the mapping function according to the experiment. The neighbor matrixMu of user u is obtained through the Local Sensitive Hash. Considering the user’s interaction behaviors such as clicking, collecting, and sharing, it reflects that users have different preferences for different items, so different weight values are used to encode the items in Mu. Then, Funk SVD is used to decompose the Mu. The decomposition process is as follows:(2)Mu≈PTQ,PT∈RN×k,Q∈Rk×N.The decomposition loss function is(3)argmin∑i,jmij−qjpi2+λpi22+qj22,where mij is the element in the matrix Mu, and pi,qj are the row vector and column vector corresponding to the matrix PT,Q. The matrix PT can be regarded as the collection of each user’s preference vector, which also includes the influence between users. Therefore, this paper regards the matrix PT as the global dependence of user u. The node at′ containing local dependence and global dependence at time t can be expressed as(4)at′=ConcatMtIs1,…,snWaI+bI,Mtos1,…,snWao+bo,PTs1,…,snWap+bp.where Wap,bp is the parameter to be learned, Wap is the Weight parameter, and bp is the bias term.


### 3.1.3. Short-Term Interest Representation

Subsections3.1.1 and 3.1.2 construct the local dependency and global dependency. Based on the local dependency and global dependency, this subsection uses Recurrent Neural Network to establish the sequence dependency. A Recurrent Neural Network (RNN) is a kind of neural network with short-term memory ability. In the Recurrent Neural Network, neuron nodes can accept not only the information of other neurons, but also their information to form a network structure with a loop. Compared with a feedforward neural network, Recurrent Neural Network is more in accord with the structure of biological neural network. In this paper, GRU is used to model short-term behavior dependence. The status update mode of GRU is(5)hs=fxs,hs−1,where xs is the current input, and hs−1 is the output of the last hidden GRU unit. The calculation process of GRU unit is as follows:(6)zs=σxs,hs−1Wz+bz,rs=σxs,hs−1Wr+br,hs′=ϕxs,hs−1⊙rsWh+bh,hs=zs⊙hs−1+1−zs⊙hs′.where Wr,Wz,Wh∈Rd×2d are the learning weight matrix, bz,br,bh are the bias terms, and ⊙ is the corresponding element product operation. σ and ϕ are the activate functions for sigmoid and tanh. zsandrs are the corresponding update gate and forgetting gate, hs′ is the candidate state gate, hs−1 is the historical state, and hs is the output state. The node hs is obtained based on the node at′ at time t and the node hs−1 at time t − 1:(7)hs=GRUat′,hs−1.Combined with all output of the GRU unit at each time, the user’s short-term interest is obtained:(8)H=h1,h2…hn.


## 3.1.1. Local Dependence Representation

Local dependence is built based on the user’s interaction graph, which contains a variety of complex jump transformation relationships between items. Select the recent interaction sequenceSiu=b1,b2,…bm to construct the user’s interaction graph. The interaction graph G=bi,ci is composed of nodes and edges, as shown in Figure 2. ci∈C , C is the edge set, and MI,MO∈RN×N are the out-degree and in-degree matrices, respectively. The out-degree and in-degree matrices represent the weight relationship, connection relationship, and jump relationship between items, as shown in Figure 2.Figure 2
G, out-degree and in-degree matrices.The nodes in the graph are represented as low latitude embedding vectorss∈Rd×1, and the node at contains local dependence and can be expressed as(1)at=ConcatMIs1,…,snWaI+bI,Mos1,…,snWao+bo.WaI,bI,Wao,bo are the parameters to be learned, WaI,Wao are the Weight parameters, and bI,bo are the bias terms.


## 3.1.2. Global Dependency Representation

User’s behavior will be affected by other users, that is, the global dependency. In order to establish this dependency, this paper uses the idea of collaborative filtering to establish global dependency. In the interaction sequenceSiu=b1,b2,…bm, for nodes bi, multiple users are having the same interaction behavior with bi. This paper selects users who have same multiple interaction behaviors with user u to construct the neighbor matrix. However, user-item matrix is extremely sparse. Therefore, directly using the whole user-item interaction matrix to find the nearest neighbor users of user u has the problems of high computational complexity and low search efficiency. In order to solve this problem, this paper uses the Local Sensitive Hash [22] (LSH) to select K users as the neighbor users of user u and construct the neighbor matrix Mu∈RN×N according to the K neighbor users. The basic idea of LSH is that, after hashing some data in the original data, it hopes that the original adjacent data can be hashed into the same bucket with the same bucket number. After hashing all the data in the original data, a hash table is obtained, and these original data are scattered into the bucket of the hash table. The data belonging to the same bucket is probably adjacent, and irrelevant data may be hashed into the same bucket. The mapping process is shown in Figure 3. After the hash mapping transformation, the adjacent data in the original space falls into the same bucket, the query data is hashed to obtain its bucket number, then all the data in the bucket corresponding to the bucket number are taken out, and then the data adjacent to the query data can be found by linear matching.Figure 3
LSH mapping diagram.Based on the idea of hash mapping, the hash function selected by Local Sensitive Hash needs to meet the following requirement: for any two pointsx,y in high-dimensional space:Ifdx,y<=R, the probability of hx=hy is not less than P1.Ifdx,y>=cR, the probability of hx=hy is not greater than P2.wherec is greater than 1, R is a constant, P1>P2, dx,y indicates the distance between two points x,y, and hx,hy, respectively, indicate the hash mapping of x,y. The hash function satisfying the above conditions is called R,cR,P1,P2−sensitive.The process of indexing massive data using LSH and performing approximate nearest neighbor search through the index is shown in Figure4.Figure 4
LSH search process.This paper selects the mapping function according to the experiment. The neighbor matrixMu of user u is obtained through the Local Sensitive Hash. Considering the user’s interaction behaviors such as clicking, collecting, and sharing, it reflects that users have different preferences for different items, so different weight values are used to encode the items in Mu. Then, Funk SVD is used to decompose the Mu. The decomposition process is as follows:(2)Mu≈PTQ,PT∈RN×k,Q∈Rk×N.The decomposition loss function is(3)argmin∑i,jmij−qjpi2+λpi22+qj22,where mij is the element in the matrix Mu, and pi,qj are the row vector and column vector corresponding to the matrix PT,Q. The matrix PT can be regarded as the collection of each user’s preference vector, which also includes the influence between users. Therefore, this paper regards the matrix PT as the global dependence of user u. The node at′ containing local dependence and global dependence at time t can be expressed as(4)at′=ConcatMtIs1,…,snWaI+bI,Mtos1,…,snWao+bo,PTs1,…,snWap+bp.where Wap,bp is the parameter to be learned, Wap is the Weight parameter, and bp is the bias term.


## 3.1.3. Short-Term Interest Representation

Subsections3.1.1 and 3.1.2 construct the local dependency and global dependency. Based on the local dependency and global dependency, this subsection uses Recurrent Neural Network to establish the sequence dependency. A Recurrent Neural Network (RNN) is a kind of neural network with short-term memory ability. In the Recurrent Neural Network, neuron nodes can accept not only the information of other neurons, but also their information to form a network structure with a loop. Compared with a feedforward neural network, Recurrent Neural Network is more in accord with the structure of biological neural network. In this paper, GRU is used to model short-term behavior dependence. The status update mode of GRU is(5)hs=fxs,hs−1,where xs is the current input, and hs−1 is the output of the last hidden GRU unit. The calculation process of GRU unit is as follows:(6)zs=σxs,hs−1Wz+bz,rs=σxs,hs−1Wr+br,hs′=ϕxs,hs−1⊙rsWh+bh,hs=zs⊙hs−1+1−zs⊙hs′.where Wr,Wz,Wh∈Rd×2d are the learning weight matrix, bz,br,bh are the bias terms, and ⊙ is the corresponding element product operation. σ and ϕ are the activate functions for sigmoid and tanh. zsandrs are the corresponding update gate and forgetting gate, hs′ is the candidate state gate, hs−1 is the historical state, and hs is the output state. The node hs is obtained based on the node at′ at time t and the node hs−1 at time t − 1:(7)hs=GRUat′,hs−1.Combined with all output of the GRU unit at each time, the user’s short-term interest is obtained:(8)H=h1,h2…hn.


## 3.2. Long-Term Interest Model

The user’s long-term interest changes over time and contains multiple interest points. Different interest points have different effects on user’s current interest, and the change rule of different interest points over time is also different. At the same time, they influence each other. So, building a user’s long-term interest model is more challenging. To solve this problem, by deeply studying the Hawkes process model and self-attention mechanism [20], this paper improves the Hawkes process model and combines the improved Hawkes model with the self-attention model to establish the user’s long-term preference model.


### 3.2.1. Subsequence Embedding

In order to model the long-term interest of the user, this paper divides the user’s historical interaction sequence into several subsequences. For the interaction subsequencesSiu=b1,b2,…bm, each element bi is embedded into a low dimensional dense vector s∈Rd×1, so that the subsequence Siu can be expressed as a low dimensional embedding matrix Siu∈Rd×N, where d is the embedding dimension of the item, and N is the number of items in the Siu. Subsequences Siu can be expressed as(9)Siu=⋯s1⋯⋯s2⋯⋮⋮⋯sN⋯.In order to establish the dependency between subsequences, this paper uses a convolutional neural network (CNN) to establish the dependency between subsequences. Considering that there are different types of dependencies between items in subsequences, multiple-scale convolution kernels are used to establish different levels of dependencies. In this paper, multiple convolution kernels are designed. Assuming that thei-th convolution kernel is Fk∈dm×n, k∈1,2…n, m,n respectively represent the width and length of the convolution kernel. After convolution operation, Siu can be mapped as follows:(10)ck=σcSiu⊙Fk,where ⊙ is the corresponding convolution operation, and σc is the corresponding activation function. Different convolution kernel is used for mapping Siu to obtain different levels of dependence between subsequence items:(11)c=c1,c2⋯ck.In this paper, the most critical feature ofck is extracted by pooling operation. After pooling, subsequences containing multiple dependency features are obtained:(12)pSiu=poolingc1,poolingc2⋯poolingck.For other subsequences, the same operation is used to obtain the corresponding characterization.


### 3.2.2. Construction of Long-Term Preference Model

For natural language sequences, modeling the complex relationship between words is the key to understanding natural language. The relationship between words includes semantic relationships and positional relationships. Self-attention [23] model greatly improves the ability of machines to understand natural language compared with the traditional natural language model. Self-attention directly establishes the weight relationship and position relationship between two words. Self-attention model is an attention core, which embeds word sequence as a low dimensional matrix X∈Rl×d, and l,d are the embedded dimensions, respectively. WQ∈Rd×z is the weight of the query matrix, WK∈Rd×z is the weight of the key matrix, and WV∈Rd×z is the weight of the value matrix. After the mapping of the three matrices, the corresponding query matrix Q, key matrix K, value matrix V are obtained, namely,(13)Q,K,V=X×WQ,X×WK,X×WV.Calculate the attention weightscore according to the query matrix Q and key matrix K, namely,(14)scoreQ,K=softmaxQKTd,d is the scale factor, in order to avoid gradient oscillation caused by too large inner product value, scoreQ,K∈RlQ×lK, where lQ,lK respectively represent the dimension values of the weight matrix. The attention matrix is obtained by multiplying the value matrix V and the weight matrix scoreQ,K:(15)AttentionQ,K,V=scoreQ,KV.In natural language, the relationship between two words will not change with time, but the user’s preference will change over time, and influence of past preference on current preference will change with time. So, the self-attention model is suitable for text sequence modeling, but not suitable for modeling of user’s long-term preference directly. In order to solve this problem, this paper combines the Hawkes process with Self-attention model to propose the time self-attention model, which considers the user’s preference changing with time. Hawkes process is a classical point process model. The point process model predicts the time and probability of an event in the future according to past historical events. Its mathematical model is as follows:(16)Prit+dt|Itu,dt=λitdt,where Itu is the corresponding historical time series, dt is the time interval, λit is the intensity function, and it+dt is the events at the time t+dt. The internal mechanism of the Hawkes process is that historical events have an incentive effect on the occurrence of future events, and the influence of historical events will be accumulated. The general form of intensity function is(17)λt=λo+∑ti<tgexct−ti,λo, gexct respectively represent the foundation strength and the incentive effects of historical events on the current, and gexct is generally defined as(18)pSiu=poolingc1,poolingc2⋯poolingck.Hawkes process believes that historical events have only an incentive effect. However historical events have both incentive and inhibitory effects on future events. At the same time,gexct artificially taking the exponential function of time cannot cover all kinds of complex situations in reality. So, this paper uses a multilayer perceptron to fit the interest incentive function gΔt,up,cp:(19)gΔt,up,cp=MLPWtΔt+Wuup+Wccp+bo,where Δt  =  tp−ti is the time interval from the time ti to the current time tp, up is the user’s preference vector at the current time, and cp is the user’s context vector at the current time, Wt , Wu and Wc are the weight parameter to be learned, and bo is the bias to be learned. The user’s preference for the item is related not only to the time interval, but also to the user’s current preference and the user’s context, and then the user’s interest density function is(20)λu,t=λi,ou,t+λi,ou,tgΔt,up,cp,where λi,ou,t the user’s historical preference. In section 3.2.1, the user’s historical interaction subsequence pSiu is obtained. The user’s historical interaction subsequence matrix is C=pS1u,pS2u,…pSiu, the corresponding query weight matrix, key weight matrix, and value weight matrix are WcQ,WcK,WcV respectively, and the corresponding query matrix Qc, key matrix Kc and value matrix Vc are(21)Qc,Kc,Vc=C×WcQ,C×WcK,C×WcV.Combining the self-attention model and the Hawkes process model, we get the time self-attention model, that is, the user’s long-term preference modelVL:(22)scoreQc,Kc=softmax1+QcKcTgΔt,up,cpd,VL=scoreQc,KcVc.


### 3.2.3. User’s Dynamic Preference Model

This paper combines users’ short-term preferencesH=h1,h2…ht with users’ long-term preference VL=scoreQc,KcVc to obtain users’ dynamic preferences model:(23)U=concatH,VL.Given the user’s preference modelU, for candidate items vj∈V, the user’s preference prediction model is(24)y^j=softmaxMLPUvj.y^j is user’s preference probability for item vj, and MLP () is a fully connected neural network. The loss function of the prediction model is(25)minτ=∑j=1nyjlogy^j+1−yjlog1−y^j+θ2,where y^j is the predicted preference probability, yj is the actual preference probability, and θ2 is the regularization of model parameters.Taking the useru as an example, the whole build user’s dynamic preference process is as follows:Input: user’s behavior sequence, user-item matrix, user feature, item feature, context environment.Output: The Top-k item recommended to the user u.Embed an item to a vector, embed the user’s behavior subsequenceSiu to a matrix, build a user-item matrix.(1)
for each user in U=u1,u2,...undo(2)
select the subsequenceSiu=b1,b2,…bm to build the user's interaction graph、in-degree MI and out-degree matrix MO , then build the Local dependence model based on the MI,MO.(3)
for subsequenceSiu=b1,b2,…bm, use the LSH to find K neighbor users, then build the neighbor matrix Mu, build the Global dependency model based on the Mu.(4)
use the GRU to build the user’s short-term interestH based on the Local dependence model and Global dependency model.(5)
use the CNN to extract dependency features of different subsequencesSiu , convert each subsequence matrix to a vector pSiu.(6)
combine the Self-attention model withpSiu to get the user's historical preference λi,ou,t get the user’s long-term preference model VL based on the Hawkes process and λi,ou,t.(7)
connectH and VL to get the user’s dynamic preference model U.(8)
calculate the user’s preference probability for itemvj based on the U and the vj(10)
repeat(11)
define the loss function asminτ=∑j=1nyjlogy^j+1−yjlog1−y^j+θ2,.(12)
Calculate the gradient of the loss function for the weight and bias, then update weight and bias until the loss is no more updated.(13)
Final(14)
Return the Top-K items to user u.


## 3.2.1. Subsequence Embedding

In order to model the long-term interest of the user, this paper divides the user’s historical interaction sequence into several subsequences. For the interaction subsequencesSiu=b1,b2,…bm, each element bi is embedded into a low dimensional dense vector s∈Rd×1, so that the subsequence Siu can be expressed as a low dimensional embedding matrix Siu∈Rd×N, where d is the embedding dimension of the item, and N is the number of items in the Siu. Subsequences Siu can be expressed as(9)Siu=⋯s1⋯⋯s2⋯⋮⋮⋯sN⋯.In order to establish the dependency between subsequences, this paper uses a convolutional neural network (CNN) to establish the dependency between subsequences. Considering that there are different types of dependencies between items in subsequences, multiple-scale convolution kernels are used to establish different levels of dependencies. In this paper, multiple convolution kernels are designed. Assuming that thei-th convolution kernel is Fk∈dm×n, k∈1,2…n, m,n respectively represent the width and length of the convolution kernel. After convolution operation, Siu can be mapped as follows:(10)ck=σcSiu⊙Fk,where ⊙ is the corresponding convolution operation, and σc is the corresponding activation function. Different convolution kernel is used for mapping Siu to obtain different levels of dependence between subsequence items:(11)c=c1,c2⋯ck.In this paper, the most critical feature ofck is extracted by pooling operation. After pooling, subsequences containing multiple dependency features are obtained:(12)pSiu=poolingc1,poolingc2⋯poolingck.For other subsequences, the same operation is used to obtain the corresponding characterization.


## 3.2.2. Construction of Long-Term Preference Model

For natural language sequences, modeling the complex relationship between words is the key to understanding natural language. The relationship between words includes semantic relationships and positional relationships. Self-attention [23] model greatly improves the ability of machines to understand natural language compared with the traditional natural language model. Self-attention directly establishes the weight relationship and position relationship between two words. Self-attention model is an attention core, which embeds word sequence as a low dimensional matrix X∈Rl×d, and l,d are the embedded dimensions, respectively. WQ∈Rd×z is the weight of the query matrix, WK∈Rd×z is the weight of the key matrix, and WV∈Rd×z is the weight of the value matrix. After the mapping of the three matrices, the corresponding query matrix Q, key matrix K, value matrix V are obtained, namely,(13)Q,K,V=X×WQ,X×WK,X×WV.Calculate the attention weightscore according to the query matrix Q and key matrix K, namely,(14)scoreQ,K=softmaxQKTd,d is the scale factor, in order to avoid gradient oscillation caused by too large inner product value, scoreQ,K∈RlQ×lK, where lQ,lK respectively represent the dimension values of the weight matrix. The attention matrix is obtained by multiplying the value matrix V and the weight matrix scoreQ,K:(15)AttentionQ,K,V=scoreQ,KV.In natural language, the relationship between two words will not change with time, but the user’s preference will change over time, and influence of past preference on current preference will change with time. So, the self-attention model is suitable for text sequence modeling, but not suitable for modeling of user’s long-term preference directly. In order to solve this problem, this paper combines the Hawkes process with Self-attention model to propose the time self-attention model, which considers the user’s preference changing with time. Hawkes process is a classical point process model. The point process model predicts the time and probability of an event in the future according to past historical events. Its mathematical model is as follows:(16)Prit+dt|Itu,dt=λitdt,where Itu is the corresponding historical time series, dt is the time interval, λit is the intensity function, and it+dt is the events at the time t+dt. The internal mechanism of the Hawkes process is that historical events have an incentive effect on the occurrence of future events, and the influence of historical events will be accumulated. The general form of intensity function is(17)λt=λo+∑ti<tgexct−ti,λo, gexct respectively represent the foundation strength and the incentive effects of historical events on the current, and gexct is generally defined as(18)pSiu=poolingc1,poolingc2⋯poolingck.Hawkes process believes that historical events have only an incentive effect. However historical events have both incentive and inhibitory effects on future events. At the same time,gexct artificially taking the exponential function of time cannot cover all kinds of complex situations in reality. So, this paper uses a multilayer perceptron to fit the interest incentive function gΔt,up,cp:(19)gΔt,up,cp=MLPWtΔt+Wuup+Wccp+bo,where Δt  =  tp−ti is the time interval from the time ti to the current time tp, up is the user’s preference vector at the current time, and cp is the user’s context vector at the current time, Wt , Wu and Wc are the weight parameter to be learned, and bo is the bias to be learned. The user’s preference for the item is related not only to the time interval, but also to the user’s current preference and the user’s context, and then the user’s interest density function is(20)λu,t=λi,ou,t+λi,ou,tgΔt,up,cp,where λi,ou,t the user’s historical preference. In section 3.2.1, the user’s historical interaction subsequence pSiu is obtained. The user’s historical interaction subsequence matrix is C=pS1u,pS2u,…pSiu, the corresponding query weight matrix, key weight matrix, and value weight matrix are WcQ,WcK,WcV respectively, and the corresponding query matrix Qc, key matrix Kc and value matrix Vc are(21)Qc,Kc,Vc=C×WcQ,C×WcK,C×WcV.Combining the self-attention model and the Hawkes process model, we get the time self-attention model, that is, the user’s long-term preference modelVL:(22)scoreQc,Kc=softmax1+QcKcTgΔt,up,cpd,VL=scoreQc,KcVc.


## 3.2.3. User’s Dynamic Preference Model

This paper combines users’ short-term preferencesH=h1,h2…ht with users’ long-term preference VL=scoreQc,KcVc to obtain users’ dynamic preferences model:(23)U=concatH,VL.Given the user’s preference modelU, for candidate items vj∈V, the user’s preference prediction model is(24)y^j=softmaxMLPUvj.y^j is user’s preference probability for item vj, and MLP () is a fully connected neural network. The loss function of the prediction model is(25)minτ=∑j=1nyjlogy^j+1−yjlog1−y^j+θ2,where y^j is the predicted preference probability, yj is the actual preference probability, and θ2 is the regularization of model parameters.Taking the useru as an example, the whole build user’s dynamic preference process is as follows:Input: user’s behavior sequence, user-item matrix, user feature, item feature, context environment.Output: The Top-k item recommended to the user u.Embed an item to a vector, embed the user’s behavior subsequenceSiu to a matrix, build a user-item matrix.(1)
for each user in U=u1,u2,...undo(2)
select the subsequenceSiu=b1,b2,…bm to build the user's interaction graph、in-degree MI and out-degree matrix MO , then build the Local dependence model based on the MI,MO.(3)
for subsequenceSiu=b1,b2,…bm, use the LSH to find K neighbor users, then build the neighbor matrix Mu, build the Global dependency model based on the Mu.(4)
use the GRU to build the user’s short-term interestH based on the Local dependence model and Global dependency model.(5)
use the CNN to extract dependency features of different subsequencesSiu , convert each subsequence matrix to a vector pSiu.(6)
combine the Self-attention model withpSiu to get the user's historical preference λi,ou,t get the user’s long-term preference model VL based on the Hawkes process and λi,ou,t.(7)
connectH and VL to get the user’s dynamic preference model U.(8)
calculate the user’s preference probability for itemvj based on the U and the vj(10)
repeat(11)
define the loss function asminτ=∑j=1nyjlogy^j+1−yjlog1−y^j+θ2,.(12)
Calculate the gradient of the loss function for the weight and bias, then update weight and bias until the loss is no more updated.(13)
Final(14)
Return the Top-K items to user u.


## 4. Experiment

### 4.1. Dataset

This paper uses Amazon review data, which is a public data set from Amazon to test user’s preference model proposed in this paper. Amazon review data is a general data set for evaluating the performance of recommendation algorithms, which contains rich product and user behavior information, like comments (rating, text), product metadata (description, category information, price, brand, and image characteristics), and links (also including viewing/purchasing links). We experiment with four subdatasets, which are Clothing_ Shoes_ Jewelry, Electronics, Movies_ TV, and Grocery_ Gourmet_ Food. Each data set contains user ID, item ID, time, user comments, basic attributes of items, and other characteristic information. The statistical information of each data set is shown in Table1, and the interactions are the number of interactions between user and item. For each data set, 70% is used to train the model, 20% is used to test the performance of the model, and 10% is used to evaluate of the model.Table 1
Dataset statistics.
DatasetUserItemInteractionsElectronics40570153478497449221Movies_TV20030821491504329155Clothing_shoes_jewelry28868327137815072767Grocery_gourmet_food7303501226481207464


### 4.2. Experimental Comparison Model

In this paper, the following models are used as experimental comparison models:BPR: BPR [24] is a classical Bayesian ranking model, which is widely used as a baseline model for comparison. The basic idea is that after representing users and items as vectors, in the new vector space, users should be closer to the items they like than the items they do not like.NCF: NCF [25] is the first classical model that combines neural networks and collaborative filtering. NCF takes the user-item interaction matrix as the input of neural network and uses a multilayer perceptron to learn the nonlinear interaction between user and item, so as to replace the simple inner product operation of user and item vector.GRU4REC: GRU4REC [6] is the classical model that introduces RNN to sequence recommendation. The dependence between sequence items is established through GRU, and combined with a feedforward neural network, the user’s preference probability for each item is obtained.SASRec: SASRec [26] directly applies the self-attention mechanism to sequence recommendation. It uses self-attention to model the user’s historical sequence and predicts the items that may be clicked in the future based on the user’s historical sequence.Caser: Caser [27] embeds the user’s behavior sequence into a matrix, extracts the dependency patterns in the behavior sequence using a convolution neural network, extracts different dependency patterns using different convolution kernels, and fuses a variety of sequence dependencies to obtain the user’s preference model.ReChourus: ReChourus [18] is a recommendation model that considers time attenuation in sequence recommendation. The model divides the relationship between items in the user’s click sequence into a complementary relationship or substitution relationship and uses normal distribution to simulate the time attenuation law of the two relationships.Tahk: the sequence recommendation model is proposed in this paper.In order to reflect the effectiveness and the progressiveness of Tahk, we compare the Tahk with traditional collaborative filtering model NCF and BPR-MF to demonstrate the superiority of the sequence recommendation model and compare the Tahk with the classic sequence recommendation model GRU4REC, SASRec, ReChorus, and Caser to show the superiority of Tahk in modeling user’s dynamic preference.


### 4.3. Experimental Evaluation Index

In this paper, two evaluation indexes are used to evaluate the recommendation model. The two indexes are NDCG@k and HR. Normalized Discount Cumulative Gain NDCG is the normalized result of Discounted Cumulative Gain (DCG). The main idea is that the user’s favorite products are ranked at the top of the recommendation list rather than at the bottom, which will increase the user experience to a greater extent. The calculation formula of NDCG is as follows, andiDCG is the ideal DCG.(26)NDCG@K=DCGiDCG.In Top-K recommendation, HR is a commonly used index to measure Recall Rate, and its calculation formula is as follows:(27)HR@K=NumberofHits@kGT,GT is all test sets, and the numerator is the sum of items belonging to the first K recommended by each user.


### 4.4. Experimental Result

#### 4.4.1. Comparison of Overall Performance

In order to compare each model more fairly and effectively, this paper first obtains the optimal parameters of the comparison model through experiments. The process of parameter selection will not be repeated here. It sets BPR the embedding dimension of features as 64, regularization factorλ1=0.01 and learning rate l=0.0001. The number of nonlinear neural network layers of the NCF model is set as 4 layers, and the Dropout rate is set as 0.01. The learning rate of GRU4REC is set to 0.001, the dropout rate is set to 0.5, and the embedding dimension is 100. The parameter setting of SASRec is similar to GRU4REC. The learning rate of Caser is set to 0.001, the L2 regularization rate is set as L2=1e−6, and the activation function of the convolution layer is set to the ReLU function. The embedded dimension of the Rechorus is set to 64, the optimizer selects Adam, and the setting of other parameters is similar to BPR. The overall performance of each comparison model is shown in Table 2 and Table 3.Table 2
Results on electronic and clothing_shoes_jewelry.
MeticsBPRGru4recRechorusNCFSASRecCaserTahkVS base (%)VS bestElectronicsHR@10.26330.28650.32180.23700.29050.28110.33256.921.07%HR@50.52170.55580.56120.48100.55640.54170.56414.240.29%HR@100.64130.67360.66740.59860.67250.66450.66352.22−1.01%HR@150.70880.73940.73880.66750.73680.72180.74413.530.47%NDCG@10.26330.28650.30150.23700.29050.28630.31395.061.24%NDCG@50.39870.42800.44180.36440.43030.43250.45165.290.98%NDCG@100.43740.46620.47960.40240.46790.47220.47854.11−0.11%NDCG@150.45530.48360.49630.42070.48490.48930.51125.591.49%Clothing_shoes_jewelryHR@10.14940.15760.16380.13330.15800.14110.16251.310.45%HR@50.34340.36430.36980.30840.36410.35410.37643.30.66%HR@100.44500.47530.49120.40750.47270.46210.50255.751.13%HR@150.50370.54450.57940.46750.54100.55140.56886.51−1.06%NDCG@10.14940.15760.16750.13330.15800.16010.16211.270.2%NDCG@50.24970.26460.27110.22390.26480.26770.27412.440.3%NDCG@100.28240.30050.31120.25540.29990.28560.32254.011.13%NDCG@150.28910.31880.32140.27170.31800.31500.33414.51.27%Table 3
Results on movie_tv and grocery_gourmet_food.
MeticsBPRGRU4RECRechorusNCFSASRecCaserTahkVS base (%)VS bestGrocery_gourmet_foodHR@10.21900.15570.20110.19990.20770.21130.20450.46−0.68%HR@50.44590.34230.39750.41050.38250.41440.45210.620.62%HR@100.56870.46150.55130.52910.47930.53120.57214.30.34%HR@150.64270.54380.62330.60440.54770.54160.65945.51.67%NDCG@10.21900.15570.15330.19990.20770.15090.18232.7−3.67%NDCG@50.26650.25160.27310.30870.29860.28310.28511.861.2%NDCG@100.32620.29000.33910.34700.32980.32470.35362.741.45%NDCG@150.33580.31180.35660.36690.34720.39120.37123.541.46%Movie_tvHR@10.33020.35260.41220.25820.39160.36410.40637.611.47%HR@50.63570.65000.68210.50820.67490.66120.70256.682.04%HR@100.75310.76070.79340.62020.77810.74250.79654.340.31%HR@150.81100.81690.83810.68350.82930.82430.835615.211.14%NDCG@10.33020.35260.40120.25820.39160.36180.41258.231.13%NDCG@50.49120.51050.55490.38920.54210.51220.54155.03−1.34%NDCG@100.52940.54640.58610.42550.57570.57480.59126.180.48%NDCG@150.54470.56130.59730.44220.58920.57640.59555.050.63%The performance comparison analysis of each model on each data set is shown in Tables2 and 3. Table 2 shows the comparison result on the datasets Electronics and Clothing_Shoes_ Jewelry. Table 3 shows the experimental results on the datasets Movie _Tv, Grocery_Gourmet_Food. The evaluation indexes are HR@K and NDCG@K, and K values are 1, 5, 10, and 15. Overall, Tahk achieves the best performance, with a maximum performance improvement of 15.21% compared with the basic model (BPR, NCF) and 2.04% compared with the sequence model, which proves that the Tahk model can effectively predict the user’s dynamic preference. The overall performance of sequence recommendation models GRU4REC, Rechorus, and SASRec on each data set is better than that of the classical models BPR and NCF, which proves that considering the sequence dependence between items is effective in predicting users’ preferences.The sparsity of the four datasets is different. Clothing_Shoes_Jewelry and Grocery_Gourmet_Food are relatively sparse, while Movie_TV and Electronics are dense, resulting in the overall HR and NDCG on the dense dataset being higher than the sparse dataset, which reflects that the quality of the dataset will greatly affect the performance of the model, whether it is the traditional model or the sequential model. BPR and NCF models only use the user-item interaction matrix, which is the most affected sparse dataset, and their performance is generally poor in the comparison model. Caser considers various dependencies of user’ click sequences and extracts these dependencies by CNN, compared with the GRU4REC model, which only considers sequence dependencies, Caser’s performance is better. The Rechorus model takes into account the substitution and complementarity between items, at the same time, the time decay rule of complementary and alternative items is taken into account, and the result validates the validity and progressiveness of the Rechorus. SASRec uses the self-attention mechanism to capture the long dependencies between sequences items, and its overall performance is better than that of the GRU4REC, which only built the short-term sequence dependencies.In the comparison model used, Rechorus considers the impact of time on user preference and uses the normal distribution to simulate complementary and alternative relations over time. Tahk also considers the influence of time on user’s preference, improves the self-attention model, and uses neural network to fit the distribution function of the user’s interest changing with time. Compared with Rechorus directly specifying the type of distribution function, the distribution function learned by neural network has stronger robustness and adaptability and can change with different users and different scenes, so the Tahk has the better performance. Rechorus model uses knowledge map to incorporate the association relationship between items, and the experimental results also prove its effectiveness. Drawing on this idea, Tahk takes neighbor user’s information into account in modeling target user’s short-term preference, its effectiveness can be seen through the experimental data, and the more detailed proof is given in the Ablation Experiment.RNN model cannot capture the long-distance sequence dependency because the gradient disappears. Self-attention model establishes the sequence dependency through point-to-point, so as to completely avoid this problem. SASRec directly applies the self-attention mechanism to the user’s click sequence modeling, and compared with traditional model BPR and sequence recommendation model GRU4REC, according to the experimental results, the effectiveness of Self-attention mechanism in sequence modeling is proved. Tahk also uses the self-attention mechanism to establish the relationship between user’s behavior subsequences. At the same time, the time factor is added to improve the weight calculation of Self-attention mechanism. The experimental results show that time self-attention is more effective than SASRec.


#### 4.4.2. Common Parameter Experiment

In order to explore the influence of common parameters on each model, we select sequence length and embedding dimension for the experiment. The session length is 10, 20, 30, 40, and 50, which represents the maximum value of sequence length. The embedding dimension is 8, 16, 32, 64, 128, and 256, which represents the embedded dimension of item features. The evaluation index is HR@10 and NDCG@10. The datasets are Electronic, Clothing_Shoes_Jewelry, Grocery_Gourmet_Food, and Movie_Tv. The experimental results are shown in Figures5–7.Figure 5
Results on electronics.Figure 6
Results on clothing_shoes_jewelry.Figure 7
Results on grocery_gourmet_food.GRU4REC, SASRec, Caser, Rechorus, and Tahk are selected for experiments. For each dataset, the performance of Tahk improves steadily with the increase of sequence length, which shows that Tahk can timely capture the changes of user’s interest according to the change of sequence length. In the electronics dataset, the performance of GRU4REC generally decreases with the increase of sequence length, indicating that GRU4REC cannot capture the dependence of long sequences. In the datasets Clothing_Shoes_Jewelry and Grocery_Gourmet_Food, with the increase of sequence length, the performance of each comparison model changes slightly, and the performance of Tahk has been increasing, indicating that Tahk can capture the subtle changes of user’s interest in a long sequence with time.Embedded dimension experiment takes Clothing_Shoes_Jewelry and Growery _Gourmet_Food as the dataset, the evaluation index is still HR@10 and NDCG@10, and the experimental results are shown in Figures8–11. As the embedded dimension increases, the performance of each model rises first and then falls. When the dimension is low, the parameters of each model are less, which limits the learning ability of model to a certain extent. When the dimension is high, the parameters of each model become larger and have stronger learning ability and data fitting ability, but the requirements for memory are also higher, and the training time is significantly longer. For dataset Clothing_Shoes_Jewelry, with the change of embedded dimension, the performance of each model does not change significantly; the reason might be that the dataset is small, resulting in overfitting. For dataset Grocery_Gourmet_Food, the performance of each model changes significantly with the increase of embedded dimensions, the embedded dimension of each model is different, and it must be determined by experiment.Figure 8
Result on clothing_shoes_jewelry.Figure 9
Results on clothing_shoes_jewelry.Figure 10
Results on grocery_gourmet_food.Figure 11
Results on grocery_gourmet_food.


#### 4.4.3. Ablation Experiment

In order to explore the impact of each module of Tahk on the overall performance, ablation experiments are carried out on three modules: time attenuation module, long-term preference module, and global dependence module of short-term preference; these three modules are renamed as Module 1, Module 2, and Module 3 respectively. The original Tahk model removes these three modules, respectively, and obtains three comparison models: Tahk (Without Module 1), Tahk (Without Module 2), and Tahk (Without Module 3). The three comparison models remain the same as the original model, including the experimental parameters and training process. Electronics, Clothing_Shoes_Jewelry, Grocery_Gourmet_Food, and Movie_Tv are experiment datasets. To facilitate writing, the four datasets are abbreviated as electronics, clothing, food, and movie. The experimental results are shown in Figures12 and 13.Figure 12
Result on NDCG@10.Figure 13
Result on HR@10.Tahk (Without Module 1): it means that when calculating the long-term preference weight, the time attenuation is not considered, and the corresponding user’s interest incentive function is removed. Others remain the same as the original model Tahk. This experiment purpose is to verify the impact of time attenuation on user’s preferences.Tahk (Without Module 2): it means that the user’s behavior sequence is regarded as a whole sequence. At the same time, the impact of the time attenuation of the item on the user’s preference is not considered. It is equivalent to removing the long-term preference module and Hawkes process module at the same time. This experiment’s purpose is to verify the division of the sequence that is conducive to predicting the user’s behavior.Tahk (Without Module 3): it means that, in short-term interest modeling, the impact of neighbor users on the target users is not considered; that is, the global dependency is not considered. This experiment’s purpose is to verify that the user’s behavior will be affected by other neighbor users.It can be seen from Figures12 and 13 that the original model Tahk has achieved the best performance on each dataset, indicating that each module has a positive effect on model performance. For the Tahk (Without Module 1) model, there is a great performance difference from the original model Tahk on each dataset. The maximum difference is 9.4%, and the minimum difference is 4.06% for HR@10, indicating that considering time attenuation is extremely important to predict user’s preference. That is, it is effective to establish user’s dynamic preference model. Overall, the Tahk (Without Module 3) model has the smallest gap with the original model Tahk on the four datasets, indicating that neighbor users have a certain impact on the behavior of target users, but it is not the most important factor. In terms of experimental performance, the original model Tahk without considering global dependency can be regarded as the Rechorus model. It is worth that the experimental performance of Tahk (Without Module 2) model on four datasets is between the best and the worst, which shows that the long-term preference module is a module that cannot be ignored, ignoring this module will affect the overall performance of the model. It also shows that dividing the user’s behavior sequence is helpful in predicting user’s preference.


## 4.1. Dataset

This paper uses Amazon review data, which is a public data set from Amazon to test user’s preference model proposed in this paper. Amazon review data is a general data set for evaluating the performance of recommendation algorithms, which contains rich product and user behavior information, like comments (rating, text), product metadata (description, category information, price, brand, and image characteristics), and links (also including viewing/purchasing links). We experiment with four subdatasets, which are Clothing_ Shoes_ Jewelry, Electronics, Movies_ TV, and Grocery_ Gourmet_ Food. Each data set contains user ID, item ID, time, user comments, basic attributes of items, and other characteristic information. The statistical information of each data set is shown in Table1, and the interactions are the number of interactions between user and item. For each data set, 70% is used to train the model, 20% is used to test the performance of the model, and 10% is used to evaluate of the model.Table 1
Dataset statistics.
DatasetUserItemInteractionsElectronics40570153478497449221Movies_TV20030821491504329155Clothing_shoes_jewelry28868327137815072767Grocery_gourmet_food7303501226481207464


## 4.2. Experimental Comparison Model

In this paper, the following models are used as experimental comparison models:BPR: BPR [24] is a classical Bayesian ranking model, which is widely used as a baseline model for comparison. The basic idea is that after representing users and items as vectors, in the new vector space, users should be closer to the items they like than the items they do not like.NCF: NCF [25] is the first classical model that combines neural networks and collaborative filtering. NCF takes the user-item interaction matrix as the input of neural network and uses a multilayer perceptron to learn the nonlinear interaction between user and item, so as to replace the simple inner product operation of user and item vector.GRU4REC: GRU4REC [6] is the classical model that introduces RNN to sequence recommendation. The dependence between sequence items is established through GRU, and combined with a feedforward neural network, the user’s preference probability for each item is obtained.SASRec: SASRec [26] directly applies the self-attention mechanism to sequence recommendation. It uses self-attention to model the user’s historical sequence and predicts the items that may be clicked in the future based on the user’s historical sequence.Caser: Caser [27] embeds the user’s behavior sequence into a matrix, extracts the dependency patterns in the behavior sequence using a convolution neural network, extracts different dependency patterns using different convolution kernels, and fuses a variety of sequence dependencies to obtain the user’s preference model.ReChourus: ReChourus [18] is a recommendation model that considers time attenuation in sequence recommendation. The model divides the relationship between items in the user’s click sequence into a complementary relationship or substitution relationship and uses normal distribution to simulate the time attenuation law of the two relationships.Tahk: the sequence recommendation model is proposed in this paper.In order to reflect the effectiveness and the progressiveness of Tahk, we compare the Tahk with traditional collaborative filtering model NCF and BPR-MF to demonstrate the superiority of the sequence recommendation model and compare the Tahk with the classic sequence recommendation model GRU4REC, SASRec, ReChorus, and Caser to show the superiority of Tahk in modeling user’s dynamic preference.


## 4.3. Experimental Evaluation Index

In this paper, two evaluation indexes are used to evaluate the recommendation model. The two indexes are NDCG@k and HR. Normalized Discount Cumulative Gain NDCG is the normalized result of Discounted Cumulative Gain (DCG). The main idea is that the user’s favorite products are ranked at the top of the recommendation list rather than at the bottom, which will increase the user experience to a greater extent. The calculation formula of NDCG is as follows, andiDCG is the ideal DCG.(26)NDCG@K=DCGiDCG.In Top-K recommendation, HR is a commonly used index to measure Recall Rate, and its calculation formula is as follows:(27)HR@K=NumberofHits@kGT,GT is all test sets, and the numerator is the sum of items belonging to the first K recommended by each user.


## 4.4. Experimental Result

### 4.4.1. Comparison of Overall Performance

In order to compare each model more fairly and effectively, this paper first obtains the optimal parameters of the comparison model through experiments. The process of parameter selection will not be repeated here. It sets BPR the embedding dimension of features as 64, regularization factorλ1=0.01 and learning rate l=0.0001. The number of nonlinear neural network layers of the NCF model is set as 4 layers, and the Dropout rate is set as 0.01. The learning rate of GRU4REC is set to 0.001, the dropout rate is set to 0.5, and the embedding dimension is 100. The parameter setting of SASRec is similar to GRU4REC. The learning rate of Caser is set to 0.001, the L2 regularization rate is set as L2=1e−6, and the activation function of the convolution layer is set to the ReLU function. The embedded dimension of the Rechorus is set to 64, the optimizer selects Adam, and the setting of other parameters is similar to BPR. The overall performance of each comparison model is shown in Table 2 and Table 3.Table 2
Results on electronic and clothing_shoes_jewelry.
MeticsBPRGru4recRechorusNCFSASRecCaserTahkVS base (%)VS bestElectronicsHR@10.26330.28650.32180.23700.29050.28110.33256.921.07%HR@50.52170.55580.56120.48100.55640.54170.56414.240.29%HR@100.64130.67360.66740.59860.67250.66450.66352.22−1.01%HR@150.70880.73940.73880.66750.73680.72180.74413.530.47%NDCG@10.26330.28650.30150.23700.29050.28630.31395.061.24%NDCG@50.39870.42800.44180.36440.43030.43250.45165.290.98%NDCG@100.43740.46620.47960.40240.46790.47220.47854.11−0.11%NDCG@150.45530.48360.49630.42070.48490.48930.51125.591.49%Clothing_shoes_jewelryHR@10.14940.15760.16380.13330.15800.14110.16251.310.45%HR@50.34340.36430.36980.30840.36410.35410.37643.30.66%HR@100.44500.47530.49120.40750.47270.46210.50255.751.13%HR@150.50370.54450.57940.46750.54100.55140.56886.51−1.06%NDCG@10.14940.15760.16750.13330.15800.16010.16211.270.2%NDCG@50.24970.26460.27110.22390.26480.26770.27412.440.3%NDCG@100.28240.30050.31120.25540.29990.28560.32254.011.13%NDCG@150.28910.31880.32140.27170.31800.31500.33414.51.27%Table 3
Results on movie_tv and grocery_gourmet_food.
MeticsBPRGRU4RECRechorusNCFSASRecCaserTahkVS base (%)VS bestGrocery_gourmet_foodHR@10.21900.15570.20110.19990.20770.21130.20450.46−0.68%HR@50.44590.34230.39750.41050.38250.41440.45210.620.62%HR@100.56870.46150.55130.52910.47930.53120.57214.30.34%HR@150.64270.54380.62330.60440.54770.54160.65945.51.67%NDCG@10.21900.15570.15330.19990.20770.15090.18232.7−3.67%NDCG@50.26650.25160.27310.30870.29860.28310.28511.861.2%NDCG@100.32620.29000.33910.34700.32980.32470.35362.741.45%NDCG@150.33580.31180.35660.36690.34720.39120.37123.541.46%Movie_tvHR@10.33020.35260.41220.25820.39160.36410.40637.611.47%HR@50.63570.65000.68210.50820.67490.66120.70256.682.04%HR@100.75310.76070.79340.62020.77810.74250.79654.340.31%HR@150.81100.81690.83810.68350.82930.82430.835615.211.14%NDCG@10.33020.35260.40120.25820.39160.36180.41258.231.13%NDCG@50.49120.51050.55490.38920.54210.51220.54155.03−1.34%NDCG@100.52940.54640.58610.42550.57570.57480.59126.180.48%NDCG@150.54470.56130.59730.44220.58920.57640.59555.050.63%The performance comparison analysis of each model on each data set is shown in Tables2 and 3. Table 2 shows the comparison result on the datasets Electronics and Clothing_Shoes_ Jewelry. Table 3 shows the experimental results on the datasets Movie _Tv, Grocery_Gourmet_Food. The evaluation indexes are HR@K and NDCG@K, and K values are 1, 5, 10, and 15. Overall, Tahk achieves the best performance, with a maximum performance improvement of 15.21% compared with the basic model (BPR, NCF) and 2.04% compared with the sequence model, which proves that the Tahk model can effectively predict the user’s dynamic preference. The overall performance of sequence recommendation models GRU4REC, Rechorus, and SASRec on each data set is better than that of the classical models BPR and NCF, which proves that considering the sequence dependence between items is effective in predicting users’ preferences.The sparsity of the four datasets is different. Clothing_Shoes_Jewelry and Grocery_Gourmet_Food are relatively sparse, while Movie_TV and Electronics are dense, resulting in the overall HR and NDCG on the dense dataset being higher than the sparse dataset, which reflects that the quality of the dataset will greatly affect the performance of the model, whether it is the traditional model or the sequential model. BPR and NCF models only use the user-item interaction matrix, which is the most affected sparse dataset, and their performance is generally poor in the comparison model. Caser considers various dependencies of user’ click sequences and extracts these dependencies by CNN, compared with the GRU4REC model, which only considers sequence dependencies, Caser’s performance is better. The Rechorus model takes into account the substitution and complementarity between items, at the same time, the time decay rule of complementary and alternative items is taken into account, and the result validates the validity and progressiveness of the Rechorus. SASRec uses the self-attention mechanism to capture the long dependencies between sequences items, and its overall performance is better than that of the GRU4REC, which only built the short-term sequence dependencies.In the comparison model used, Rechorus considers the impact of time on user preference and uses the normal distribution to simulate complementary and alternative relations over time. Tahk also considers the influence of time on user’s preference, improves the self-attention model, and uses neural network to fit the distribution function of the user’s interest changing with time. Compared with Rechorus directly specifying the type of distribution function, the distribution function learned by neural network has stronger robustness and adaptability and can change with different users and different scenes, so the Tahk has the better performance. Rechorus model uses knowledge map to incorporate the association relationship between items, and the experimental results also prove its effectiveness. Drawing on this idea, Tahk takes neighbor user’s information into account in modeling target user’s short-term preference, its effectiveness can be seen through the experimental data, and the more detailed proof is given in the Ablation Experiment.RNN model cannot capture the long-distance sequence dependency because the gradient disappears. Self-attention model establishes the sequence dependency through point-to-point, so as to completely avoid this problem. SASRec directly applies the self-attention mechanism to the user’s click sequence modeling, and compared with traditional model BPR and sequence recommendation model GRU4REC, according to the experimental results, the effectiveness of Self-attention mechanism in sequence modeling is proved. Tahk also uses the self-attention mechanism to establish the relationship between user’s behavior subsequences. At the same time, the time factor is added to improve the weight calculation of Self-attention mechanism. The experimental results show that time self-attention is more effective than SASRec.


### 4.4.2. Common Parameter Experiment

In order to explore the influence of common parameters on each model, we select sequence length and embedding dimension for the experiment. The session length is 10, 20, 30, 40, and 50, which represents the maximum value of sequence length. The embedding dimension is 8, 16, 32, 64, 128, and 256, which represents the embedded dimension of item features. The evaluation index is HR@10 and NDCG@10. The datasets are Electronic, Clothing_Shoes_Jewelry, Grocery_Gourmet_Food, and Movie_Tv. The experimental results are shown in Figures5–7.Figure 5
Results on electronics.Figure 6
Results on clothing_shoes_jewelry.Figure 7
Results on grocery_gourmet_food.GRU4REC, SASRec, Caser, Rechorus, and Tahk are selected for experiments. For each dataset, the performance of Tahk improves steadily with the increase of sequence length, which shows that Tahk can timely capture the changes of user’s interest according to the change of sequence length. In the electronics dataset, the performance of GRU4REC generally decreases with the increase of sequence length, indicating that GRU4REC cannot capture the dependence of long sequences. In the datasets Clothing_Shoes_Jewelry and Grocery_Gourmet_Food, with the increase of sequence length, the performance of each comparison model changes slightly, and the performance of Tahk has been increasing, indicating that Tahk can capture the subtle changes of user’s interest in a long sequence with time.Embedded dimension experiment takes Clothing_Shoes_Jewelry and Growery _Gourmet_Food as the dataset, the evaluation index is still HR@10 and NDCG@10, and the experimental results are shown in Figures8–11. As the embedded dimension increases, the performance of each model rises first and then falls. When the dimension is low, the parameters of each model are less, which limits the learning ability of model to a certain extent. When the dimension is high, the parameters of each model become larger and have stronger learning ability and data fitting ability, but the requirements for memory are also higher, and the training time is significantly longer. For dataset Clothing_Shoes_Jewelry, with the change of embedded dimension, the performance of each model does not change significantly; the reason might be that the dataset is small, resulting in overfitting. For dataset Grocery_Gourmet_Food, the performance of each model changes significantly with the increase of embedded dimensions, the embedded dimension of each model is different, and it must be determined by experiment.Figure 8
Result on clothing_shoes_jewelry.Figure 9
Results on clothing_shoes_jewelry.Figure 10
Results on grocery_gourmet_food.Figure 11
Results on grocery_gourmet_food.


### 4.4.3. Ablation Experiment

In order to explore the impact of each module of Tahk on the overall performance, ablation experiments are carried out on three modules: time attenuation module, long-term preference module, and global dependence module of short-term preference; these three modules are renamed as Module 1, Module 2, and Module 3 respectively. The original Tahk model removes these three modules, respectively, and obtains three comparison models: Tahk (Without Module 1), Tahk (Without Module 2), and Tahk (Without Module 3). The three comparison models remain the same as the original model, including the experimental parameters and training process. Electronics, Clothing_Shoes_Jewelry, Grocery_Gourmet_Food, and Movie_Tv are experiment datasets. To facilitate writing, the four datasets are abbreviated as electronics, clothing, food, and movie. The experimental results are shown in Figures12 and 13.Figure 12
Result on NDCG@10.Figure 13
Result on HR@10.Tahk (Without Module 1): it means that when calculating the long-term preference weight, the time attenuation is not considered, and the corresponding user’s interest incentive function is removed. Others remain the same as the original model Tahk. This experiment purpose is to verify the impact of time attenuation on user’s preferences.Tahk (Without Module 2): it means that the user’s behavior sequence is regarded as a whole sequence. At the same time, the impact of the time attenuation of the item on the user’s preference is not considered. It is equivalent to removing the long-term preference module and Hawkes process module at the same time. This experiment’s purpose is to verify the division of the sequence that is conducive to predicting the user’s behavior.Tahk (Without Module 3): it means that, in short-term interest modeling, the impact of neighbor users on the target users is not considered; that is, the global dependency is not considered. This experiment’s purpose is to verify that the user’s behavior will be affected by other neighbor users.It can be seen from Figures12 and 13 that the original model Tahk has achieved the best performance on each dataset, indicating that each module has a positive effect on model performance. For the Tahk (Without Module 1) model, there is a great performance difference from the original model Tahk on each dataset. The maximum difference is 9.4%, and the minimum difference is 4.06% for HR@10, indicating that considering time attenuation is extremely important to predict user’s preference. That is, it is effective to establish user’s dynamic preference model. Overall, the Tahk (Without Module 3) model has the smallest gap with the original model Tahk on the four datasets, indicating that neighbor users have a certain impact on the behavior of target users, but it is not the most important factor. In terms of experimental performance, the original model Tahk without considering global dependency can be regarded as the Rechorus model. It is worth that the experimental performance of Tahk (Without Module 2) model on four datasets is between the best and the worst, which shows that the long-term preference module is a module that cannot be ignored, ignoring this module will affect the overall performance of the model. It also shows that dividing the user’s behavior sequence is helpful in predicting user’s preference.


## 4.4.1. Comparison of Overall Performance

In order to compare each model more fairly and effectively, this paper first obtains the optimal parameters of the comparison model through experiments. The process of parameter selection will not be repeated here. It sets BPR the embedding dimension of features as 64, regularization factorλ1=0.01 and learning rate l=0.0001. The number of nonlinear neural network layers of the NCF model is set as 4 layers, and the Dropout rate is set as 0.01. The learning rate of GRU4REC is set to 0.001, the dropout rate is set to 0.5, and the embedding dimension is 100. The parameter setting of SASRec is similar to GRU4REC. The learning rate of Caser is set to 0.001, the L2 regularization rate is set as L2=1e−6, and the activation function of the convolution layer is set to the ReLU function. The embedded dimension of the Rechorus is set to 64, the optimizer selects Adam, and the setting of other parameters is similar to BPR. The overall performance of each comparison model is shown in Table 2 and Table 3.Table 2
Results on electronic and clothing_shoes_jewelry.
MeticsBPRGru4recRechorusNCFSASRecCaserTahkVS base (%)VS bestElectronicsHR@10.26330.28650.32180.23700.29050.28110.33256.921.07%HR@50.52170.55580.56120.48100.55640.54170.56414.240.29%HR@100.64130.67360.66740.59860.67250.66450.66352.22−1.01%HR@150.70880.73940.73880.66750.73680.72180.74413.530.47%NDCG@10.26330.28650.30150.23700.29050.28630.31395.061.24%NDCG@50.39870.42800.44180.36440.43030.43250.45165.290.98%NDCG@100.43740.46620.47960.40240.46790.47220.47854.11−0.11%NDCG@150.45530.48360.49630.42070.48490.48930.51125.591.49%Clothing_shoes_jewelryHR@10.14940.15760.16380.13330.15800.14110.16251.310.45%HR@50.34340.36430.36980.30840.36410.35410.37643.30.66%HR@100.44500.47530.49120.40750.47270.46210.50255.751.13%HR@150.50370.54450.57940.46750.54100.55140.56886.51−1.06%NDCG@10.14940.15760.16750.13330.15800.16010.16211.270.2%NDCG@50.24970.26460.27110.22390.26480.26770.27412.440.3%NDCG@100.28240.30050.31120.25540.29990.28560.32254.011.13%NDCG@150.28910.31880.32140.27170.31800.31500.33414.51.27%Table 3
Results on movie_tv and grocery_gourmet_food.
MeticsBPRGRU4RECRechorusNCFSASRecCaserTahkVS base (%)VS bestGrocery_gourmet_foodHR@10.21900.15570.20110.19990.20770.21130.20450.46−0.68%HR@50.44590.34230.39750.41050.38250.41440.45210.620.62%HR@100.56870.46150.55130.52910.47930.53120.57214.30.34%HR@150.64270.54380.62330.60440.54770.54160.65945.51.67%NDCG@10.21900.15570.15330.19990.20770.15090.18232.7−3.67%NDCG@50.26650.25160.27310.30870.29860.28310.28511.861.2%NDCG@100.32620.29000.33910.34700.32980.32470.35362.741.45%NDCG@150.33580.31180.35660.36690.34720.39120.37123.541.46%Movie_tvHR@10.33020.35260.41220.25820.39160.36410.40637.611.47%HR@50.63570.65000.68210.50820.67490.66120.70256.682.04%HR@100.75310.76070.79340.62020.77810.74250.79654.340.31%HR@150.81100.81690.83810.68350.82930.82430.835615.211.14%NDCG@10.33020.35260.40120.25820.39160.36180.41258.231.13%NDCG@50.49120.51050.55490.38920.54210.51220.54155.03−1.34%NDCG@100.52940.54640.58610.42550.57570.57480.59126.180.48%NDCG@150.54470.56130.59730.44220.58920.57640.59555.050.63%The performance comparison analysis of each model on each data set is shown in Tables2 and 3. Table 2 shows the comparison result on the datasets Electronics and Clothing_Shoes_ Jewelry. Table 3 shows the experimental results on the datasets Movie _Tv, Grocery_Gourmet_Food. The evaluation indexes are HR@K and NDCG@K, and K values are 1, 5, 10, and 15. Overall, Tahk achieves the best performance, with a maximum performance improvement of 15.21% compared with the basic model (BPR, NCF) and 2.04% compared with the sequence model, which proves that the Tahk model can effectively predict the user’s dynamic preference. The overall performance of sequence recommendation models GRU4REC, Rechorus, and SASRec on each data set is better than that of the classical models BPR and NCF, which proves that considering the sequence dependence between items is effective in predicting users’ preferences.The sparsity of the four datasets is different. Clothing_Shoes_Jewelry and Grocery_Gourmet_Food are relatively sparse, while Movie_TV and Electronics are dense, resulting in the overall HR and NDCG on the dense dataset being higher than the sparse dataset, which reflects that the quality of the dataset will greatly affect the performance of the model, whether it is the traditional model or the sequential model. BPR and NCF models only use the user-item interaction matrix, which is the most affected sparse dataset, and their performance is generally poor in the comparison model. Caser considers various dependencies of user’ click sequences and extracts these dependencies by CNN, compared with the GRU4REC model, which only considers sequence dependencies, Caser’s performance is better. The Rechorus model takes into account the substitution and complementarity between items, at the same time, the time decay rule of complementary and alternative items is taken into account, and the result validates the validity and progressiveness of the Rechorus. SASRec uses the self-attention mechanism to capture the long dependencies between sequences items, and its overall performance is better than that of the GRU4REC, which only built the short-term sequence dependencies.In the comparison model used, Rechorus considers the impact of time on user preference and uses the normal distribution to simulate complementary and alternative relations over time. Tahk also considers the influence of time on user’s preference, improves the self-attention model, and uses neural network to fit the distribution function of the user’s interest changing with time. Compared with Rechorus directly specifying the type of distribution function, the distribution function learned by neural network has stronger robustness and adaptability and can change with different users and different scenes, so the Tahk has the better performance. Rechorus model uses knowledge map to incorporate the association relationship between items, and the experimental results also prove its effectiveness. Drawing on this idea, Tahk takes neighbor user’s information into account in modeling target user’s short-term preference, its effectiveness can be seen through the experimental data, and the more detailed proof is given in the Ablation Experiment.RNN model cannot capture the long-distance sequence dependency because the gradient disappears. Self-attention model establishes the sequence dependency through point-to-point, so as to completely avoid this problem. SASRec directly applies the self-attention mechanism to the user’s click sequence modeling, and compared with traditional model BPR and sequence recommendation model GRU4REC, according to the experimental results, the effectiveness of Self-attention mechanism in sequence modeling is proved. Tahk also uses the self-attention mechanism to establish the relationship between user’s behavior subsequences. At the same time, the time factor is added to improve the weight calculation of Self-attention mechanism. The experimental results show that time self-attention is more effective than SASRec.


## 4.4.2. Common Parameter Experiment

In order to explore the influence of common parameters on each model, we select sequence length and embedding dimension for the experiment. The session length is 10, 20, 30, 40, and 50, which represents the maximum value of sequence length. The embedding dimension is 8, 16, 32, 64, 128, and 256, which represents the embedded dimension of item features. The evaluation index is HR@10 and NDCG@10. The datasets are Electronic, Clothing_Shoes_Jewelry, Grocery_Gourmet_Food, and Movie_Tv. The experimental results are shown in Figures5–7.Figure 5
Results on electronics.Figure 6
Results on clothing_shoes_jewelry.Figure 7
Results on grocery_gourmet_food.GRU4REC, SASRec, Caser, Rechorus, and Tahk are selected for experiments. For each dataset, the performance of Tahk improves steadily with the increase of sequence length, which shows that Tahk can timely capture the changes of user’s interest according to the change of sequence length. In the electronics dataset, the performance of GRU4REC generally decreases with the increase of sequence length, indicating that GRU4REC cannot capture the dependence of long sequences. In the datasets Clothing_Shoes_Jewelry and Grocery_Gourmet_Food, with the increase of sequence length, the performance of each comparison model changes slightly, and the performance of Tahk has been increasing, indicating that Tahk can capture the subtle changes of user’s interest in a long sequence with time.Embedded dimension experiment takes Clothing_Shoes_Jewelry and Growery _Gourmet_Food as the dataset, the evaluation index is still HR@10 and NDCG@10, and the experimental results are shown in Figures8–11. As the embedded dimension increases, the performance of each model rises first and then falls. When the dimension is low, the parameters of each model are less, which limits the learning ability of model to a certain extent. When the dimension is high, the parameters of each model become larger and have stronger learning ability and data fitting ability, but the requirements for memory are also higher, and the training time is significantly longer. For dataset Clothing_Shoes_Jewelry, with the change of embedded dimension, the performance of each model does not change significantly; the reason might be that the dataset is small, resulting in overfitting. For dataset Grocery_Gourmet_Food, the performance of each model changes significantly with the increase of embedded dimensions, the embedded dimension of each model is different, and it must be determined by experiment.Figure 8
Result on clothing_shoes_jewelry.Figure 9
Results on clothing_shoes_jewelry.Figure 10
Results on grocery_gourmet_food.Figure 11
Results on grocery_gourmet_food.


## 4.4.3. Ablation Experiment

In order to explore the impact of each module of Tahk on the overall performance, ablation experiments are carried out on three modules: time attenuation module, long-term preference module, and global dependence module of short-term preference; these three modules are renamed as Module 1, Module 2, and Module 3 respectively. The original Tahk model removes these three modules, respectively, and obtains three comparison models: Tahk (Without Module 1), Tahk (Without Module 2), and Tahk (Without Module 3). The three comparison models remain the same as the original model, including the experimental parameters and training process. Electronics, Clothing_Shoes_Jewelry, Grocery_Gourmet_Food, and Movie_Tv are experiment datasets. To facilitate writing, the four datasets are abbreviated as electronics, clothing, food, and movie. The experimental results are shown in Figures12 and 13.Figure 12
Result on NDCG@10.Figure 13
Result on HR@10.Tahk (Without Module 1): it means that when calculating the long-term preference weight, the time attenuation is not considered, and the corresponding user’s interest incentive function is removed. Others remain the same as the original model Tahk. This experiment purpose is to verify the impact of time attenuation on user’s preferences.Tahk (Without Module 2): it means that the user’s behavior sequence is regarded as a whole sequence. At the same time, the impact of the time attenuation of the item on the user’s preference is not considered. It is equivalent to removing the long-term preference module and Hawkes process module at the same time. This experiment’s purpose is to verify the division of the sequence that is conducive to predicting the user’s behavior.Tahk (Without Module 3): it means that, in short-term interest modeling, the impact of neighbor users on the target users is not considered; that is, the global dependency is not considered. This experiment’s purpose is to verify that the user’s behavior will be affected by other neighbor users.It can be seen from Figures12 and 13 that the original model Tahk has achieved the best performance on each dataset, indicating that each module has a positive effect on model performance. For the Tahk (Without Module 1) model, there is a great performance difference from the original model Tahk on each dataset. The maximum difference is 9.4%, and the minimum difference is 4.06% for HR@10, indicating that considering time attenuation is extremely important to predict user’s preference. That is, it is effective to establish user’s dynamic preference model. Overall, the Tahk (Without Module 3) model has the smallest gap with the original model Tahk on the four datasets, indicating that neighbor users have a certain impact on the behavior of target users, but it is not the most important factor. In terms of experimental performance, the original model Tahk without considering global dependency can be regarded as the Rechorus model. It is worth that the experimental performance of Tahk (Without Module 2) model on four datasets is between the best and the worst, which shows that the long-term preference module is a module that cannot be ignored, ignoring this module will affect the overall performance of the model. It also shows that dividing the user’s behavior sequence is helpful in predicting user’s preference.


## 5. Conclusion

In summary, this paper proposes a dynamic evolution method of user’s preferences based on user’s behavior sequence, which can effectively predict user’s dynamic preference, which is extremely important in the field of recommendation. We make a full comparative experiment using the Amazon dataset. The experimental results show that the method proposed in this paper is superior to the classical recommendation model and static sequence recommendation. In addition, the comparative experiment and ablation experiment are carried out, which fully proved that user’s dynamic preferences are necessary to recommend the item to a user. We solve the problem that the recommendation system cannot adjust the recommendation strategy in real-time according to the changes in users’ preferences and alleviates the data-sparse problem by using the user’s behavior sequences dataset. However, the algorithm in this paper also has some limitations. The incentive function in the user’s long-term interest lacks interpretability; in the research work, we are committed to improving the interpretability of the model, and to exploring better solutions to improve data sparsity [28].



---

*Source: 6101045-2022-07-22.xml*