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

Function build_feature_columns

modelzoo/dien/train.py:673–764  ·  view source on GitHub ↗
(data_location=None)

Source from the content-addressed store, hash-verified

671
672# generate feature columns
673def build_feature_columns(data_location=None):
674 # uid_file
675 uid_file = os.path.join(data_location, 'uid_voc.txt')
676 mid_file = os.path.join(data_location, 'mid_voc.txt')
677 cat_file = os.path.join(data_location, 'cat_voc.txt')
678 if (not os.path.exists(uid_file)) or (not os.path.exists(mid_file)) or (
679 not os.path.exists(cat_file)):
680 print(
681 "uid_voc.txt, mid_voc.txt or cat_voc does not exist in data file.")
682 sys.exit()
683 # uid
684 uid_cate_column = tf.feature_column.categorical_column_with_vocabulary_file(
685 'UID', uid_file, default_value=0)
686 ev_opt = None
687 if not args.tf:
688 '''Feature Elimination of EmbeddingVariable Feature'''
689 if args.ev_elimination == 'gstep':
690 # Feature elimination based on global steps
691 evict_opt = tf.GlobalStepEvict(steps_to_live=4000)
692 elif args.ev_elimination == 'l2':
693 # Feature elimination based on l2 weight
694 evict_opt = tf.L2WeightEvict(l2_weight_threshold=1.0)
695 else:
696 evict_opt = None
697 '''Feature Filter of EmbeddingVariable Feature'''
698 if args.ev_filter == 'cbf':
699 # CBF-based feature filter
700 filter_option = tf.CBFFilter(filter_freq=3,
701 max_element_size=2**30,
702 false_positive_probability=0.01,
703 counter_type=tf.int64)
704 elif args.ev_filter == 'counter':
705 # Counter-based feature filter
706 filter_option = tf.CounterFilter(filter_freq=3)
707 else:
708 filter_option = None
709 ev_opt = tf.EmbeddingVariableOption(evict_option=evict_opt,
710 filter_option=filter_option)
711
712 if args.ev:
713 '''Embedding Variable Feature with feature_column API'''
714 uid_cate_column = tf.feature_column.categorical_column_with_embedding(
715 'UID', dtype=tf.string, ev_option=ev_opt)
716 elif args.adaptive_emb:
717 ''' Adaptive Embedding Feature Part 2 of 2
718 Expcet the follow code, a dict, 'adaptive_mask_tensors', is need as the input of
719 'tf.feature_column.input_layer(adaptive_mask_tensors=adaptive_mask_tensors)'.
720 For column 'COL_NAME',the value of adaptive_mask_tensors['$COL_NAME'] is a int32
721 tensor with shape [batch_size].
722 '''
723 uid_cate_column = tf.feature_column.categorical_column_with_adaptive_embedding(
724 'UID',
725 hash_bucket_size=100000,
726 dtype=tf.string,
727 ev_option=ev_opt)
728 elif args.dynamic_ev:
729 '''Dynamic-dimension Embedding Variable'''
730 print(

Callers 1

mainFunction · 0.70

Calls 2

exitMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected