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

Function build_feature_columns

modelzoo/dssm/train.py:321–466  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

319
320# generate feature columns
321def build_feature_columns():
322 user_column = []
323 item_column = []
324 if args.group_embedding and not args.tf:
325 with tf.feature_column.group_embedding_column_scope(name="categorical"):
326 for column_name in INPUT_FEATURES:
327 categorical_column = tf.feature_column.categorical_column_with_hash_bucket(
328 column_name,
329 hash_bucket_size=HASH_BUCKET_SIZES[column_name],
330 dtype=tf.string)
331
332 if not args.tf:
333 '''Feature Elimination of EmbeddingVariable Feature'''
334 if args.ev_elimination == 'gstep':
335 # Feature elimination based on global steps
336 evict_opt = tf.GlobalStepEvict(steps_to_live=4000)
337 elif args.ev_elimination == 'l2':
338 # Feature elimination based on l2 weight
339 evict_opt = tf.L2WeightEvict(l2_weight_threshold=1.0)
340 else:
341 evict_opt = None
342 '''Feature Filter of EmbeddingVariable Feature'''
343 if args.ev_filter == 'cbf':
344 # CBF-based feature filter
345 filter_option = tf.CBFFilter(filter_freq=3,
346 max_element_size=2**30,
347 false_positive_probability=0.01,
348 counter_type=tf.int64)
349 elif args.ev_filter == 'counter':
350 # Counter-based feature filter
351 filter_option = tf.CounterFilter(filter_freq=3)
352 else:
353 filter_option = None
354 ev_opt = tf.EmbeddingVariableOption(evict_option=evict_opt,
355 filter_option=filter_option)
356
357 if args.ev:
358 '''Embedding Variable Feature'''
359 categorical_column = tf.feature_column.categorical_column_with_embedding(
360 column_name, dtype=tf.string, ev_option=ev_opt)
361 elif args.adaptive_emb:
362 ''' Adaptive Embedding Feature Part 2 of 2
363 Expcet the follow code, a dict, 'adaptive_mask_tensors', is need as the input of
364 'tf.feature_column.input_layer(adaptive_mask_tensors=adaptive_mask_tensors)'.
365 For column 'COL_NAME',the value of adaptive_mask_tensors['$COL_NAME'] is a int32
366 tensor with shape [batch_size].
367 '''
368 categorical_column = tf.feature_column.categorical_column_with_adaptive_embedding(
369 column_name,
370 hash_bucket_size=HASH_BUCKET_SIZES[column_name],
371 dtype=tf.string,
372 ev_option=ev_opt)
373 elif args.dynamic_ev:
374 '''Dynamic-dimension Embedding Variable'''
375 print(
376 "Dynamic-dimension Embedding Variable isn't really enabled in model."
377 )
378 sys.exit()

Callers 1

mainFunction · 0.70

Calls 2

exitMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected