hi我是小明哥,年少不知小明帥,為約妹子強說愁,哈哈,言歸正傳,每個新模型出來不到兩個月,甚至不到一個月,就有人參考你的文章(你以為別人參考很開心,其實是人家為了踩你啊)馬上與你的結果對比,效果就是比你的好,這種正常的競爭/競賽我覺得很好,公平公正公開,不開源的就算了,誰知道有沒有實作paper中宣稱的結果,這種都是不足為信的,
總體來說,DGCF是CF協同過濾的大范疇之內的,當然要與最佳的模型對比了,目前來看最優的是GCN(LightGCN),這種方法如果維度小點能夠達到相當不錯的效果就好了,當資料量大時,比如百萬用戶,千萬點擊,這個模型引數必須減少(embedding size和n_layers),不然GPU/記憶體不夠,又想模型好,又想覆寫全面,我說你是不是想多了,這種好事怕很難遇見吧(找物件不也是如此),另外這個DGCF也是GNN方法的應用,與GCN方法是類似的(不同之處下次再說),而用到GNN的序列模型目前最好的是GCE-GNN,這個方法目前沒有官方開源,第三方的codes笨菜鳥(就是我)還沒實作(挺難的),很多開源的新方法其實很難實際應用,1是資料量問題(空間記憶體都是問題),2是速度/時間問題,根本跑不起來,這方面的問題都很突出,一味地增加embedding size等引數使得效果變好會導致前面兩個問題相當嚴重,結果只能退而求其次,降低后發現與舊方法效果沒啥差別,哎,這就是一江煙雨許多愁了,
本大佬準備搞定這個模型今年就收官了,將精力放在調優之上,比如youtube怎么可能放棄呢?比如是不是可以覆寫全部的用戶,就算降低了維度,單個用戶CTR變少了,總體的會不會出現變大的情況?(會不會有這種好的幺蛾子?哈哈),是不是可以將訓練的embedding保留下次還用,直到有更新?當然我依舊會選擇在這里同諸位大佬分享我的生活(對,作業生活都接觸才能了解一個人),不管前路如何,而我已然在這里等你訊息,當然你也可以群里暢談人生理想,聊聊生活的瑣事與煩惱,小明哥將始終陪伴你左右,不離不棄,
For Video Recommendation in Deep learning QQ Group 277356808
For Visual in deep learning QQ Group 629530787
I'm here waiting for you
別加那么多,沒必要,另外,不接受這個網頁的私聊/私信!!!
1-資料構建
一般來說CF是不講究啥點擊時間順序的,所以在召回評價時用留一法是不對的,效果肯定比不上序列模型,先看訓練集與測驗集:
0 10 5 16 17 9 0 15 14 3 6 11 13 12
1 22 27 19 39 20 48 36 29 44 23 46 26 47 33 40 25 34 38 31 24 30 41 49 37
2 51 53 1 63 62 58 61 56 57 55
3 1 80 83 77 68 67 64 72 69 66 73 76 70 82 74
4 87 94 86 96 90 92 85 5 88 91 9 95
5 106 105 100 22 17 104 56 99 101 41
6 25 138 117 75 133 118 110 112 121 136 113 108 124 115 122 72 99 130 127 100 111 137 135 116 73 139 125 120 27 119 107
7 103 140 145 141 146 8 37 125 14 144 142 73
8 235 11 127 158 42 167 234 248 190 54 195 212 92 77 147 178 200 216 257 255 218 232 162 166 12 201 256 211 36 142 123 204 196 174 189 183 247 14 242 159 3 168 46 58 170 206 228 176 160 197 243 233 154 231 171 237 215 225 43 156 210 161 236 182 227 149 209 251 245 180 157 191 163 186 229 73 13 177 4 254 238 193 258 57 188 5 39 98 94 198 148 222 169 199 249 35 214 223 246 219 244 18 259 252
9 47 262 267 265 264 3 78 261 220 212 202 266 57 46 110 37 263 82 69
測驗集也是類似的,前面是user_id后面時item_id
0 1 8 2 4
1 28 50 21 35 32 0 45
2 60 59 24
3 65 81 75 79
4 98 97 93
5 36 102 73
6 105 129 114 131 132 123 128 109 126
7 13 47 143
8 165 132 253 208 221 203 240 51 187 119 230 175 155 172 220 151 28 152 226 184 143 192 164 96 179 224 48 217 202 153
9 135 48 6 142 121
user和item也都有對應編碼,至于驗證集在實際中沒必要,將越多的資料用于訓練不好嗎?省點時間做召回不好嗎?要啥驗證集
org_id remap_id
1 0
2 1
3 2
5 3
6 4
7 5
8 6
9 7
10 8
org_id remap_id
1193 0
2355 1
1287 2
2804 3
595 4
1035 5
3105 6
1270 7
527 8
以上就是基本的資料,只要自己可以構建,即可開工,沒必要一點不改照搬作者的代碼,會改別人的代碼才是看懂了代碼流程,
2-關于資料的輸入代碼,這部分與LightGCN代碼中是一樣的
【看著人家來公司帶娃我還是五味雜陳(捂臉),假若,,,該多好,人生的意義我啥時候才能參透呢?上帝的安排到底是什么啊?】
【昨天實在太困了,就回去了,洗衣服,和我媽打電話,無論開始是什么話題,最后結束的一定是"趕緊找物件啊",我也挺急的,但我似乎并不需要,不著急,慢慢來,還年輕,過年就又長了一歲,還不到30,還早,先搞好作業,做好作業,作業成就我,歡迎持續關注,歡迎吃瓜】
不同之處如下:(如果關于稀疏矩陣的處理整不好,就會出現記憶體爆炸,這部分直接限制了實際應用)
def get_adj_mat(self, low=0.00006, high=1.0):
## try:
t1 = time.time()
adj_mat, norm_adj_mat, norm_adj_mat_noeye, band_cross_adj_mat = self.create_adj_mat(low=low, high=high)
print('already load adj matrix', adj_mat.shape, time.time() - t1)
## except Exception as error:
## print(error)
## return
return adj_mat, norm_adj_mat, norm_adj_mat_noeye, band_cross_adj_mat
def create_adj_mat(self, low=0.0075, high=0.02):
t1 = time.time()
adj_mat = sp.dok_matrix((self.n_users + self.n_items, self.n_users + self.n_items), dtype=np.float32)
adj_mat = adj_mat.tolil()
R = self.R.tolil()
# prevent memory from overflowing
'''
for i in range(5):
adj_mat[int(self.n_users*i/5.0):int(self.n_users*(i+1.0)/5), self.n_users:] =\
R[int(self.n_users*i/5.0):int(self.n_users*(i+1.0)/5)]
adj_mat[self.n_users:,int(self.n_users*i/5.0):int(self.n_users*(i+1.0)/5)] =\
R[int(self.n_users*i/5.0):int(self.n_users*(i+1.0)/5)].T
'''
adj_mat[:self.n_users, self.n_users:] = R
adj_mat[self.n_users:, :self.n_users] = R.T
adj_mat = adj_mat.todok()
print('already create adjacency matrix', adj_mat.shape, time.time() - t1)
t2 = time.time()
def normalized_adj_single(adj):
rowsum = np.array(adj.sum(1))
d_inv = np.power(rowsum, -1).flatten()
d_inv[np.isinf(d_inv)] = 0.
d_mat_inv = sp.diags(d_inv)
norm_adj = d_mat_inv.dot(adj)
print('generate single-normalized adjacency matrix.')
return norm_adj.tocoo()
def normalized_adj_laplacian(adj):
rowsum = np.array(adj.sum(1))
d_inv = np.power(rowsum, -0.5).flatten()
d_inv[np.isinf(d_inv)] = 0.
d_mat_inv = sp.diags(d_inv)
row_norm_adj = d_mat_inv.dot(adj)
norm_adj = row_norm_adj.dot(d_mat_inv)
print('generate laplacian-normalized adjacency matrix.')
return norm_adj.tocoo()
def band_cross_hop_laplacian(adj, low_pass=0.0025, high_stop=1):
cross_adj = adj.dot(adj)
# cross_adj.data = np.where(cross_adj.data>filter_numer, cross_adj.data, 0.)
rowsum = np.array(cross_adj.sum(1))
d_inv = np.power(rowsum, -1/2).flatten()
d_inv[np.isinf(d_inv)] = 0.
d_mat_inv = sp.diags(d_inv)
row_norm_adj = d_mat_inv.dot(cross_adj)
norm_adj = row_norm_adj.dot(d_mat_inv)
norm_adj.data[np.isinf(norm_adj.data)] = 0.
norm_adj.data = np.where(norm_adj.data>low_pass, norm_adj.data, 0.)
norm_adj.data = np.where(norm_adj.data<high_stop, norm_adj.data, 0.)
norm_adj.eliminate_zeros()
print('generate filtered laplacian-normalized cross-hop adjacency matrix.')
return norm_adj.tocoo()
def check_adj_if_equal(adj):
dense_A = np.array(adj.todense())
degree = np.sum(dense_A, axis=1, keepdims=False)
temp = np.dot(np.diag(np.power(degree, -1)), dense_A)
print('check normalized adjacency matrix whether equal to this laplacian matrix.')
return temp
'''
norm_adj_mat = normalized_adj_single(adj_mat + sp.eye(adj_mat.shape[0]))
mean_adj_mat = normalized_adj_single(adj_mat)
'''
laplacian_adj_mat = normalized_adj_laplacian(adj_mat + sp.eye(adj_mat.shape[0]))
laplacian_adj_mat_noeye = normalized_adj_laplacian(adj_mat)
cross_adj_mat = band_cross_hop_laplacian(adj_mat, low_pass=low, high_stop=high)
print('already normalize adjacency matrix', time.time() - t2)
#return adj_mat.tocsr(), norm_adj_mat.tocsr(), mean_adj_mat.tocsr()
return adj_mat.tocsr(), laplacian_adj_mat.tocsr(), laplacian_adj_mat_noeye.tocsr(), cross_adj_mat.tocsr()
其中注釋的部分是LightGCN的部分代碼,其他則相同,但這部分在資料量大時問題相當突出,詳見我的issue,當然代碼地址也順便告訴你了,
其他部分其實都差不多,比如BPR loss,這部分是一樣的,
3-infer部分
模型訓練好的結果依舊是user和item的embedding,得到這個后直接采用faiss召回即可,關于其指標評價可參考我的博文,HR,MAP,MRR,NDCG等等
堅持吧,小明哥,
一片春愁待酒澆,江上舟搖,樓上簾招,
秋娘渡與泰娘橋,風又飄飄,雨又瀟瀟,
【20201122-20:32補充】
我看了下提及的那個DGCF——這個是7月份的SIGIR的,沒有與LightGCN對比,而我這個博文的是11月份的,有與LightGCN對比,當然這種東西,你是DGCF,我也是DGCF,你是小明哥,我也是小明哥,只不過全稱不同,
回家睡覺,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/226622.html
標籤:AI
