DCN

November 27, 2024 ยท View on GitHub

This directory's train.py showcases an example of training a Deep & Cross Network (DCN) through Kv Variable and custom optimizer (including Adam, Adagrad, Group Adam, and Group Adagrad) from TFPlus to perform CTR prediction tasks.

The implementation of this example is referenced from the DeepRec repository, see: https://github.com/DeepRec-AI/DeepRec/tree/main/modelzoo/dcn

Model Architecture

Deep & Cross Network(DCN) is proposed by Google by 2017.

Usage

Stand-alone Training

  1. Install TFPlus Firstly, you need to install TFPlus according to the instructions in README. You can manually build TFPlus locally or use Docker image of TFPlus (recommended).
  2. Download Criteo Dataset In this example, the Train & eval dataset uses Kaggle Display Advertising Challenge Dataset (Criteo Dataset). Due to the large size of the Criteo Dataset, you need to manually download the dataset.
    Download the train/eval dataset(in csv format) from
  1. Training
python train.py

You can use the --tf argument to disable TFPlus features and use the community tensorflow to perform regular training.

python train.py --tf

Use arguments to set up a custom configuation:

  • TFPlus Features:
    • --optimizer: Choose the optimizer for deep model from ['adam', 'adagrad', 'group_adam', 'sparse_group_ftrl']. Use adam by default. These optimizers are custom versions from TFPlus, and are compatible with Kv Variable.
  • Basic Settings:
    • --data_location: Full path of train & eval data, default to ./data.
    • --steps: Set the number of steps on train dataset. Default will be set to 1 epoch.
    • --no_eval: Do not evaluate trained model by eval dataset.
    • --batch_size: Batch size to train. Default to 2048.
    • --output_dir: Full path to output directory for logs and saved model, default to ./result.
    • --checkpoint: Full path to checkpoints input/output directory, default to $(OUTPUT_DIR)/model_$(MODEL_NAME)_$(TIMESTAMPS)
    • --save_steps: Set the number of steps on saving checkpoints, zero to close. Default will be set to 0.
    • --seed: Set the random seed for tensorflow.
    • --timeline: Save steps of profile hooks to record timeline, zero to close, defualt to 0.
    • --keep_checkpoint_max: Maximum number of recent checkpoint to keep. Default to 1.
    • --learning_rate: Learning rate for network. Default to 0.1.
    • --interaction_op: Choose interaction op before top MLP layer('dot', 'cat'). Default to cat.
    • --inter: Set inter op parallelism threads. Default to 0.
    • --intra: Set intra op parallelism threads. Default to 0.
    • --tf: Use TF 2.13.0 embedding API and disable TFPlus features.

Benchmark

The results below utilize the default parameters of train.py, with only the learning rate and optimizer changed.

Optimizer learning rate Accuracy AUC
DCN TFPlus w/ Adam 0.001 0.77356 0.76201
TFPlus w/ Adagard 0.001 0.74652 0.69305
TFPlus w/ Adagard 0.1 0.72445 0.64390
TFPlus w/ Group Adam 0.001 0.76340 0.76197
TFPlus w/ Group Adagrad 0.1 0.75896 0.75370

Dataset Introduction

Train & eval dataset using Kaggle Display Advertising Challenge Dataset (Criteo Dataset).

Fields

Total 40 columns:
[0]:Label - Target variable that indicates if an ad was clicked or not(1 or 0)
[1-13]:I1-I13 - A total 13 columns of integer continuous features(mostly count features)
[14-39]:C1-C26 - A total 26 columns of categorical features. The values have been hashed onto 32 bits for anonymization purposes.

Integer column's distribution is as follow:

Column12345678910111213
Min0-300000000000
Max15392206665535561265538823352326279510624376918118076879

Categorical column's numbers of types is as follow:

columnC1C2C3C4C5C6C7C8C9C10C11C12C13C14C15C16C17C18C19C20C21C22C23C24C25C26
nums1396553259403169846929023120486083651565309218650931282612750153732310500221184190232717151357909484305

Processing

  • Interger columns I[1-13] is processed with tf.feature_column.numeric_column() function, and the data is normalized.
    In order to save time, the data required for normalization has been calculated in advance.
  • Categorical columns C[1-26] is processed with tfplus.kv_variable.python.ops.variable_scope.get_kv_variable() function after using tf.strings.to_hash_bucket_fast() function.