推薦系統中的注意力機制——阿里深度興趣網絡(DIN)


參考:

https://zhuanlan.zhihu.com/p/51623339

https://arxiv.org/abs/1706.06978

注意力機制顧名思義,就是模型在預測的時候,對用戶不同行為的注意力是不一樣的,“相關”的行為歷史看重一些,“不相關”的歷史甚至可以忽略。那么這樣的思想反應到模型中也是直觀的。

如果按照之前的做法,我們會一碗水端平的考慮所有行為記錄的影響,對應到模型中就是我們會用一個average pooling層把用戶交互過的所有商品的embedding vector平均一下形成這個用戶的user vector,機靈一點的工程師最多加一個time decay,讓最近的行為產生的影響大一些,那就是在做average pooling的時候按時間調整一下權重。

 

上式中, V_u 是用戶的embedding向量, V_a 是候選廣告商品的embedding向量, V_i 是用戶u的第i次行為的embedding向量,因為這里用戶的行為就是瀏覽商品或店鋪,所以行為的embedding的向量就是那次瀏覽的商品或店鋪的embedding向量。

因為加入了注意力機制, V_u 從過去 V_i 的加和變成了 V_i 的加權和, V_i 的權重 w_i 就由 V_i與 V_a 的關系決定,也就是上式中的 g(V_i,V_a) ,不負責任的說,這個 g(V_i,V_a) 的加入就是本文70%的價值所在。 

那么 g(V_i,V_a) 這個函數到底采用什么比較好呢?看完下面的架構圖自然就清楚了。 => 如何生成注意力$g(V_i, V_a)$

相比原來這個標准的深度推薦網絡(Base model),DIN在生成用戶embedding vector的時候加入了一個activation unit層,這一層產生了每個用戶行為 V_i 的權重,下面我們仔細看一下這個權重是怎么生成的,也就是 g(V_i,V_a) 是如何定義的。

傳統的Attention機制中,給定兩個item embedding,比如u和v,通常是直接做點積uv或者uWv,其中W是一個|u|x|v|的權重矩陣,但這篇paper中阿里顯然做了更進一步的改進,着重看上圖右上角的activation unit,首先是把u和v以及u v的element wise差值向量合並起來作為輸入,然后喂給全連接層,最后得出權重,這樣的方法顯然損失的信息更少。但如果你自己想方便的引入attention機制的話,不妨先從點積的方法做起嘗試一下,因為這樣連訓練都不用訓練。

再稍微留意一下這個架構圖中的紅線,你會發現每個ad會有 good_id, shop_id 兩層屬性,shop_id只跟用戶歷史中的shop_id序列發生作用,good_id只跟用戶的good_id序列發生作用,這樣做的原因也是顯而易見的。

論文里面,activation unit結構:

activation units are applied on the user behavior features, which performs as a weighted sum pooling to adaptively calculate user representation $v_U$ given a candidate ad A:

where ${e_1, e_2, ..., e_H }$ is the list of embedding vectors of behaviors of user $U$ with length of H, $v_A$ is the embedding vector of ad A.

 

 

如果說上面的部分是文70%的價值所在,那么余下30%應該還有這么幾點:

    • 用GAUC這個離線metric替代AUC
    • 用Dice方法替代經典的PReLU激活函數
    • 介紹一種Adaptive的正則化方法
    • 介紹阿里的X-Deep Learning深度學習平台

PReLU激活函數:

  其中,$p(s) = I(s > 0)$

Dice方法:

Dice can be viewed as a generalization of PReLu. The key idea of Dice is to adaptively adjust the rectified point according to distribution of input data, whose value is set to be the mean of input. Besides, Dice controls smoothly to switch between the two channels. When $E(s) = 0 $ and  $Var[s] = 0 $, Dice degenerates into PReLU.

GAUC:

因為auc反映的是整體樣本間的一個排序能力,而在計算廣告領域,我們實際要衡量的是不同用戶對不同廣告之間的排序能力, 實際更關注的是同一個用戶對不同廣告間的排序能力。group auc實際是計算每個用戶的auc,然后加權平均,最后得到group auc,這樣就能減少不同用戶間的排序結果不太好比較這一影響

實際處理時權重一般可以設為每個用戶view的次數,或click的次數,而且一般計算時,會過濾掉單個用戶全是正樣本或負樣本的情況。

實現代碼: https://github.com/qiaoguan/deep-ctr-prediction/blob/master/DeepCross/metric.py

 


 

閱讀論文

基線模型: embedding & MLP

$Embedding  Layer: $

For the $i-th$ feature group of $t_i$ ($t_i$ 是 $K_i$ 維向量,可能有一個或多個項是1), let $W_i = [w^i_1 , ...,w^i_j , ...,w^i_{K_i} ] ∈ R^{D×K_i} $ represent the $i-th$ embedding dictionary, where $w^i_j ∈ R^D $ is an embedding vector with dimensionality of D. Embedding operation follows the table lookup mechanism。

embedding機制:

1、If $t_i$ is one-hot vector with $j-th$ element $t_i[j] = 1 $, the embedded representation of $t_i$ is a single embedding vector $e_i = w^i_j $.

2、If $t_i$ is multi-hot vector with $t_i[j] = 1 $ for  $j ∈ {i_1, i_2, ...,i_k }$, the embedded representation of $t_i$ is a list of embedding vectors: ${e_{i_1} , e_{i_2} , ...e_{i_k} } = {w^i_{i1} ,w^i_{i2} , ...w^i_{ik} }$. 

$Pooling layer and Concat layer: $ 

The number of non-zero values for multi-hot behavioral feature vector $t_i$ varies across instances, causing the lengths of the corresponding list of embedding vectors to be variable. As fully connected networks can only handle fixed-length inputs, it is a common practice to transform the list of embedding vectors via a pooling layer to get a fixed-length vector:

$e_i = pooling(e_{i_1} , e_{i_2}, ...e{i_k} )$

Both embedding and pooling layers operate in a group-wise manner, mapping the original sparse features into multiple fixedlength representation vectors. Then all the vectors are concatenated together to obtain the overall representation vector for the instance 

$MLP:$

Given the concatenated dense representation vector, fully connected layers are used to learn the combination of features automatically. Recently developed methods  focus on designing structures of MLP for better information extraction.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM