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 12 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. # Contents
  2. - [DeepFM Description](#deepfm-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. - [Distributed Training](#distributed-training)
  13. - [Evaluation Process](#evaluation-process)
  14. - [Evaluation](#evaluation)
  15. - [Model Description](#model-description)
  16. - [Performance](#performance)
  17. - [Evaluation Performance](#evaluation-performance)
  18. - [Inference Performance](#evaluation-performance)
  19. - [Description of Random Situation](#description-of-random-situation)
  20. - [ModelZoo Homepage](#modelzoo-homepage)
  21. # [DeepFM Description](#contents)
  22. Learning sophisticated feature interactions behind user behaviors is critical in maximizing CTR for recommender systems. Despite great progress, existing methods seem to have a strong bias towards low- or high-order interactions, or require expertise feature engineering. In this paper, we show that it is possible to derive an end-to-end learning model that emphasizes both low- and high-order feature interactions. The proposed model, DeepFM, combines the power of factorization machines for recommendation and deep learning for feature learning in a new neural network architecture.
  23. [Paper](https://arxiv.org/abs/1703.04247): Huifeng Guo, Ruiming Tang, Yunming Ye, Zhenguo Li, Xiuqiang He. DeepFM: A Factorization-Machine based Neural Network for CTR Prediction
  24. # [Model Architecture](#contents)
  25. DeepFM consists of two components. The FM component is a factorization machine, which is proposed in to learn feature interactions for recommendation. The deep component is a feed-forward neural network, which is used to learn high-order feature interactions.
  26. The FM and deep component share the same input raw feature vector, which enables DeepFM to learn low- and high-order feature interactions simultaneously from the input raw features.
  27. # [Dataset](#contents)
  28. - [1] A dataset used in Huifeng Guo, Ruiming Tang, Yunming Ye, Zhenguo Li, Xiuqiang He. DeepFM: A Factorization-Machine based Neural Network for CTR Prediction[J]. 2017.
  29. # [Environment Requirements](#contents)
  30. - Hardware(Ascend/GPU)
  31. - Prepare hardware environment with Ascend or GPU processor. If you want to try Ascend, please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get the resources.
  32. - Framework
  33. - [MindSpore](https://www.mindspore.cn/install/en)
  34. - For more information, please check the resources below:
  35. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  36. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  37. # [Quick Start](#contents)
  38. After installing MindSpore via the official website, you can start training and evaluation as follows:
  39. - runing on Ascend
  40. ```
  41. # run training example
  42. python train.py \
  43. --dataset_path='dataset/train' \
  44. --ckpt_path='./checkpoint' \
  45. --eval_file_name='auc.log' \
  46. --loss_file_name='loss.log' \
  47. --device_target='Ascend' \
  48. --do_eval=True > ms_log/output.log 2>&1 &
  49. # run distributed training example
  50. sh scripts/run_distribute_train.sh 8 /dataset_path /rank_table_8p.json
  51. # run evaluation example
  52. python eval.py \
  53. --dataset_path='dataset/test' \
  54. --checkpoint_path='./checkpoint/deepfm.ckpt' \
  55. --device_target='Ascend' > ms_log/eval_output.log 2>&1 &
  56. OR
  57. sh scripts/run_eval.sh 0 Ascend /dataset_path /checkpoint_path/deepfm.ckpt
  58. ```
  59. For distributed training, a hccl configuration file with JSON format needs to be created in advance.
  60. Please follow the instructions in the link below:
  61. https://gitee.com/mindspore/mindspore/tree/master/model_zoo/utils/hccl_tools.
  62. - running on GPU
  63. For running on GPU, please change `device_target` from `Ascend` to `GPU` in configuration file src/config.py
  64. ```
  65. # run training example
  66. python train.py \
  67. --dataset_path='dataset/train' \
  68. --ckpt_path='./checkpoint' \
  69. --eval_file_name='auc.log' \
  70. --loss_file_name='loss.log' \
  71. --device_target='GPU' \
  72. --do_eval=True > ms_log/output.log 2>&1 &
  73. # run distributed training example
  74. sh scripts/run_distribute_train.sh 8 /dataset_path
  75. # run evaluation example
  76. python eval.py \
  77. --dataset_path='dataset/test' \
  78. --checkpoint_path='./checkpoint/deepfm.ckpt' \
  79. --device_target='GPU' > ms_log/eval_output.log 2>&1 &
  80. OR
  81. sh scripts/run_eval.sh 0 GPU /dataset_path /checkpoint_path/deepfm.ckpt
  82. ```
  83. # [Script Description](#contents)
  84. ## [Script and Sample Code](#contents)
  85. ```
  86. .
  87. └─deepfm
  88. ├─README.md
  89. ├─mindspore_hub_conf.md # config for mindspore hub
  90. ├─scripts
  91. ├─run_standalone_train.sh # launch standalone training(1p) in Ascend or GPU
  92. ├─run_distribute_train.sh # launch distributed training(8p) in Ascend
  93. ├─run_distribute_train_gpu.sh # launch distributed training(8p) in GPU
  94. └─run_eval.sh # launch evaluating in Ascend or GPU
  95. ├─src
  96. ├─__init__.py # python init file
  97. ├─config.py # parameter configuration
  98. ├─callback.py # define callback function
  99. ├─deepfm.py # deepfm network
  100. ├─dataset.py # create dataset for deepfm
  101. ├─eval.py # eval net
  102. └─train.py # train net
  103. ```
  104. ## [Script Parameters](#contents)
  105. Parameters for both training and evaluation can be set in config.py
  106. - train parameters
  107. ```
  108. optional arguments:
  109. -h, --help show this help message and exit
  110. --dataset_path DATASET_PATH
  111. Dataset path
  112. --ckpt_path CKPT_PATH
  113. Checkpoint path
  114. --eval_file_name EVAL_FILE_NAME
  115. Auc log file path. Default: "./auc.log"
  116. --loss_file_name LOSS_FILE_NAME
  117. Loss log file path. Default: "./loss.log"
  118. --do_eval DO_EVAL Do evaluation or not. Default: True
  119. --device_target DEVICE_TARGET
  120. Ascend or GPU. Default: Ascend
  121. ```
  122. - eval parameters
  123. ```
  124. optional arguments:
  125. -h, --help show this help message and exit
  126. --checkpoint_path CHECKPOINT_PATH
  127. Checkpoint file path
  128. --dataset_path DATASET_PATH
  129. Dataset path
  130. --device_target DEVICE_TARGET
  131. Ascend or GPU. Default: Ascend
  132. ```
  133. ## [Training Process](#contents)
  134. ### Training
  135. - running on Ascend
  136. ```
  137. python train.py \
  138. --dataset_path='dataset/train' \
  139. --ckpt_path='./checkpoint' \
  140. --eval_file_name='auc.log' \
  141. --loss_file_name='loss.log' \
  142. --device_target='Ascend' \
  143. --do_eval=True > ms_log/output.log 2>&1 &
  144. ```
  145. The python command above will run in the background, you can view the results through the file `ms_log/output.log`.
  146. After training, you'll get some checkpoint files under `./checkpoint` folder by default. The loss value are saved in loss.log file.
  147. ```
  148. 2020-05-27 15:26:29 epoch: 1 step: 41257, loss is 0.498953253030777
  149. 2020-05-27 15:32:32 epoch: 2 step: 41257, loss is 0.45545706152915955
  150. ...
  151. ```
  152. The model checkpoint will be saved in the current directory.
  153. - running on GPU
  154. To do.
  155. ### Distributed Training
  156. - running on Ascend
  157. ```
  158. sh scripts/run_distribute_train.sh 8 /dataset_path /rank_table_8p.json
  159. ```
  160. The above shell script will run distribute training in the background. You can view the results through the file `log[X]/output.log`. The loss value are saved in loss.log file.
  161. - running on GPU
  162. To do.
  163. ## [Evaluation Process](#contents)
  164. ### Evaluation
  165. - evaluation on dataset when running on Ascend
  166. Before running the command below, please check the checkpoint path used for evaluation.
  167. ```
  168. python eval.py \
  169. --dataset_path='dataset/test' \
  170. --checkpoint_path='./checkpoint/deepfm.ckpt' \
  171. --device_target='Ascend' > ms_log/eval_output.log 2>&1 &
  172. OR
  173. sh scripts/run_eval.sh 0 Ascend /dataset_path /checkpoint_path/deepfm.ckpt
  174. ```
  175. 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.
  176. ```
  177. {'result': {'AUC': 0.8057789065281104, 'eval_time': 35.64779996871948}}
  178. ```
  179. - evaluation on dataset when running on GPU
  180. To do.
  181. # [Model Description](#contents)
  182. ## [Performance](#contents)
  183. ### Evaluation Performance
  184. | Parameters | Ascend | GPU |
  185. | -------------------------- | ----------------------------------------------------------- | ---------------------- |
  186. | Model Version | DeepFM | To do |
  187. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 755G | To do |
  188. | uploaded Date | 09/15/2020 (month/day/year) | To do |
  189. | MindSpore Version | 1.0.0 | To do |
  190. | Dataset | [1] | To do |
  191. | Training Parameters | epoch=15, batch_size=1000, lr=1e-5 | To do |
  192. | Optimizer | Adam | To do |
  193. | Loss Function | Sigmoid Cross Entropy With Logits | To do |
  194. | outputs | Accuracy | To do |
  195. | Loss | 0.45 | To do |
  196. | Speed | 1pc: 8.16 ms/step; | To do |
  197. | Total time | 1pc: 90 mins; | To do |
  198. | Parameters (M) | 16.5 | To do |
  199. | Checkpoint for Fine tuning | 190M (.ckpt file) | To do |
  200. | Scripts | [deepfm script](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/recommend/deepfm) | To do |
  201. ### Inference Performance
  202. | Parameters | Ascend | GPU |
  203. | ------------------- | --------------------------- | --------------------------- |
  204. | Model Version | DeepFM | To do |
  205. | Resource | Ascend 910 | To do |
  206. | Uploaded Date | 05/27/2020 (month/day/year) | To do |
  207. | MindSpore Version | 0.3.0-alpha | To do |
  208. | Dataset | [1] | To do |
  209. | batch_size | 1000 | To do |
  210. | outputs | accuracy | To do |
  211. | Accuracy | 1pc: 80.55%; | To do |
  212. | Model for inference | 190M (.ckpt file) | To do |
  213. # [Description of Random Situation](#contents)
  214. We set the random seed before training in train.py.
  215. # [ModelZoo Homepage](#contents)
  216. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).