简单来说,Wide 部分的主要作用是让模型具有较强的“记忆能力”(Memorization),而 Deep 部分的主要作用是让模型具有“泛化能力”(Generalization),因为只有这样的结构特点,才能让模型兼具逻辑回归和深度神经网络的优点,也就是既能快速处理和记忆大量历史行为特征,又具有强大的表达能力,这就是 Google 提出这个模型的动机。

模型的记忆能力

所谓的 “记忆能力”,可以被宽泛地理解为模型直接学习历史数据中物品或者特征的“共现频率”,并且把它们直接作为推荐依据的能力

模型的泛化能力

“泛化能力”指的是模型对于新鲜样本、以及从未出现过的特征组合的预测能力。


Wide&Deep 模型的应用场景

Wide&Deep 模型的 TensorFlow 实现

继续使用 TensorFlow 的 Keras 接口来构建 Wide&Deep 模型

# wide and deep model architecture

# deep part for all input features

deep = tf.keras.layers.DenseFeatures(numerical_columns + categorical_columns)(inputs)

deep = tf.keras.layers.Dense(128, activation='relu')(deep)

deep = tf.keras.layers.Dense(128, activation='relu')(deep)

# wide part for cross feature

wide = tf.keras.layers.DenseFeatures(crossed_feature)(inputs)

both = tf.keras.layers.concatenate([deep, wide])

output_layer = tf.keras.layers.Dense(1, activation='sigmoid')(both)

model = tf.keras.Model(inputs, output_layer)



在生成 crossed_feature 的过程中,我其实仿照了 Google Play 的应用方式,生成了一个由“用户已好评电影”和“当前评价电影”组成的一个交叉特征

movie_feature = tf.feature_column.categorical_column_with_identity(key='movieId', num_buckets=1001)

rated_movie_feature = tf.feature_column.categorical_column_with_identity(key='userRatedMovie1', num_buckets=1001)

crossed_feature = tf.feature_column.crossed_column([movie_feature, rated_movie_feature], 10000)

在 Deep 部分和 Wide 部分都构建完后,我们要使用 concatenate layer 把两部分连接起来,形成一个完整的特征向量,输入到最终的 sigmoid 神经元中,产生推荐分数

  • 无标签