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

Function build_feature_columns

modelzoo/bst/train.py:428–600  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

426
427# generate feature columns
428def build_feature_columns():
429 user_column = []
430 item_column = []
431 tag_column = []
432 key_column = []
433 if args.group_embedding and not args.tf:
434 with tf.feature_column.group_embedding_column_scope(name="categorical"):
435 for column_name in INPUT_FEATURES:
436 if column_name in TAG_COLUMN:
437 # parse_sequence_feature
438 categorical_column = tf.feature_column.sequence_categorical_column_with_hash_bucket(
439 column_name,
440 hash_bucket_size=HASH_BUCKET_SIZES[column_name],
441 dtype=tf.string)
442 else:
443 # parse_id_feature
444 categorical_column = tf.feature_column.categorical_column_with_hash_bucket(
445 column_name,
446 hash_bucket_size=HASH_BUCKET_SIZES[column_name],
447 dtype=tf.string)
448
449 if not args.tf:
450 '''Feature Elimination of EmbeddingVariable Feature'''
451 if args.ev_elimination == 'gstep':
452 # Feature elimination based on global steps
453 evict_opt = tf.GlobalStepEvict(steps_to_live=4000)
454 elif args.ev_elimination == 'l2':
455 # Feature elimination based on l2 weight
456 evict_opt = tf.L2WeightEvict(l2_weight_threshold=1.0)
457 else:
458 evict_opt = None
459 '''Feature Filter of EmbeddingVariable Feature'''
460 if args.ev_filter == 'cbf':
461 # CBF-based feature filter
462 filter_option = tf.CBFFilter(
463 filter_freq=3,
464 max_element_size=2**30,
465 false_positive_probability=0.01,
466 counter_type=tf.int64)
467 elif args.ev_filter == 'counter':
468 # Counter-based feature filter
469 filter_option = tf.CounterFilter(filter_freq=3)
470 else:
471 filter_option = None
472 ev_opt = tf.EmbeddingVariableOption(
473 evict_option=evict_opt, filter_option=filter_option)
474
475 if args.ev:
476 '''Embedding Variable Feature'''
477 categorical_column = tf.feature_column.categorical_column_with_embedding(
478 column_name, dtype=tf.string, ev_option=ev_opt)
479 elif args.adaptive_emb:
480 ''' Adaptive Embedding Feature Part 2 of 2
481 Expcet the follow code, a dict, 'adaptive_mask_tensors', is need as the input of
482 'tf.feature_column.input_layer(adaptive_mask_tensors=adaptive_mask_tensors)'.
483 For column 'COL_NAME',the value of adaptive_mask_tensors['$COL_NAME'] is a int32
484 tensor with shape [batch_size].
485 '''

Callers 1

mainFunction · 0.70

Calls 2

exitMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected