| 361 | return dataset |
| 362 | |
| 363 | def build_feature_cols(): |
| 364 | feature_cols = [] |
| 365 | if args.group_embedding and not args.tf: |
| 366 | with tf.feature_column.group_embedding_column_scope(name="categorical"): |
| 367 | for column_name in ALL_FEATURE_COLUMNS: |
| 368 | if column_name in NOT_USED_CATEGORY: |
| 369 | continue |
| 370 | if column_name in HASH_INPUTS: |
| 371 | print('Column name = ', column_name, ' hash bucket size = ', HASH_BUCKET_SIZES[column_name]) |
| 372 | categorical_column = tf.feature_column.categorical_column_with_hash_bucket( |
| 373 | column_name, |
| 374 | hash_bucket_size=HASH_BUCKET_SIZES[column_name], |
| 375 | dtype=tf.string) |
| 376 | |
| 377 | if not args.tf: |
| 378 | '''Feature Elimination of EmbeddingVariable Feature''' |
| 379 | if args.ev_elimination == 'gstep': |
| 380 | # Feature elimination based on global steps |
| 381 | evict_opt = tf.GlobalStepEvict(steps_to_live=4000) |
| 382 | elif args.ev_elimination == 'l2': |
| 383 | # Feature elimination based on l2 weight |
| 384 | evict_opt = tf.L2WeightEvict(l2_weigt_threshold=1.0) |
| 385 | else: |
| 386 | evict_opt = None |
| 387 | '''Feature Filter of EmbeddingVariable Feature''' |
| 388 | if args.ev_filter == 'cbf': |
| 389 | # CBF-based feature filter |
| 390 | filter_option = tf.CBFFilter( |
| 391 | filter_freq=3, |
| 392 | max_element_size=2**30, |
| 393 | false_positive_probability=0.01, |
| 394 | counter_type=tf.int64) |
| 395 | elif args.ev_filter == 'counter': |
| 396 | # Counter-based feature filter |
| 397 | filter_option = tf.CounterFilter(filter_freq=3) |
| 398 | else: |
| 399 | filter_option = None |
| 400 | ev_opt = tf.EmbeddingVariableOption( |
| 401 | evict_option=evict_opt, filter_option=filter_option) |
| 402 | |
| 403 | if args.ev: |
| 404 | '''Embedding Variable Feature''' |
| 405 | categorical_column = tf.feature_column.categorical_column_with_embedding( |
| 406 | column_name, dtype=tf.string, ev_option=ev_opt) |
| 407 | elif args.adaptive_emb: |
| 408 | ''' Adaptive Embedding Feature Part 2 of 2 |
| 409 | Expcet the follow code, a dict, 'adaptive_mask_tensors', is need as the input of |
| 410 | 'tf.feature_column.input_layer(adaptive_mask_tensors=adaptive_mask_tensors)'. |
| 411 | For column 'COL_NAME',the value of adaptive_mask_tensors['$COL_NAME'] is a int32 |
| 412 | tensor with shape [batch_size]. |
| 413 | ''' |
| 414 | |
| 415 | categorical_column = tf.feature_column.categorical_column_with_adaptive_embedding( |
| 416 | column_name, |
| 417 | hash_bucket_size=HASH_BUCKET_SIZES[column_name], |
| 418 | dtype=tf.string, |
| 419 | ev_option=ev_opt) |
| 420 | elif args.dynamic_ev: |