(self)
| 169 | return dnn_input |
| 170 | |
| 171 | def prediction(self): |
| 172 | # input features |
| 173 | with tf.variable_scope('input_layer', |
| 174 | partitioner=self.input_layer_partitioner, |
| 175 | reuse=tf.AUTO_REUSE): |
| 176 | |
| 177 | fm_cols = {} |
| 178 | wide_input = tf.feature_column.input_layer( |
| 179 | self.feature, self.wide_column, cols_to_output_tensors=fm_cols) |
| 180 | fm_input = tf.stack([fm_cols[cols] for cols in self.fm_column], 1) |
| 181 | dnn_input = tf.feature_column.input_layer(self.feature, |
| 182 | self.deep_column) |
| 183 | |
| 184 | if self.bf16: |
| 185 | wide_input = tf.cast(wide_input, dtype=tf.bfloat16) |
| 186 | fm_input = tf.cast(fm_input, dtype=tf.bfloat16) |
| 187 | dnn_input = tf.cast(dnn_input, dtype=tf.bfloat16) |
| 188 | |
| 189 | # DNN part |
| 190 | if self.bf16: |
| 191 | with tf.variable_scope('dnn').keep_weights(): |
| 192 | dnn_output = self.dnn(dnn_input, self.dnn_hidden_units, |
| 193 | 'dnn_layer') |
| 194 | else: |
| 195 | with tf.variable_scope('dnn'): |
| 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 | if self.bf16: |
| 212 | with tf.variable_scope('final_dnn').keep_weights(): |
| 213 | net = self.dnn(all_input, self.final_hidden_units, 'final_dnn') |
| 214 | net = tf.cast(net, dtype=tf.float32) |
| 215 | else: |
| 216 | with tf.variable_scope('final_dnn'): |
| 217 | net = self.dnn(all_input, self.final_hidden_units, 'final_dnn') |
| 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 |
no test coverage detected