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

Function build_feature_columns

modelzoo/dcn/train.py:412–582  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

410
411# generate feature columns
412def build_feature_columns():
413 # Notes: Statistics of Kaggle's Criteo Dataset has been calculated in advance to save time.
414 mins_list = [
415 0.0, -3.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
416 ]
417 range_list = [
418 1539.0, 22069.0, 65535.0, 561.0, 2655388.0, 233523.0, 26297.0, 5106.0,
419 24376.0, 9.0, 181.0, 1807.0, 6879.0
420 ]
421
422 def make_minmaxscaler(min, range):
423 def minmaxscaler(col):
424 return (col - min) / range
425
426 return minmaxscaler
427
428 emb_stacking_columns = []
429 if args.group_embedding and not args.tf:
430 with tf.feature_column.group_embedding_column_scope(name="categorical"):
431 for column_name in FEATURE_COLUMNS:
432 if column_name in CATEGORICAL_COLUMNS:
433 categorical_column = tf.feature_column.categorical_column_with_hash_bucket(
434 column_name, hash_bucket_size=10000, dtype=tf.string)
435
436 if not args.tf:
437 '''Feature Elimination of EmbeddingVariable Feature'''
438 if args.ev_elimination == 'gstep':
439 # Feature elimination based on global steps
440 evict_opt = tf.GlobalStepEvict(steps_to_live=4000)
441 elif args.ev_elimination == 'l2':
442 # Feature elimination based on l2 weight
443 evict_opt = tf.L2WeightEvict(l2_weight_threshold=1.0)
444 else:
445 evict_opt = None
446 '''Feature Filter of EmbeddingVariable Feature'''
447 if args.ev_filter == 'cbf':
448 # CBF-based feature filter
449 filter_option = tf.CBFFilter(
450 filter_freq=3,
451 max_element_size=2**30,
452 false_positive_probability=0.01,
453 counter_type=tf.int64)
454 elif args.ev_filter == 'counter':
455 # Counter-based feature filter
456 filter_option = tf.CounterFilter(filter_freq=3)
457 else:
458 filter_option = None
459 ev_opt = tf.EmbeddingVariableOption(
460 evict_option=evict_opt, filter_option=filter_option)
461
462 if args.ev:
463 '''Embedding Variable Feature'''
464 categorical_column = tf.feature_column.categorical_column_with_embedding(
465 column_name, dtype=tf.string, ev_option=ev_opt)
466 elif args.adaptive_emb:
467 ''' Adaptive Embedding Feature Part 2 of 2
468 Expcet the follow code, a dict, 'adaptive_mask_tensors', is need as the input of
469 'tf.feature_column.input_layer(adaptive_mask_tensors=adaptive_mask_tensors)'.

Callers 1

mainFunction · 0.70

Calls 4

exitMethod · 0.80
make_minmaxscalerFunction · 0.70
appendMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected