(self)
| 159 | |
| 160 | # create model |
| 161 | def _create_model(self): |
| 162 | # Dnn part |
| 163 | with tf.variable_scope('dnn'): |
| 164 | # input layer |
| 165 | with tf.variable_scope('input_from_feature_columns', |
| 166 | partitioner=self._input_layer_partitioner, |
| 167 | reuse=tf.AUTO_REUSE): |
| 168 | if self._adaptive_emb and not self.tf: |
| 169 | '''Adaptive Embedding Feature Part 1 of 2''' |
| 170 | adaptive_mask_tensors = {} |
| 171 | for col in CATEGORICAL_COLUMNS: |
| 172 | adaptive_mask_tensors[col] = tf.ones([args.batch_size], |
| 173 | tf.int32) |
| 174 | net = tf.feature_column.input_layer( |
| 175 | features=self._feature, |
| 176 | feature_columns=self._deep_column, |
| 177 | adaptive_mask_tensors=adaptive_mask_tensors) |
| 178 | else: |
| 179 | net = tf.feature_column.input_layer( |
| 180 | features=self._feature, |
| 181 | feature_columns=self._deep_column) |
| 182 | self._add_layer_summary(net, 'input_from_feature_columns') |
| 183 | |
| 184 | # hidden layers |
| 185 | dnn_scope = tf.variable_scope('dnn_layers', \ |
| 186 | partitioner=self._dense_layer_partitioner, reuse=tf.AUTO_REUSE) |
| 187 | with dnn_scope.keep_weights(dtype=tf.float32) if self.bf16 \ |
| 188 | else dnn_scope: |
| 189 | if self.bf16: |
| 190 | net = tf.cast(net, dtype=tf.bfloat16) |
| 191 | |
| 192 | net = self._dnn(net, self._dnn_hidden_units, 'hiddenlayer') |
| 193 | |
| 194 | if self.bf16: |
| 195 | net = tf.cast(net, dtype=tf.float32) |
| 196 | |
| 197 | # dnn logits |
| 198 | logits_scope = tf.variable_scope('logits') |
| 199 | with logits_scope.keep_weights(dtype=tf.float32) if self.bf16 \ |
| 200 | else logits_scope as dnn_logits_scope: |
| 201 | dnn_logits = tf.layers.dense(net, |
| 202 | units=1, |
| 203 | activation=None, |
| 204 | name=dnn_logits_scope) |
| 205 | self._add_layer_summary(dnn_logits, dnn_logits_scope.name) |
| 206 | |
| 207 | # linear part |
| 208 | with tf.variable_scope( |
| 209 | 'linear', partitioner=self._dense_layer_partitioner) as scope: |
| 210 | if args.tf or not args.emb_fusion: |
| 211 | linear_logits = tf.feature_column.linear_model( |
| 212 | units=1, |
| 213 | features=self._feature, |
| 214 | feature_columns=self._wide_column, |
| 215 | sparse_combiner='sum', |
| 216 | weight_collections=None, |
| 217 | trainable=True) |
| 218 | else: |
no test coverage detected