You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 10 kB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. # Contents
  2. - [AutoDis Description](#AutoDis-description)
  3. - [Model Architecture](#model-architecture)
  4. - [Dataset](#dataset)
  5. - [Environment Requirements](#environment-requirements)
  6. - [Quick Start](#quick-start)
  7. - [Script Description](#script-description)
  8. - [Script and Sample Code](#script-and-sample-code)
  9. - [Script Parameters](#script-parameters)
  10. - [Training Process](#training-process)
  11. - [Training](#training)
  12. - [Evaluation Process](#evaluation-process)
  13. - [Evaluation](#evaluation)
  14. - [Model Description](#model-description)
  15. - [Performance](#performance)
  16. - [Evaluation Performance](#evaluation-performance)
  17. - [Inference Performance](#evaluation-performance)
  18. - [Description of Random Situation](#description-of-random-situation)
  19. - [ModelZoo Homepage](#modelzoo-homepage)
  20. # [AutoDis Description](#contents)
  21. The common methods for numerical feature embedding are Normalization and Discretization. The former shares a single embedding for intra-field features and the latter transforms the features into categorical form through various discretization approaches. However, the first approach surfers from low capacity and the second one limits performance as well because the discretization rule cannot be optimized with the ultimate goal of CTR model.
  22. To fill the gap of representing numerical features, in this paper, we propose AutoDis, a framework that discretizes features in numerical fields automatically and is optimized with CTR models in an end-to-end manner. Specifically, we introduce a set of meta-embeddings for each numerical field to model the relationship among the intra-field features and propose an automatic differentiable discretization and aggregation approach to capture the correlations between the numerical features and meta-embeddings. AutoDis is a valid framework to work with various popular deep CTR models and is able to improve the recommendation performance significantly.
  23. [Paper](https://arxiv.org/abs/2012.08986): Huifeng Guo*, Bo Chen*, Ruiming Tang, Zhenguo Li, Xiuqiang He. AutoDis: Automatic Discretization for Embedding Numerical Features in CTR Prediction
  24. # [Model Architecture](#contents)
  25. AutoDis leverages a set of meta-embeddings for each numerical field, which are shared among all the intra-field feature values. Meta-embeddings learn the relationship across different feature values in this field with a manageable number of embedding parameters. Utilizing meta-embedding is able to avoid explosive embedding parameters introduced by assigning each numerical feature with an independent embedding simply. Besides, the embedding of a numerical feature is designed as a differentiable aggregation over the shared meta-embeddings, so that the discretization of numerical features can be optimized with the ultimate goal of deep CTR models in an end-to-end manner.
  26. # [Dataset](#contents)
  27. - [1] A dataset Criteo used in Huifeng Guo, Ruiming Tang, Yunming Ye, Zhenguo Li, Xiuqiang He. DeepFM: A Factorization-Machine based Neural Network for CTR Prediction[J]. 2017.
  28. # [Environment Requirements](#contents)
  29. - Hardware(Ascend/GPU)
  30. - Prepare hardware environment with Ascend or GPU processor.
  31. - Framework
  32. - [MindSpore](https://www.mindspore.cn/install/en)
  33. - For more information, please check the resources below:
  34. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  35. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  36. # [Quick Start](#contents)
  37. After installing MindSpore via the official website, you can start training and evaluation as follows:
  38. - running on Ascend
  39. ```python
  40. # run training example
  41. python train.py \
  42. --dataset_path='dataset/train' \
  43. --ckpt_path='./checkpoint' \
  44. --eval_file_name='auc.log' \
  45. --loss_file_name='loss.log' \
  46. --device_target='Ascend' \
  47. --do_eval=True > ms_log/output.log 2>&1 &
  48. # run evaluation example
  49. python eval.py \
  50. --dataset_path='dataset/test' \
  51. --checkpoint_path='./checkpoint/autodis.ckpt' \
  52. --device_target='Ascend' > ms_log/eval_output.log 2>&1 &
  53. OR
  54. sh scripts/run_eval.sh 0 Ascend /dataset_path /checkpoint_path/autodis.ckpt
  55. ```
  56. For distributed training, a hccl configuration file with JSON format needs to be created in advance.
  57. Please follow the instructions in the link below:
  58. <https://gitee.com/mindspore/mindspore/tree/master/model_zoo/utils/hccl_tools>.
  59. # [Script Description](#contents)
  60. ## [Script and Sample Code](#contents)
  61. ```bash
  62. .
  63. └─autodis
  64. ├─README.md
  65. ├─mindspore_hub_conf.md # config for mindspore hub
  66. ├─scripts
  67. ├─run_standalone_train.sh # launch standalone training(1p) in Ascend or GPU
  68. └─run_eval.sh # launch evaluating in Ascend or GPU
  69. ├─src
  70. ├─__init__.py # python init file
  71. ├─config.py # parameter configuration
  72. ├─callback.py # define callback function
  73. ├─autodis.py # AutoDis network
  74. ├─dataset.py # create dataset for AutoDis
  75. ├─eval.py # eval net
  76. └─train.py # train net
  77. ```
  78. ## [Script Parameters](#contents)
  79. Parameters for both training and evaluation can be set in config.py
  80. - train parameters
  81. ```python
  82. optional arguments:
  83. -h, --help show this help message and exit
  84. --dataset_path DATASET_PATH
  85. Dataset path
  86. --ckpt_path CKPT_PATH
  87. Checkpoint path
  88. --eval_file_name EVAL_FILE_NAME
  89. Auc log file path. Default: "./auc.log"
  90. --loss_file_name LOSS_FILE_NAME
  91. Loss log file path. Default: "./loss.log"
  92. --do_eval DO_EVAL Do evaluation or not. Default: True
  93. --device_target DEVICE_TARGET
  94. Ascend or GPU. Default: Ascend
  95. ```
  96. - eval parameters
  97. ```bash
  98. optional arguments:
  99. -h, --help show this help message and exit
  100. --checkpoint_path CHECKPOINT_PATH
  101. Checkpoint file path
  102. --dataset_path DATASET_PATH
  103. Dataset path
  104. --device_target DEVICE_TARGET
  105. Ascend or GPU. Default: Ascend
  106. ```
  107. ## [Training Process](#contents)
  108. ### Training
  109. - running on Ascend
  110. ```python
  111. python train.py \
  112. --dataset_path='dataset/train' \
  113. --ckpt_path='./checkpoint' \
  114. --eval_file_name='auc.log' \
  115. --loss_file_name='loss.log' \
  116. --device_target='Ascend' \
  117. --do_eval=True > ms_log/output.log 2>&1 &
  118. ```
  119. The python command above will run in the background, you can view the results through the file `ms_log/output.log`.
  120. After training, you'll get some checkpoint files under `./checkpoint` folder by default. The loss value are saved in loss.log file.
  121. ```txt
  122. 2020-12-10 14:58:04 epoch: 1 step: 41257, loss is 0.44559600949287415
  123. 2020-12-10 15:06:59 epoch: 2 step: 41257, loss is 0.4370603561401367
  124. ...
  125. ```
  126. The model checkpoint will be saved in the current directory.
  127. ## [Evaluation Process](#contents)
  128. ### Evaluation
  129. - evaluation on dataset when running on Ascend
  130. Before running the command below, please check the checkpoint path used for evaluation.
  131. ```python
  132. python eval.py \
  133. --dataset_path='dataset/test' \
  134. --checkpoint_path='./checkpoint/autodis.ckpt' \
  135. --device_target='Ascend' > ms_log/eval_output.log 2>&1 &
  136. OR
  137. sh scripts/run_eval.sh 0 Ascend /dataset_path /checkpoint_path/autodis.ckpt
  138. ```
  139. The above python command will run in the background. You can view the results through the file "eval_output.log". The accuracy is saved in auc.log file.
  140. ```txt
  141. {'result': {'AUC': 0.8109881454077731, 'eval_time': 27.72783327102661s}}
  142. ```
  143. # [Model Description](#contents)
  144. ## [Performance](#contents)
  145. ### Training Performance
  146. | Parameters | Ascend |
  147. | -------------------------- | ----------------------------------------------------------- |
  148. | Model Version | AutoDis |
  149. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 755G |
  150. | uploaded Date | 12/12/2020 (month/day/year) |
  151. | MindSpore Version | 1.1.0 |
  152. | Dataset | [1] |
  153. | Training Parameters | epoch=15, batch_size=1000, lr=1e-5 |
  154. | Optimizer | Adam |
  155. | Loss Function | Sigmoid Cross Entropy With Logits |
  156. | outputs | Accuracy |
  157. | Loss | 0.42 |
  158. | Speed | 1pc: 8.16 ms/step; |
  159. | Total time | 1pc: 90 mins; |
  160. | Parameters (M) | 16.5 |
  161. | Checkpoint for Fine tuning | 191M (.ckpt file) |
  162. | Scripts | [AutoDis script](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/research/recommend/autodis) |
  163. ### Inference Performance
  164. | Parameters | Ascend |
  165. | ------------------- | --------------------------- |
  166. | Model Version | AutoDis |
  167. | Resource | Ascend 910 |
  168. | Uploaded Date | 12/12/2020 (month/day/year) |
  169. | MindSpore Version | 0.3.0-alpha |
  170. | Dataset | [1] |
  171. | batch_size | 1000 |
  172. | outputs | accuracy |
  173. | AUC | 1pc: 0.8112; |
  174. | Model for inference | 191M (.ckpt file) |
  175. # [Description of Random Situation](#contents)
  176. We set the random seed before training in train.py.
  177. # [ModelZoo Homepage](#contents)
  178. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).