README.md 3.5 KB
Newer Older
Q
Qiao Longfei 已提交
1

Q
Qiao Longfei 已提交
2
# DNN for Click-Through Rate prediction
Q
Qiao Longfei 已提交
3 4

## Introduction
Q
Qiao Longfei 已提交
5
This model implements the DNN part proposed in the following paper:
Q
Qiao Longfei 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

```text
@inproceedings{guo2017deepfm,
  title={DeepFM: A Factorization-Machine based Neural Network for CTR Prediction},
  author={Huifeng Guo, Ruiming Tang, Yunming Ye, Zhenguo Li and Xiuqiang He},
  booktitle={the Twenty-Sixth International Joint Conference on Artificial Intelligence (IJCAI)},
  pages={1725--1731},
  year={2017}
}
```

The DeepFm combines factorization machine and deep neural networks to model
both low order and high order feature interactions. For details of the
factorization machines, please refer to the paper [factorization
machines](https://www.csie.ntu.edu.tw/~b97053/paper/Rendle2010FM.pdf)

22 23 24 25 26 27 28
## Environment
You should install PaddlePaddle Fluid first, and run:

```shell
pip install -r requirements.txt
```

Q
Qiao Longfei 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
## Dataset
This example uses Criteo dataset which was used for the [Display Advertising
Challenge](https://www.kaggle.com/c/criteo-display-ad-challenge/)
hosted by Kaggle.

Each row is the features for an ad display and the first column is a label
indicating whether this ad has been clicked or not. There are 39 features in
total. 13 features take integer values and the other 26 features are
categorical features. For the test dataset, the labels are omitted.

Download dataset:
```bash
cd data && ./download.sh && cd ..
```

## Model
Q
Qiao Longfei 已提交
45 46 47
This Demo only implement the DNN part of the model described in DeepFM paper.
DeepFM model will be provided in other model.

Q
Qiao Longfei 已提交
48

49
## Data Preprocessing method
Q
Qiao Longfei 已提交
50 51 52
To preprocess the raw dataset, the integer features are clipped then min-max
normalized to [0, 1] and the categorical features are one-hot encoded. The raw
training dataset are splited such that 90% are used for training and the other
53 54
10% are used for validation during training. In reader.py, training data is the first 
90% of data in train.txt, and validation data is the left.
Q
Qiao Longfei 已提交
55 56 57 58

## Train
The command line options for training can be listed by `python train.py -h`.

Q
Qiao Longfei 已提交
59
### Local Train:
Q
Qiao Longfei 已提交
60 61
```bash
python train.py \
62
        --train_data_path data/raw/train.txt \
Q
Qiao Longfei 已提交
63 64 65
        2>&1 | tee train.log
```

Q
Qiao Longfei 已提交
66
After training pass 1 batch 40000, the testing AUC is `0.801178` and the testing
Q
Qiao Longfei 已提交
67 68
cost is `0.445196`.

Q
Qiao Longfei 已提交
69
### Distributed Train
70 71 72
Run a 2 pserver 2 trainer distribute training on a single machine.
In distributed training setting, training data is splited by trainer_id, so that training data
 do not overlap among trainers
Q
Qiao Longfei 已提交
73

Q
Qiao Longfei 已提交
74
```bash
Q
Qiao Longfei 已提交
75
sh cluster_train.sh
Q
Qiao Longfei 已提交
76 77
```

Q
Qiao Longfei 已提交
78 79 80 81 82 83
## Infer
The command line options for infering can be listed by `python infer.py -h`.

To make inference for the test dataset:
```bash
python infer.py \
Q
Qiao Longfei 已提交
84
        --model_path models/ \
85
        --data_path data/raw/train.txt
Q
Qiao Longfei 已提交
86
```
87
Note: The AUC value in the last log info is the total AUC for all test dataset. Here, train.txt is splited inside the reader.py so that validation data does not have overlap with training data.
Q
Qiao Longfei 已提交
88 89 90 91 92

## Train on Baidu Cloud
1. Please prepare some CPU machines on Baidu Cloud following the steps in [train_on_baidu_cloud](https://github.com/PaddlePaddle/FluidDoc/blob/develop/doc/fluid/user_guides/howto/training/train_on_baidu_cloud_cn.rst)
1. Prepare dataset using preprocess.py.
1. Split the train.txt to trainer_num parts and put them on the machines.
T
tangwei12 已提交
93 94 95 96
1. Run training with the cluster train using the command in `Distributed Train` above.

## Train on Paddle Cloud
If you want to run this training on PaddleCloud, you can use the script ```cloud.py```, you can change the arguments in ```trian.py``` through environments in PaddleCloud.