MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / prediction

Method prediction

modelzoo/features/runtime/deepfm/train.py:174–222  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

172 return dnn_input
173
174 def prediction(self):
175 # input features
176 with tf.variable_scope('input_layer',
177 partitioner=self.input_layer_partitioner,
178 reuse=tf.AUTO_REUSE):
179
180 fm_cols = {}
181 wide_input = tf.feature_column.input_layer(
182 self.feature, self.wide_column, cols_to_output_tensors=fm_cols)
183 fm_input = tf.stack([fm_cols[cols] for cols in self.fm_column], 1)
184 dnn_input = tf.feature_column.input_layer(self.feature,
185 self.deep_column)
186
187 if self.bf16:
188 wide_input = tf.cast(wide_input, dtype=tf.bfloat16)
189 fm_input = tf.cast(fm_input, dtype=tf.bfloat16)
190 dnn_input = tf.cast(dnn_input, dtype=tf.bfloat16)
191
192 # DNN part
193 dnn_scope = tf.variable_scope('dnn')
194 with dnn_scope.keep_weights(dtype=tf.float32) if self.bf16 \
195 else dnn_scope:
196 dnn_output = self.dnn(dnn_input, self.dnn_hidden_units,
197 'dnn_layer')
198
199 # linear / fisrt order part
200 with tf.variable_scope('linear', reuse=tf.AUTO_REUSE) as linear:
201 linear_output = tf.reduce_sum(wide_input, axis=1, keepdims=True)
202
203 # FM second order part
204 with tf.variable_scope('fm', reuse=tf.AUTO_REUSE) as fm:
205 sum_square = tf.square(tf.reduce_sum(fm_input, axis=1))
206 square_sum = tf.reduce_sum(tf.square(fm_input), axis=1)
207 fm_output = 0.5 * tf.subtract(sum_square, square_sum)
208
209 # Final dnn layer
210 all_input = tf.concat([dnn_output, linear_output, fm_output], 1)
211 final_dnn_scope = tf.variable_scope('final_dnn')
212 with final_dnn_scope.keep_weights(dtype=tf.float32) if self.bf16 \
213 else final_dnn_scope:
214 net = self.dnn(all_input, self.final_hidden_units, 'final_dnn')
215
216 if self.bf16:
217 net = tf.cast(net, dtype=tf.float32)
218
219 net = tf.layers.dense(net, units=1)
220 net = tf.math.sigmoid(net)
221
222 return net
223
224 def optimizer(self):
225 loss_func = tf.losses.mean_squared_error

Callers 1

__init__Method · 0.95

Calls 8

dnnMethod · 0.95
variable_scopeMethod · 0.80
keep_weightsMethod · 0.80
reduce_sumMethod · 0.80
stackMethod · 0.45
castMethod · 0.45
squareMethod · 0.45
concatMethod · 0.45

Tested by

no test coverage detected