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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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/zh-CN/master/index.html)
  36. - [MindSpore API](https://www.mindspore.cn/api/zh-CN/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. ├─scripts
  90. ├─run_standalone_train.sh # launch standalone training(1p) in Ascend or GPU
  91. ├─run_distribute_train.sh # launch distributed training(8p) in Ascend
  92. ├─run_distribute_train_gpu.sh # launch distributed training(8p) in GPU
  93. └─run_eval.sh # launch evaluating in Ascend or GPU
  94. ├─src
  95. ├─__init__.py # python init file
  96. ├─config.py # parameter configuration
  97. ├─callback.py # define callback function
  98. ├─deepfm.py # deepfm network
  99. ├─dataset.py # create dataset for deepfm
  100. ├─eval.py # eval net
  101. └─train.py # train net
  102. ```
  103. ## [Script Parameters](#contents)
  104. Parameters for both training and evaluation can be set in config.py
  105. - train parameters
  106. ```
  107. optional arguments:
  108. -h, --help show this help message and exit
  109. --dataset_path DATASET_PATH
  110. Dataset path
  111. --ckpt_path CKPT_PATH
  112. Checkpoint path
  113. --eval_file_name EVAL_FILE_NAME
  114. Auc log file path. Default: "./auc.log"
  115. --loss_file_name LOSS_FILE_NAME
  116. Loss log file path. Default: "./loss.log"
  117. --do_eval DO_EVAL Do evaluation or not. Default: True
  118. --device_target DEVICE_TARGET
  119. Ascend or GPU. Default: Ascend
  120. ```
  121. - eval parameters
  122. ```
  123. optional arguments:
  124. -h, --help show this help message and exit
  125. --checkpoint_path CHECKPOINT_PATH
  126. Checkpoint file path
  127. --dataset_path DATASET_PATH
  128. Dataset path
  129. --device_target DEVICE_TARGET
  130. Ascend or GPU. Default: Ascend
  131. ```
  132. ## [Training Process](#contents)
  133. ### Training
  134. - running on Ascend
  135. ```
  136. python train.py \
  137. --dataset_path='dataset/train' \
  138. --ckpt_path='./checkpoint' \
  139. --eval_file_name='auc.log' \
  140. --loss_file_name='loss.log' \
  141. --device_target='Ascend' \
  142. --do_eval=True > ms_log/output.log 2>&1 &
  143. ```
  144. The python command above will run in the background, you can view the results through the file `ms_log/output.log`.
  145. After training, you'll get some checkpoint files under `./checkpoint` folder by default. The loss value are saved in loss.log file.
  146. ```
  147. 2020-05-27 15:26:29 epoch: 1 step: 41257, loss is 0.498953253030777
  148. 2020-05-27 15:32:32 epoch: 2 step: 41257, loss is 0.45545706152915955
  149. ...
  150. ```
  151. The model checkpoint will be saved in the current directory.
  152. - running on GPU
  153. To do.
  154. ### Distributed Training
  155. - running on Ascend
  156. ```
  157. sh scripts/run_distribute_train.sh 8 /dataset_path /rank_table_8p.json
  158. ```
  159. 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.
  160. - running on GPU
  161. To do.
  162. ## [Evaluation Process](#contents)
  163. ### Evaluation
  164. - evaluation on dataset when running on Ascend
  165. Before running the command below, please check the checkpoint path used for evaluation.
  166. ```
  167. python eval.py \
  168. --dataset_path='dataset/test' \
  169. --checkpoint_path='./checkpoint/deepfm.ckpt' \
  170. --device_target='Ascend' > ms_log/eval_output.log 2>&1 &
  171. OR
  172. sh scripts/run_eval.sh 0 Ascend /dataset_path /checkpoint_path/deepfm.ckpt
  173. ```
  174. 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.
  175. ```
  176. {'result': {'AUC': 0.8057789065281104, 'eval_time': 35.64779996871948}}
  177. ```
  178. - evaluation on dataset when running on GPU
  179. To do.
  180. # [Model Description](#contents)
  181. ## [Performance](#contents)
  182. ### Evaluation Performance
  183. | Parameters | Ascend | GPU |
  184. | -------------------------- | ----------------------------------------------------------- | ---------------------- |
  185. | Model Version | DeepFM | To do |
  186. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 314G | To do |
  187. | uploaded Date | 05/17/2020 (month/day/year) | To do |
  188. | MindSpore Version | 0.3.0-alpha | To do |
  189. | Dataset | [1] | To do |
  190. | Training Parameters | epoch=15, batch_size=1000, lr=1e-5 | To do |
  191. | Optimizer | Adam | To do |
  192. | Loss Function | Sigmoid Cross Entropy With Logits | To do |
  193. | outputs | Accuracy | To do |
  194. | Loss | 0.45 | To do |
  195. | Speed | 1pc: 8.16 ms/step; | To do |
  196. | Total time | 1pc: 90 mins; | To do |
  197. | Parameters (M) | 16.5 | To do |
  198. | Checkpoint for Fine tuning | 190M (.ckpt file) | To do |
  199. | Scripts | [deepfm script](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/recommend/deepfm) | To do |
  200. ### Inference Performance
  201. | Parameters | Ascend | GPU |
  202. | ------------------- | --------------------------- | --------------------------- |
  203. | Model Version | DeepFM | To do |
  204. | Resource | Ascend 910 | To do |
  205. | Uploaded Date | 05/27/2020 (month/day/year) | To do |
  206. | MindSpore Version | 0.3.0-alpha | To do |
  207. | Dataset | [1] | To do |
  208. | batch_size | 1000 | To do |
  209. | outputs | accuracy | To do |
  210. | Accuracy | 1pc: 80.55%; | To do |
  211. | Model for inference | 190M (.ckpt file) | To do |
  212. # [Description of Random Situation](#contents)
  213. We set the random seed before training in train.py.
  214. # [ModelZoo Homepage](#contents)
  215. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).