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

Function build_feature_columns

modelzoo/dlrm/train.py:342–495  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

340
341# generate feature columns
342def build_feature_columns():
343 dense_column = []
344 sparse_column = []
345 if args.group_embedding and not args.tf:
346 with tf.feature_column.group_embedding_column_scope(name="categorical"):
347 for column_name in FEATURE_COLUMNS:
348 if column_name in CATEGORICAL_COLUMNS:
349 categorical_column = tf.feature_column.categorical_column_with_hash_bucket(
350 column_name,
351 hash_bucket_size=10000,
352 dtype=tf.string)
353
354 if not args.tf:
355 '''Feature Elimination of EmbeddingVariable Feature'''
356 if args.ev_elimination == 'gstep':
357 # Feature elimination based on global steps
358 evict_opt = tf.GlobalStepEvict(steps_to_live=4000)
359 elif args.ev_elimination == 'l2':
360 # Feature elimination based on l2 weight
361 evict_opt = tf.L2WeightEvict(l2_weight_threshold=1.0)
362 else:
363 evict_opt = None
364 '''Feature Filter of EmbeddingVariable Feature'''
365 if args.ev_filter == 'cbf':
366 # CBF-based feature filter
367 filter_option = tf.CBFFilter(
368 filter_freq=3,
369 max_element_size=2**30,
370 false_positive_probability=0.01,
371 counter_type=tf.int64)
372 elif args.ev_filter == 'counter':
373 # Counter-based feature filter
374 filter_option = tf.CounterFilter(filter_freq=3)
375 else:
376 filter_option = None
377 ev_opt = tf.EmbeddingVariableOption(
378 evict_option=evict_opt, filter_option=filter_option)
379
380 if args.ev:
381 '''Embedding Variable Feature'''
382 categorical_column = tf.feature_column.categorical_column_with_embedding(
383 column_name, dtype=tf.string, ev_option=ev_opt)
384 elif args.adaptive_emb:
385 ''' Adaptive Embedding Feature Part 2 of 2
386 Expcet the follow code, a dict, 'adaptive_mask_tensors', is need as the input of
387 'tf.feature_column.input_layer(adaptive_mask_tensors=adaptive_mask_tensors)'.
388 For column 'COL_NAME',the value of adaptive_mask_tensors['$COL_NAME'] is a int32
389 tensor with shape [batch_size].
390 '''
391 categorical_column = tf.feature_column.categorical_column_with_adaptive_embedding(
392 column_name,
393 hash_bucket_size=HASH_BUCKET_SIZES[column_name],
394 dtype=tf.string,
395 ev_option=ev_opt)
396 elif args.dynamic_ev:
397 '''Dynamic-dimension Embedding Variable'''
398 print(
399 "Dynamic-dimension Embedding Variable isn't really enabled in model."

Callers 1

mainFunction · 0.70

Calls 2

exitMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected