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

Method _create_model

modelzoo/ple/train.py:251–308  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

249
250 # create model
251 def _create_model(self):
252 TAG_COLUMN = ['tag_category_list', 'tag_brand_list']
253 for key in TAG_COLUMN:
254 self._feature[key] = tf.strings.split(self._feature[key], '|')
255
256 key_dict = {}
257 with self._make_scope('input_layer', self._bf16, self._input_layer_partitioner):
258 print('Adaptive emb = ', self._adaptive_emb, 'TF = ', self.tf)
259 if self._adaptive_emb and not self.tf:
260 '''Adaptive Embedding Feature part 1 of 2'''
261 print('Adaptive Embedding Feature part 1 of 2')
262 adaptive_mask_tensors = {}
263 for col in HASH_INPUTS:
264 adaptive_mask_tensors[col] = tf.ones([args.batch_size],
265 tf.int32)
266 input_emb = tf.feature_column.input_layer(
267 self._feature,
268 self._feature_column,
269 adaptive_mask_tensors=adaptive_mask_tensors,
270 cols_to_output_tensors=key_dict)
271 else:
272 input_emb = tf.feature_column.input_layer(
273 self._feature,
274 self._feature_column,
275 cols_to_output_tensors=key_dict)
276
277 with self._make_scope('PLE', self._bf16, self._dense_layer_partitioner):
278 if self._bf16:
279 input_emb = tf.cast(input_emb, dtype=tf.bfloat16)
280 ple_inputs = [input_emb] * (self._num_tasks + 1)
281 ple_outputs = []
282 for i in range(self._num_layers):
283 with tf.variable_scope(f'extraction_network_{i}'):
284 if i == self._num_layers - 1: # the last extraction net
285 ple_outputs = self.cgc_model(inputs=ple_inputs, level_name='level_'+str(i)+'_', is_last=True)
286 else:
287 ple_outputs = self.cgc_model(inputs=ple_inputs, level_name='level_'+str(i)+'_', is_last=False)
288 ple_inputs = ple_outputs
289
290 towers=[]
291 for i, tower in enumerate(self._towers):
292 tower_name = tower[0]
293 hidden_units = tower[2]
294
295 with tf.variable_scope(tower_name, reuse=tf.AUTO_REUSE):
296 tower_output = self._dnn(ple_outputs[i], dnn_hidden_units=hidden_units, layer_name='tower_'+tower_name)
297 final_tower_predict = tf.layers.dense(inputs=tower_output,
298 units=1,
299 activation=None,
300 name=f'{tower_name}_output')
301 self._add_layer_summary(final_tower_predict, f'{tower_name}_output')
302 if self._bf16:
303 final_tower_predict = tf.cast(final_tower_predict, dtype=tf.float32)
304 towers.append(final_tower_predict)
305 tower_stack = tf.stack(towers, axis=1)
306 self._logits = tf.squeeze(tower_stack, [2])
307 self.probability = tf.math.sigmoid(self._logits)
308 self.output = tf.round(self.probability)

Callers 1

__init__Method · 0.95

Calls 11

_make_scopeMethod · 0.95
cgc_modelMethod · 0.95
_dnnMethod · 0.95
_add_layer_summaryMethod · 0.95
onesMethod · 0.80
variable_scopeMethod · 0.80
rangeFunction · 0.50
splitMethod · 0.45
castMethod · 0.45
appendMethod · 0.45
stackMethod · 0.45

Tested by

no test coverage detected