飞道的博客

Multi-Interest Network with Dynamic Routing forRecommendation at Tmall 论文阅读笔记

257人阅读  评论(0)

1. ABSTRACT

1.1 Industrial recommender systems

        (1)工业推荐系统通常由匹配阶段和排名阶段组成;

        (2)匹配阶段:检索与用户兴趣相关的候选项;

        (3)排名阶段:根据用户兴趣对候选项进行排序。

Industrial recommender systems usually consist of the matching stage and the ranking stage, in order to handle the billion-scale of users and items. The matching stage retrieves candidate items relevant to user interests, while the ranking stage sorts candidate items by user interests. 

1.2  deep learning-based models(shortage

        大多数现有的基于深度学习的模型将一个用户表示为一个单一的向量,这不足以捕获用户兴趣的不同性质。

Most of the existing deep learning-based models represent one user as a single vector which is insufficient to capture the varying nature of user’s interests.

1.3 The paper was presented

        (1)提出了动态路由多兴趣网络(MIND),以处理用户在匹配阶段的不同兴趣 ;

        (2)开发了一种名为标签感知注意的技术来帮助学习具有多个向量的用户表示。

We propose the Multi-Interest Network with Dynamic routing (MIND) for dealing with user’s diverse interests in the matching stage.
we develop a technique named label-aware attention to help learn a user representation with multiple vectors.

1.4 deployed

        MIND已经部署在移动天猫应用程序主页上的主要在线流量。

Currently, MIND has been deployed for handling major online traffic at the homepage on Mobile Tmall App.

2. INTRODUCTION

2.1 Tmall's personalized recommendation system(RS)

        匹配阶段和排名阶段中建模用户兴趣和找到捕获用户兴趣的用户表示是至关重要的,以支持满足用户兴趣的项目的有效检索。

2.2 Major contributions to the paper

        (1)设计了一个多兴趣提取层

        (2)建立了一个用于个性化推荐任务的深度神经网络。

        (3)构建了一个系统来实现数据收集、模型培训和在线服务的the whole pipeline

To capture diverse interests of users from user behaviors, we design the multi-interest extractor layer, which utilizes dynamic routing to adaptively aggregate user’s historical
behaviors into user representation vectors.
By using user representation vectors produced by the multi-interest extractor layer and a newly proposed label-aware attention layer, we build a deep neural network for personalized recommendation tasks. Compared with existing methods, MIND shows superior performance on several public datasets and one industrial dataset from Tmall.
To deploy MIND for serving billion-scale users at Tmall, we construct a system to implement the whole pipeline for data collecting, model training and online serving. The deployed system significantly improves the click-through rate (CTR) of the homepage on Mobile Tmall App.

3. RELATED WORK

3.1 Deep Learning for Recommendation

        (1)Neural Collaborative Filtering (NCF);

        (2)DeepFM;

        (3)Deep Matrix Factorization Models (DMF);

        (4)Personalized top-n sequential recommendation via convolutional sequence embedding;

3.2 User Representation

        (1)employs RNN-GRU to learn user embeddings from the temporal ordered review documents;

        (2)Modelling Context with User Embeddings for Sarcasm Detection in Social Media。

3.3 Capsule Network

        采用动态路由来学习胶囊之间的连接的权重,并利用期望最大化算法进行了改进,克服了一些缺陷,获得了更好的精度。

4. Paper core method

 

4.1 Problem Formalization

       (1) 函数:

        其中:,d表示Userd的embedding向量的维度,K代表预测的用户兴趣个数

        (2)函数

        其中,表示每个item的embeding向量表征

     

        (3)函数

4.2 Embedding & Pooling Layer

     输入由三部分组成,过Embedding层之后获得了三个Embedding向量,所以通过pooling层将其变成单一的Embedding向量

4.3 Multi-Interest Extractor Layer

        参考了胶囊网络中的动态路由的方法

4.3.1 B2I Dynamic Routing算法流程

4.3.2 流程主要公式

         (1)用户兴趣向量:

        (2)系数使用高斯分布进行初始化

        (3)循环中的公式: 

        注意是一个可学习参数, S相当于是对User的行为胶囊和兴趣胶囊进行信息交互融合的一个权重。 

      

4.4 Label-aware Attention Layer

        就类似于我们给项目加入权重

        其中p值取的情况如下表:

p 对应情况
0 每个用户兴趣向量有相同的权重
>0 p越大,与目标商品向量点积更大的用户兴趣向量会有更大的权重
只使用与目标商品向量点积最大的用户兴趣向量,忽略其他用户向量

       :论文得出当p趋于无穷大的时候模型的训练效果是最好的。

4.5 Training & Serving

4.5.1 Training

        其中表示用户向量,表示标签项目嵌入 

        D是包含用户项的训练数据的集合

4.5.2 Serving

        在服务时,用户的行为序列和用户配置文件被输入到fuser函数中,为每个用户生成多个表示向量。然后,利用这些表示向量通过近似最近邻方法检索前N个项。

4.6 Connections with Existing Methods

        YouTube DNN. Both MIND and YouTube DNN

5. EXPERIMENTS

5.1 Datasets

5.2 the main metric

  denotes the test set consisting of pairs of users and   target items ( u , i )
 denotes the indicator function

6. The MIND model definition

        基于paddle的MIND模型定义(飞桨AI Studio - 人工智能学习实训社区 (baidu.com))。


  
  1. class CapsuleNetwork(nn.Layer):
  2. def __init__( self, hidden_size, seq_len, bilinear_type=2, interest_num=4, routing_times=3, hard_readout=True,
  3. relu_layer=False):
  4. super(CapsuleNetwork, self).__init__()
  5. self.hidden_size = hidden_size # h
  6. self.seq_len = seq_len # s
  7. self.bilinear_type = bilinear_type
  8. self.interest_num = interest_num
  9. self.routing_times = routing_times
  10. self.hard_readout = hard_readout
  11. self.relu_layer = relu_layer
  12. self.stop_grad = True
  13. self.relu = nn.Sequential(
  14. nn.Linear(self.hidden_size, self.hidden_size, bias_attr= False),
  15. nn.ReLU()
  16. )
  17. if self.bilinear_type == 0: # MIND
  18. self.linear = nn.Linear(self.hidden_size, self.hidden_size, bias_attr= False)
  19. elif self.bilinear_type == 1:
  20. self.linear = nn.Linear(self.hidden_size, self.hidden_size * self.interest_num, bias_attr= False)
  21. else: # ComiRec_DR
  22. self.w = self.create_parameter(
  23. shape=[ 1, self.seq_len, self.interest_num * self.hidden_size, self.hidden_size])
  24. def forward( self, item_eb, mask):
  25. if self.bilinear_type == 0: # MIND
  26. item_eb_hat = self.linear(item_eb) # [b, s, h]
  27. item_eb_hat = paddle.repeat_interleave(item_eb_hat, self.interest_num, 2) # [b, s, h*in]
  28. elif self.bilinear_type == 1:
  29. item_eb_hat = self.linear(item_eb)
  30. else: # ComiRec_DR
  31. u = paddle.unsqueeze(item_eb, 2) # shape=(batch_size, maxlen, 1, embedding_dim)
  32. item_eb_hat = paddle. sum(self.w[:, :self.seq_len, :, :] * u,
  33. 3) # shape=(batch_size, maxlen, hidden_size*interest_num)
  34. item_eb_hat = paddle.reshape(item_eb_hat, (- 1, self.seq_len, self.interest_num, self.hidden_size))
  35. item_eb_hat = paddle.transpose(item_eb_hat, perm=[ 0, 2, 1, 3])
  36. # item_eb_hat = paddle.reshape(item_eb_hat, (-1, self.interest_num, self.seq_len, self.hidden_size))
  37. # [b, in, s, h]
  38. if self.stop_grad: # 截断反向传播,item_emb_hat不计入梯度计算中
  39. item_eb_hat_iter = item_eb_hat.detach()
  40. else:
  41. item_eb_hat_iter = item_eb_hat
  42. # b的shape=(b, in, s)
  43. if self.bilinear_type > 0: # b初始化为0(一般的胶囊网络算法)
  44. capsule_weight = paddle.zeros((item_eb_hat.shape[ 0], self.interest_num, self.seq_len))
  45. else: # MIND使用高斯分布随机初始化b
  46. capsule_weight = paddle.randn((item_eb_hat.shape[ 0], self.interest_num, self.seq_len))
  47. for i in range(self.routing_times): # 动态路由传播3次
  48. atten_mask = paddle.repeat_interleave(paddle.unsqueeze(mask, 1), self.interest_num, 1) # [b, in, s]
  49. paddings = paddle.zeros_like(atten_mask)
  50. # 计算c,进行mask,最后shape=[b, in, 1, s]
  51. capsule_softmax_weight = F.softmax(capsule_weight, axis=- 1)
  52. capsule_softmax_weight = paddle.where(atten_mask== 0, paddings, capsule_softmax_weight) # mask
  53. capsule_softmax_weight = paddle.unsqueeze(capsule_softmax_weight, 2)
  54. if i < 2:
  55. # s=c*u_hat , (batch_size, interest_num, 1, seq_len) * (batch_size, interest_num, seq_len, hidden_size)
  56. interest_capsule = paddle.matmul(capsule_softmax_weight,
  57. item_eb_hat_iter) # shape=(batch_size, interest_num, 1, hidden_size)
  58. cap_norm = paddle. sum(paddle.square(interest_capsule), - 1, keepdim= True) # shape=(batch_size, interest_num, 1, 1)
  59. scalar_factor = cap_norm / ( 1 + cap_norm) / paddle.sqrt(cap_norm + 1e-9) # shape同上
  60. interest_capsule = scalar_factor * interest_capsule # squash(s)->v,shape=(batch_size, interest_num, 1, hidden_size)
  61. # 更新b
  62. delta_weight = paddle.matmul(item_eb_hat_iter, # shape=(batch_size, interest_num, seq_len, hidden_size)
  63. paddle.transpose(interest_capsule, perm=[ 0, 1, 3, 2])
  64. # shape=(batch_size, interest_num, hidden_size, 1)
  65. ) # u_hat*v, shape=(batch_size, interest_num, seq_len, 1)
  66. delta_weight = paddle.reshape(delta_weight, (
  67. - 1, self.interest_num, self.seq_len)) # shape=(batch_size, interest_num, seq_len)
  68. capsule_weight = capsule_weight + delta_weight # 更新b
  69. else:
  70. interest_capsule = paddle.matmul(capsule_softmax_weight, item_eb_hat)
  71. cap_norm = paddle. sum(paddle.square(interest_capsule), - 1, keepdim= True)
  72. scalar_factor = cap_norm / ( 1 + cap_norm) / paddle.sqrt(cap_norm + 1e-9)
  73. interest_capsule = scalar_factor * interest_capsule
  74. interest_capsule = paddle.reshape(interest_capsule, (- 1, self.interest_num, self.hidden_size))
  75. if self.relu_layer: # MIND模型使用book数据库时,使用relu_layer
  76. interest_capsule = self.relu(interest_capsule)
  77. return interest_capsule

  
  1. class MIND(nn.Layer):
  2. def __init__( self, config):
  3. super(MIND, self).__init__()
  4. self.config = config
  5. self.embedding_dim = self.config[ 'embedding_dim']
  6. self.max_length = self.config[ 'max_length']
  7. self.n_items = self.config[ 'n_items']
  8. self.item_emb = nn.Embedding(self.n_items, self.embedding_dim, padding_idx= 0)
  9. self.capsule = CapsuleNetwork(self.embedding_dim, self.max_length, bilinear_type= 0,
  10. interest_num=self.config[ 'K'])
  11. self.loss_fun = nn.CrossEntropyLoss()
  12. self.reset_parameters()
  13. def calculate_loss( self,user_emb,pos_item):
  14. all_items = self.item_emb.weight
  15. scores = paddle.matmul(user_emb, all_items.transpose([ 1, 0]))
  16. return self.loss_fun(scores,pos_item)
  17. def output_items( self):
  18. return self.item_emb.weight
  19. def reset_parameters( self, initializer=None):
  20. for weight in self.parameters():
  21. paddle.nn.initializer.KaimingNormal(weight)
  22. def forward( self, item_seq, mask, item, train=True):
  23. if train:
  24. seq_emb = self.item_emb(item_seq) # Batch,Seq,Emb
  25. item_e = self.item_emb(item).squeeze( 1)
  26. multi_interest_emb = self.capsule(seq_emb, mask) # Batch,K,Emb
  27. cos_res = paddle.bmm(multi_interest_emb, item_e.squeeze( 1).unsqueeze(- 1))
  28. k_index = paddle.argmax(cos_res, axis= 1)
  29. best_interest_emb = paddle.rand((multi_interest_emb.shape[ 0], multi_interest_emb.shape[ 2]))
  30. for k in range(multi_interest_emb.shape[ 0]):
  31. best_interest_emb[k, :] = multi_interest_emb[k, k_index[k], :]
  32. loss = self.calculate_loss(best_interest_emb,item)
  33. output_dict = {
  34. 'user_emb': multi_interest_emb,
  35. 'loss': loss,
  36. }
  37. else:
  38. seq_emb = self.item_emb(item_seq) # Batch,Seq,Emb
  39. multi_interest_emb = self.capsule(seq_emb, mask) # Batch,K,Emb
  40. output_dict = {
  41. 'user_emb': multi_interest_emb,
  42. }
  43. return output_dict

 参考:Multi-Interest Network with Dynamic Routing forRecommendation at Tmall

            飞桨AI Studio - 人工智能学习与实训社区 (baidu.com)


转载:https://blog.csdn.net/qq_51167531/article/details/128054481
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场