日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

DeepFM算法

發(fā)布時(shí)間:2023/12/8 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DeepFM算法 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一:背景與特點(diǎn)

之前為了同時(shí)學(xué)習(xí)低階和高階組合特征,提出了?Wide&Deep 模型。它混合了一個(gè)?線性模型(Wide part)?和?Deep 模(Deep part)。這兩部分模型需要不同的輸入,而?Wide part?部分的輸入,依舊?依賴人工特征工程。但是,這些模型普遍都存在兩個(gè)問(wèn)題:

  • 偏向于提取低階或者高階的組合特征。不能同時(shí)提取這兩種類型的特征。
  • 需要專業(yè)的領(lǐng)域知識(shí)來(lái)做特征工程。
  • 于是DeepFM 應(yīng)運(yùn)而生,成功解決了這兩個(gè)問(wèn)題,并做了一些改進(jìn),其優(yōu)點(diǎn)如下:

  • 不需要預(yù)訓(xùn)練 FM 得到隱向量。
  • 不需要人工特征工程。
  • 能同時(shí)學(xué)習(xí)低階和高階的組合特征。
  • FM 模塊和 Deep 模塊共享?Feature Embedding?部分,可以更快的訓(xùn)練,以及更精確的訓(xùn)練學(xué)習(xí)。
  • 二:模型結(jié)構(gòu)

    DeepFM主要做法如下:

  • FM Component + Deep Component。FM 提取低階組合特征,Deep 提取高階組合特征。但是和 Wide&Deep 不同的是,DeepFM 是端到端的訓(xùn)練,不需要人工特征工程。
  • 共享 feature embedding。FM 和 Deep 共享輸入和feature embedding不但使得訓(xùn)練更快,而且使得訓(xùn)練更加準(zhǔn)確。相比之下,Wide&Deep 中,input vector 非常大,里面包含了大量的人工設(shè)計(jì)的 pairwise 組合特征,增加了它的計(jì)算復(fù)雜度。
  • 需要訓(xùn)練的主要有兩部分:

  • input_vector 和 Addition Unit 相連的全連接層,也就是 1 階的 Embedding 矩陣。
  • Sparse Feature 到 Dense Embedding 的 Embedding 矩陣,中間也是全連接的,要訓(xùn)練的是中間的權(quán)重矩陣,這個(gè)權(quán)重矩陣也就是隱向量 Vi。
  • 整體結(jié)構(gòu)圖如下所示:

    由上面網(wǎng)絡(luò)結(jié)構(gòu)圖可以看到,DeepFM 包括 FM和 DNN兩部分,所以模型最終的輸出也由這兩部分組成:

    下面,把結(jié)構(gòu)圖進(jìn)行拆分,分別來(lái)看這兩部分。

    2.1:FM Component

    FM 部分的輸出如下:

    這里需要注意兩點(diǎn):

  • 由于輸入特征one-hot編碼,所以embedding vector也就是輸入層到Dense Embeddings層的權(quán)重。
  • Deep輸入層的神經(jīng)元個(gè)數(shù)是由embedding vector和field_size共同確定,直觀來(lái)說(shuō)就是:神經(jīng)元的個(gè)數(shù)為embedding vector*field_size。
  • FM Component 總結(jié):

  • FM 模塊實(shí)現(xiàn)了對(duì)于 1 階和 2 階組合特征的建模。
  • 無(wú)須預(yù)訓(xùn)練。
  • 沒(méi)有人工特征工程。
  • embedding 矩陣的大小是:特征數(shù)量 * 嵌入維度。然后用一個(gè) index 表示選擇了哪個(gè)特征。
  • 2.2 :Deep Component

    這里DNN的作用是構(gòu)造高階組合特征,網(wǎng)絡(luò)里面黑色的線是全連接層,參數(shù)需要神經(jīng)網(wǎng)絡(luò)去學(xué)習(xí)。且有一個(gè)特點(diǎn):DNN的輸入也是embedding vector。所謂的權(quán)值共享指的就是這里。

    這里假設(shè)α(0)=(e1,e2,...em)表示 embedding層的輸出,那么α(0)作為下一層 DNN隱藏層的輸入,其前饋過(guò)程如下:

    三:總結(jié)

    DeepFM優(yōu)點(diǎn):

  • 沒(méi)有用 FM 去預(yù)訓(xùn)練隱向量 Vi,并用 Vi去初始化神經(jīng)網(wǎng)絡(luò)。(相比之下 FNN 就需要預(yù)訓(xùn)練 FM 來(lái)初始化 DNN)。
  • FM 模塊不是獨(dú)立的,是跟整個(gè)模型一起訓(xùn)練學(xué)習(xí)得到的。(相比之下 Wide&Deep 中的 Wide 和 Deep 部分是沒(méi)有共享的)
  • 不需要特征工程。(相比之下 Wide&Deep 中的 Wide 部分需要特征工程)
  • 訓(xùn)練效率高。(相比 PNN 沒(méi)有那么多參數(shù))
  • 其中最核心的

  • 沒(méi)有預(yù)訓(xùn)練(no pre-training)
  • 共享 Feature Embedding,沒(méi)有特征工程(no feature engineering)
  • 同時(shí)學(xué)習(xí)低階和高階組合特征(capture both low-high-order interaction features)
  • 四:代碼核心部分

    # ---------- first order term ----------self.y_first_order = tf.nn.embedding_lookup(self.weights["feature_bias"], self.feat_index) # None * F * 1self.y_first_order = tf.reduce_sum(tf.multiply(self.y_first_order, feat_value), 2) # None * Fself.y_first_order = tf.nn.dropout(self.y_first_order, self.dropout_keep_fm[0]) # None * F# ---------- second order term ---------------# sum_square partself.summed_features_emb = tf.reduce_sum(self.embeddings, 1) # None * Kself.summed_features_emb_square = tf.square(self.summed_features_emb) # None * K# square_sum partself.squared_features_emb = tf.square(self.embeddings)self.squared_sum_features_emb = tf.reduce_sum(self.squared_features_emb, 1) # None * K# second orderself.y_second_order = 0.5 * tf.subtract(self.summed_features_emb_square,self.squared_sum_features_emb) # None * Kself.y_second_order = tf.nn.dropout(self.y_second_order, self.dropout_keep_fm[1]) # None * K# ---------- Deep component ----------self.y_deep = tf.reshape(self.embeddings, shape=[-1, self.field_size * self.embedding_size]) # None * (F*K)self.y_deep = tf.nn.dropout(self.y_deep, self.dropout_keep_deep[0])for i in range(0, len(self.deep_layers)):self.y_deep = tf.add(tf.matmul(self.y_deep, self.weights["layer_%d" % i]),self.weights["bias_%d" % i]) # None * layer[i] * 1if self.batch_norm:self.y_deep = self.batch_norm_layer(self.y_deep, train_phase=self.train_phase,scope_bn="bn_%d" % i) # None * layer[i] * 1self.y_deep = self.deep_layers_activation(self.y_deep)self.y_deep = tf.nn.dropout(self.y_deep, self.dropout_keep_deep[1 + i]) # dropout at each Deep layer# ---------- DeepFM ----------if self.use_fm and self.use_deep:concat_input = tf.concat([self.y_first_order, self.y_second_order, self.y_deep], axis=1)elif self.use_fm:concat_input = tf.concat([self.y_first_order, self.y_second_order], axis=1)elif self.use_deep:concat_input = self.y_deepself.out = tf.add(tf.matmul(concat_input, self.weights["concat_projection"]), self.weights["concat_bias"],name="output")

    ?

    總結(jié)

    以上是生活随笔為你收集整理的DeepFM算法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。