torch-rechub 0.0.1__tar.gz → 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/LICENSE +21 -21
  2. torch_rechub-0.0.3/PKG-INFO +177 -0
  3. torch_rechub-0.0.3/README.md +143 -0
  4. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/setup.cfg +4 -4
  5. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/setup.py +37 -35
  6. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub/basic/activation.py +54 -52
  7. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub/basic/callback.py +32 -32
  8. torch_rechub-0.0.3/torch_rechub/basic/features.py +94 -0
  9. torch_rechub-0.0.3/torch_rechub/basic/initializers.py +92 -0
  10. torch_rechub-0.0.3/torch_rechub/basic/layers.py +720 -0
  11. torch_rechub-0.0.3/torch_rechub/basic/loss_func.py +34 -0
  12. torch_rechub-0.0.3/torch_rechub/basic/metaoptimizer.py +72 -0
  13. torch_rechub-0.0.3/torch_rechub/basic/metric.py +250 -0
  14. torch_rechub-0.0.3/torch_rechub/models/matching/__init__.py +11 -0
  15. torch_rechub-0.0.3/torch_rechub/models/matching/comirec.py +188 -0
  16. torch_rechub-0.0.3/torch_rechub/models/matching/dssm.py +66 -0
  17. torch_rechub-0.0.3/torch_rechub/models/matching/dssm_facebook.py +79 -0
  18. torch_rechub-0.0.3/torch_rechub/models/matching/dssm_senet.py +75 -0
  19. torch_rechub-0.0.3/torch_rechub/models/matching/gru4rec.py +87 -0
  20. torch_rechub-0.0.3/torch_rechub/models/matching/mind.py +101 -0
  21. torch_rechub-0.0.3/torch_rechub/models/matching/narm.py +76 -0
  22. torch_rechub-0.0.3/torch_rechub/models/matching/sasrec.py +140 -0
  23. torch_rechub-0.0.3/torch_rechub/models/matching/sine.py +151 -0
  24. torch_rechub-0.0.3/torch_rechub/models/matching/stamp.py +83 -0
  25. torch_rechub-0.0.3/torch_rechub/models/matching/youtube_dnn.py +71 -0
  26. torch_rechub-0.0.3/torch_rechub/models/matching/youtube_sbc.py +98 -0
  27. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub/models/multi_task/__init__.py +5 -4
  28. torch_rechub-0.0.3/torch_rechub/models/multi_task/aitm.py +84 -0
  29. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub/models/multi_task/esmm.py +55 -45
  30. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub/models/multi_task/mmoe.py +58 -52
  31. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub/models/multi_task/ple.py +130 -104
  32. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub/models/multi_task/shared_bottom.py +45 -44
  33. torch_rechub-0.0.3/torch_rechub/models/ranking/__init__.py +11 -0
  34. torch_rechub-0.0.3/torch_rechub/models/ranking/afm.py +63 -0
  35. torch_rechub-0.0.3/torch_rechub/models/ranking/bst.py +63 -0
  36. torch_rechub-0.0.3/torch_rechub/models/ranking/dcn.py +38 -0
  37. torch_rechub-0.0.3/torch_rechub/models/ranking/dcn_v2.py +69 -0
  38. torch_rechub-0.0.3/torch_rechub/models/ranking/deepffm.py +123 -0
  39. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub/models/ranking/deepfm.py +41 -41
  40. torch_rechub-0.0.3/torch_rechub/models/ranking/dien.py +191 -0
  41. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub/models/ranking/din.py +91 -81
  42. torch_rechub-0.0.3/torch_rechub/models/ranking/edcn.py +117 -0
  43. torch_rechub-0.0.3/torch_rechub/models/ranking/fibinet.py +50 -0
  44. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub/models/ranking/widedeep.py +41 -41
  45. torch_rechub-0.0.3/torch_rechub/trainers/__init__.py +3 -0
  46. torch-rechub-0.0.1/torch_rechub/trainers/trainer.py → torch_rechub-0.0.3/torch_rechub/trainers/ctr_trainer.py +128 -111
  47. torch_rechub-0.0.3/torch_rechub/trainers/match_trainer.py +170 -0
  48. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub/trainers/mtl_trainer.py +206 -144
  49. torch_rechub-0.0.3/torch_rechub/utils/data.py +360 -0
  50. torch_rechub-0.0.3/torch_rechub/utils/match.py +274 -0
  51. torch_rechub-0.0.3/torch_rechub/utils/mtl.py +126 -0
  52. torch_rechub-0.0.3/torch_rechub.egg-info/PKG-INFO +177 -0
  53. torch_rechub-0.0.3/torch_rechub.egg-info/SOURCES.txt +58 -0
  54. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub.egg-info/requires.txt +2 -1
  55. torch-rechub-0.0.1/PKG-INFO +0 -100
  56. torch-rechub-0.0.1/README.md +0 -72
  57. torch-rechub-0.0.1/torch_rechub/basic/features.py +0 -57
  58. torch-rechub-0.0.1/torch_rechub/basic/layers.py +0 -240
  59. torch-rechub-0.0.1/torch_rechub/basic/utils.py +0 -168
  60. torch-rechub-0.0.1/torch_rechub/models/ranking/__init__.py +0 -3
  61. torch-rechub-0.0.1/torch_rechub/trainers/__init__.py +0 -2
  62. torch-rechub-0.0.1/torch_rechub.egg-info/PKG-INFO +0 -100
  63. torch-rechub-0.0.1/torch_rechub.egg-info/SOURCES.txt +0 -29
  64. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub/__init__.py +0 -0
  65. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub/basic/__init__.py +0 -0
  66. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub/models/__init__.py +0 -0
  67. {torch-rechub-0.0.1/torch_rechub/models/matching → torch_rechub-0.0.3/torch_rechub/utils}/__init__.py +0 -0
  68. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub.egg-info/dependency_links.txt +0 -0
  69. {torch-rechub-0.0.1 → torch_rechub-0.0.3}/torch_rechub.egg-info/top_level.txt +0 -0
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Mincai Lai
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Datawhale
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,177 @@
1
+ Metadata-Version: 2.1
2
+ Name: torch-rechub
3
+ Version: 0.0.3
4
+ Summary: A Lighting Pytorch Framework for Recommendation System, Easy-to-use and Easy-to-extend.
5
+ Home-page: https://github.com/datawhalechina/torch-rechub
6
+ Author: Datawhale
7
+ Author-email: laimc@shanghaitech.edu.cn
8
+ Keywords: ctr,click through rate,deep learning,pytorch,recsys,recommendation
9
+ Platform: all
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Intended Audience :: Education
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Classifier: Topic :: Software Development :: Libraries
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: License :: OSI Approved :: MIT License
25
+ Requires-Python: >=3.8
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: numpy>=1.19.0
29
+ Requires-Dist: torch>=1.7.0
30
+ Requires-Dist: pandas>=1.0.5
31
+ Requires-Dist: tqdm>=4.64.0
32
+ Requires-Dist: scikit_learn>=0.23.2
33
+ Requires-Dist: annoy>=1.17.0
34
+
35
+ # Torch-RecHub
36
+
37
+ <p align="left">
38
+ <img src='https://img.shields.io/badge/python-3.8+-brightgreen'>
39
+ <img src='https://img.shields.io/badge/torch-1.7+-brightgreen'>
40
+ <img src='https://img.shields.io/badge/scikit_learn-0.23.2+-brightgreen'>
41
+ <img src='https://img.shields.io/badge/pandas-1.0.5+-brightgreen'>
42
+ <img src='https://img.shields.io/badge/annoy-1.17.0-brightgreen'>
43
+ <img src="https://img.shields.io/pypi/l/torch-rechub">
44
+ <a href="https://github.com/datawhalechina/torch-rechub"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fdatawhalechina%2Ftorch-rechub&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false"/></a>
45
+
46
+ ## 中文Wiki站
47
+
48
+ 查看最新研发进度,认领感兴趣的研发任务,学习rechub模型复现心得,加入rechub共建者团队等
49
+
50
+ [点击链接](https://www.wolai.com/rechub/2qjdg3DPy1179e1vpcHZQC)
51
+
52
+ ## 安装
53
+
54
+ ```python
55
+ #稳定版
56
+ pip install torch-rechub
57
+
58
+ #最新版(推荐)
59
+ 1. git clone https://github.com/datawhalechina/torch-rechub.git
60
+ 2. cd torch-rechub
61
+ 3. python setup.py install
62
+ ```
63
+
64
+ ## 核心定位
65
+
66
+ 易用易拓展,聚焦复现业界实用的推荐模型,以及泛生态化的推荐场景
67
+
68
+ ## 主要特性
69
+
70
+ * scikit-learn风格易用的API(fit、predict),即插即用
71
+
72
+ * 模型训练与模型定义解耦,易拓展,可针对不同类型的模型设置不同的训练机制
73
+
74
+ * 接受pandas的DataFrame、Dict数据输入,上手成本低
75
+
76
+ * 高度模块化,支持常见Layer,容易调用组装成新模型
77
+
78
+ * LR、MLP、FM、FFM、CIN
79
+
80
+ * target-attention、self-attention、transformer
81
+
82
+ * 支持常见排序模型
83
+
84
+ * WideDeep、DeepFM、DIN、DCN、xDeepFM等
85
+
86
+ * 支持常见召回模型
87
+
88
+ * DSSM、YoutubeDNN、YoutubeDSSM、FacebookEBR、MIND等
89
+
90
+ * 丰富的多任务学习支持
91
+
92
+ * SharedBottom、ESMM、MMOE、PLE、AITM等模型
93
+
94
+ * GradNorm、UWL、MetaBanlance等动态loss加权机制
95
+
96
+ * 聚焦更生态化的推荐场景
97
+
98
+ - [ ] 冷启动
99
+
100
+ - [ ] 延迟反馈
101
+
102
+ * [ ] 去偏
103
+
104
+ * 支持丰富的训练机制
105
+
106
+ * [ ] 对比学习
107
+
108
+ * [ ] 蒸馏学习
109
+
110
+ * [ ] 第三方高性能开源Trainer支持(Pytorch Lighting)
111
+
112
+ * [ ] 更多模型正在开发中
113
+
114
+ ## 快速使用
115
+
116
+ ### 使用案例
117
+
118
+ - 所有模型使用案例参考 `/examples`
119
+
120
+ - 202206 Datawhale-RecHub推荐课程 组队学习期间notebook教程参考 `/tutorials`
121
+
122
+ ### 精排(CTR预测)
123
+
124
+ ```python
125
+ from torch_rechub.models.ranking import DeepFM
126
+ from torch_rechub.trainers import CTRTrainer
127
+ from torch_rechub.utils.data import DataGenerator
128
+
129
+ dg = DataGenerator(x, y)
130
+ train_dataloader, val_dataloader, test_dataloader = dg.generate_dataloader(split_ratio=[0.7, 0.1], batch_size=256)
131
+
132
+ model = DeepFM(deep_features=deep_features, fm_features=fm_features, mlp_params={"dims": [256, 128], "dropout": 0.2, "activation": "relu"})
133
+
134
+ ctr_trainer = CTRTrainer(model)
135
+ ctr_trainer.fit(train_dataloader, val_dataloader)
136
+ auc = ctr_trainer.evaluate(ctr_trainer.model, test_dataloader)
137
+ ```
138
+
139
+ ### 多任务排序
140
+
141
+ ```python
142
+ from torch_rechub.models.multi_task import SharedBottom, ESMM, MMOE, PLE, AITM
143
+ from torch_rechub.trainers import MTLTrainer
144
+
145
+ task_types = ["classification", "classification"]
146
+ model = MMOE(features, task_types, 8, expert_params={"dims": [32,16]}, tower_params_list=[{"dims": [32, 16]}, {"dims": [32, 16]}])
147
+
148
+ mtl_trainer = MTLTrainer(model)
149
+ mtl_trainer.fit(train_dataloader, val_dataloader)
150
+ auc = ctr_trainer.evaluate(ctr_trainer.model, test_dataloader)
151
+ ```
152
+
153
+ ### 召回模型
154
+
155
+ ```python
156
+ from torch_rechub.models.matching import DSSM
157
+ from torch_rechub.trainers import MatchTrainer
158
+ from torch_rechub.utils.data import MatchDataGenerator
159
+
160
+ dg = MatchDataGenerator(x y)
161
+ train_dl, test_dl, item_dl = dg.generate_dataloader(test_user, all_item, batch_size=256)
162
+
163
+ model = DSSM(user_features, item_features, temperature=0.02,
164
+ user_params={
165
+ "dims": [256, 128, 64],
166
+ "activation": 'prelu',
167
+ },
168
+ item_params={
169
+ "dims": [256, 128, 64],
170
+ "activation": 'prelu',
171
+ })
172
+
173
+ match_trainer = MatchTrainer(model)
174
+ match_trainer.fit(train_dl)
175
+
176
+ ```
177
+
@@ -0,0 +1,143 @@
1
+ # Torch-RecHub
2
+
3
+ <p align="left">
4
+ <img src='https://img.shields.io/badge/python-3.8+-brightgreen'>
5
+ <img src='https://img.shields.io/badge/torch-1.7+-brightgreen'>
6
+ <img src='https://img.shields.io/badge/scikit_learn-0.23.2+-brightgreen'>
7
+ <img src='https://img.shields.io/badge/pandas-1.0.5+-brightgreen'>
8
+ <img src='https://img.shields.io/badge/annoy-1.17.0-brightgreen'>
9
+ <img src="https://img.shields.io/pypi/l/torch-rechub">
10
+ <a href="https://github.com/datawhalechina/torch-rechub"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fdatawhalechina%2Ftorch-rechub&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false"/></a>
11
+
12
+ ## 中文Wiki站
13
+
14
+ 查看最新研发进度,认领感兴趣的研发任务,学习rechub模型复现心得,加入rechub共建者团队等
15
+
16
+ [点击链接](https://www.wolai.com/rechub/2qjdg3DPy1179e1vpcHZQC)
17
+
18
+ ## 安装
19
+
20
+ ```python
21
+ #稳定版
22
+ pip install torch-rechub
23
+
24
+ #最新版(推荐)
25
+ 1. git clone https://github.com/datawhalechina/torch-rechub.git
26
+ 2. cd torch-rechub
27
+ 3. python setup.py install
28
+ ```
29
+
30
+ ## 核心定位
31
+
32
+ 易用易拓展,聚焦复现业界实用的推荐模型,以及泛生态化的推荐场景
33
+
34
+ ## 主要特性
35
+
36
+ * scikit-learn风格易用的API(fit、predict),即插即用
37
+
38
+ * 模型训练与模型定义解耦,易拓展,可针对不同类型的模型设置不同的训练机制
39
+
40
+ * 接受pandas的DataFrame、Dict数据输入,上手成本低
41
+
42
+ * 高度模块化,支持常见Layer,容易调用组装成新模型
43
+
44
+ * LR、MLP、FM、FFM、CIN
45
+
46
+ * target-attention、self-attention、transformer
47
+
48
+ * 支持常见排序模型
49
+
50
+ * WideDeep、DeepFM、DIN、DCN、xDeepFM等
51
+
52
+ * 支持常见召回模型
53
+
54
+ * DSSM、YoutubeDNN、YoutubeDSSM、FacebookEBR、MIND等
55
+
56
+ * 丰富的多任务学习支持
57
+
58
+ * SharedBottom、ESMM、MMOE、PLE、AITM等模型
59
+
60
+ * GradNorm、UWL、MetaBanlance等动态loss加权机制
61
+
62
+ * 聚焦更生态化的推荐场景
63
+
64
+ - [ ] 冷启动
65
+
66
+ - [ ] 延迟反馈
67
+
68
+ * [ ] 去偏
69
+
70
+ * 支持丰富的训练机制
71
+
72
+ * [ ] 对比学习
73
+
74
+ * [ ] 蒸馏学习
75
+
76
+ * [ ] 第三方高性能开源Trainer支持(Pytorch Lighting)
77
+
78
+ * [ ] 更多模型正在开发中
79
+
80
+ ## 快速使用
81
+
82
+ ### 使用案例
83
+
84
+ - 所有模型使用案例参考 `/examples`
85
+
86
+ - 202206 Datawhale-RecHub推荐课程 组队学习期间notebook教程参考 `/tutorials`
87
+
88
+ ### 精排(CTR预测)
89
+
90
+ ```python
91
+ from torch_rechub.models.ranking import DeepFM
92
+ from torch_rechub.trainers import CTRTrainer
93
+ from torch_rechub.utils.data import DataGenerator
94
+
95
+ dg = DataGenerator(x, y)
96
+ train_dataloader, val_dataloader, test_dataloader = dg.generate_dataloader(split_ratio=[0.7, 0.1], batch_size=256)
97
+
98
+ model = DeepFM(deep_features=deep_features, fm_features=fm_features, mlp_params={"dims": [256, 128], "dropout": 0.2, "activation": "relu"})
99
+
100
+ ctr_trainer = CTRTrainer(model)
101
+ ctr_trainer.fit(train_dataloader, val_dataloader)
102
+ auc = ctr_trainer.evaluate(ctr_trainer.model, test_dataloader)
103
+ ```
104
+
105
+ ### 多任务排序
106
+
107
+ ```python
108
+ from torch_rechub.models.multi_task import SharedBottom, ESMM, MMOE, PLE, AITM
109
+ from torch_rechub.trainers import MTLTrainer
110
+
111
+ task_types = ["classification", "classification"]
112
+ model = MMOE(features, task_types, 8, expert_params={"dims": [32,16]}, tower_params_list=[{"dims": [32, 16]}, {"dims": [32, 16]}])
113
+
114
+ mtl_trainer = MTLTrainer(model)
115
+ mtl_trainer.fit(train_dataloader, val_dataloader)
116
+ auc = ctr_trainer.evaluate(ctr_trainer.model, test_dataloader)
117
+ ```
118
+
119
+ ### 召回模型
120
+
121
+ ```python
122
+ from torch_rechub.models.matching import DSSM
123
+ from torch_rechub.trainers import MatchTrainer
124
+ from torch_rechub.utils.data import MatchDataGenerator
125
+
126
+ dg = MatchDataGenerator(x y)
127
+ train_dl, test_dl, item_dl = dg.generate_dataloader(test_user, all_item, batch_size=256)
128
+
129
+ model = DSSM(user_features, item_features, temperature=0.02,
130
+ user_params={
131
+ "dims": [256, 128, 64],
132
+ "activation": 'prelu',
133
+ },
134
+ item_params={
135
+ "dims": [256, 128, 64],
136
+ "activation": 'prelu',
137
+ })
138
+
139
+ match_trainer = MatchTrainer(model)
140
+ match_trainer.fit(train_dl)
141
+
142
+ ```
143
+
@@ -1,4 +1,4 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -1,35 +1,37 @@
1
- from distutils.core import setup
2
- from setuptools import find_packages
3
-
4
- with open("README.md", "r") as f:
5
- long_description = f.read()
6
-
7
- setup(
8
- name='torch-rechub', # 包名
9
- version='0.0.1', # 版本号
10
- description='A Lighting Pytorch Framework for Recommendation System, Easy-to-use and Easy-to-extend.',
11
- long_description=long_description,
12
- long_description_content_type="text/markdown",
13
- author='Mincai lai',
14
- author_email='757387961@qq.com',
15
- url='https://github.com/morningsky/Torch-RecHub',
16
- install_requires=['numpy>=1.21.5', 'torch>=1.7.0', 'pandas>=1.0.5', 'tqdm>=4.64.0', 'scikit_learn>=0.23.2'],
17
- packages=find_packages(),
18
- platforms=["all"],
19
- classifiers=[
20
- 'Intended Audience :: Developers',
21
- "Intended Audience :: Education",
22
- "Intended Audience :: Science/Research",
23
- 'Operating System :: OS Independent',
24
- 'Programming Language :: Python :: 3',
25
- 'Programming Language :: Python :: 3.7',
26
- 'Programming Language :: Python :: 3.8',
27
- 'Programming Language :: Python :: 3.9',
28
- 'Topic :: Scientific/Engineering',
29
- 'Topic :: Scientific/Engineering :: Artificial Intelligence',
30
- 'Topic :: Software Development :: Libraries',
31
- 'Topic :: Software Development :: Libraries :: Python Modules',
32
- 'License :: OSI Approved :: MIT License',
33
- ],
34
- keywords=['ctr', 'click through rate', 'deep learning', 'pytorch', 'recsys', 'recommendation'],
35
- )
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r", encoding='utf-8') as f:
4
+ long_description = f.read()
5
+
6
+ setup(
7
+ name='torch-rechub',
8
+ version='0.0.3',
9
+ description='A Lighting Pytorch Framework for Recommendation System, Easy-to-use and Easy-to-extend.',
10
+ long_description=long_description,
11
+ long_description_content_type="text/markdown",
12
+ author='Datawhale',
13
+ author_email='laimc@shanghaitech.edu.cn',
14
+ url='https://github.com/datawhalechina/torch-rechub',
15
+ install_requires=['numpy>=1.19.0', 'torch>=1.7.0', 'pandas>=1.0.5', 'tqdm>=4.64.0', 'scikit_learn>=0.23.2', 'annoy>=1.17.0'],
16
+ packages=find_packages(),
17
+ platforms=["all"],
18
+ classifiers=[
19
+ 'Intended Audience :: Developers',
20
+ "Intended Audience :: Education",
21
+ "Intended Audience :: Science/Research",
22
+ 'Operating System :: OS Independent',
23
+ 'Programming Language :: Python :: 3',
24
+ 'Programming Language :: Python :: 3.8',
25
+ 'Programming Language :: Python :: 3.9',
26
+ 'Programming Language :: Python :: 3.10',
27
+ 'Programming Language :: Python :: 3.11',
28
+ 'Programming Language :: Python :: 3.12',
29
+ 'Topic :: Scientific/Engineering',
30
+ 'Topic :: Scientific/Engineering :: Artificial Intelligence',
31
+ 'Topic :: Software Development :: Libraries',
32
+ 'Topic :: Software Development :: Libraries :: Python Modules',
33
+ 'License :: OSI Approved :: MIT License',
34
+ ],
35
+ keywords=['ctr', 'click through rate', 'deep learning', 'pytorch', 'recsys', 'recommendation'],
36
+ python_requires='>=3.8',
37
+ )
@@ -1,52 +1,54 @@
1
- import torch
2
- import torch.nn as nn
3
-
4
-
5
- class Dice(nn.Module):
6
- """The Dice activation function mentioned in the `DIN paper
7
- https://arxiv.org/abs/1706.06978`
8
- """
9
-
10
- def __init__(self, epsilon=1e-3):
11
- super(Dice, self).__init__()
12
- self.epsilon = epsilon
13
- self.alpha = nn.Parameter(torch.randn(1))
14
-
15
- def forward(self, x: torch.Tensor):
16
- # x: N * num_neurons
17
- avg = x.mean(dim=1) # N
18
- avg = avg.unsqueeze(dim=1) # N * 1
19
- var = torch.pow(x - avg, 2) + self.epsilon # N * num_neurons
20
- var = var.sum(dim=1).unsqueeze(dim=1) # N * 1
21
-
22
- ps = (x - avg) / torch.sqrt(var) # N * 1
23
-
24
- ps = nn.Sigmoid()(ps) # N * 1
25
- return ps * x + (1 - ps) * self.alpha * x
26
-
27
-
28
- def activation_layer(act_name):
29
- """Construct activation layers
30
-
31
- Args:
32
- act_name: str or nn.Module, name of activation function
33
-
34
- Returns:
35
- act_layer: activation layer
36
- """
37
- if isinstance(act_name, str):
38
- if act_name.lower() == 'sigmoid':
39
- act_layer = nn.Sigmoid()
40
- elif act_name.lower() == 'relu':
41
- act_layer = nn.ReLU(inplace=True)
42
- elif act_name.lower() == 'dice':
43
- act_layer = Dice()
44
- elif act_name.lower() == 'prelu':
45
- act_layer = nn.PReLU()
46
- elif act_name.lower() == "softmax":
47
- act_layer = nn.Softmax(dim=1)
48
- elif issubclass(act_name, nn.Module):
49
- act_layer = act_name()
50
- else:
51
- raise NotImplementedError
52
- return act_layer
1
+ import torch
2
+ import torch.nn as nn
3
+
4
+
5
+ class Dice(nn.Module):
6
+ """The Dice activation function mentioned in the `DIN paper
7
+ https://arxiv.org/abs/1706.06978`
8
+ """
9
+
10
+ def __init__(self, epsilon=1e-3):
11
+ super(Dice, self).__init__()
12
+ self.epsilon = epsilon
13
+ self.alpha = nn.Parameter(torch.randn(1))
14
+
15
+ def forward(self, x: torch.Tensor):
16
+ # x: N * num_neurons
17
+ avg = x.mean(dim=1) # N
18
+ avg = avg.unsqueeze(dim=1) # N * 1
19
+ var = torch.pow(x - avg, 2) + self.epsilon # N * num_neurons
20
+ var = var.sum(dim=1).unsqueeze(dim=1) # N * 1
21
+
22
+ ps = (x - avg) / torch.sqrt(var) # N * 1
23
+
24
+ ps = nn.Sigmoid()(ps) # N * 1
25
+ return ps * x + (1 - ps) * self.alpha * x
26
+
27
+
28
+ def activation_layer(act_name):
29
+ """Construct activation layers
30
+
31
+ Args:
32
+ act_name: str or nn.Module, name of activation function
33
+
34
+ Returns:
35
+ act_layer: activation layer
36
+ """
37
+ if isinstance(act_name, str):
38
+ if act_name.lower() == 'sigmoid':
39
+ act_layer = nn.Sigmoid()
40
+ elif act_name.lower() == 'relu':
41
+ act_layer = nn.ReLU(inplace=True)
42
+ elif act_name.lower() == 'dice':
43
+ act_layer = Dice()
44
+ elif act_name.lower() == 'prelu':
45
+ act_layer = nn.PReLU()
46
+ elif act_name.lower() == "softmax":
47
+ act_layer = nn.Softmax(dim=1)
48
+ elif act_name.lower() == 'leakyrelu':
49
+ act_layer = nn.LeakyReLU()
50
+ elif issubclass(act_name, nn.Module):
51
+ act_layer = act_name()
52
+ else:
53
+ raise NotImplementedError
54
+ return act_layer
@@ -1,33 +1,33 @@
1
- import copy
2
-
3
-
4
- class EarlyStopper(object):
5
- """Early stops the training if validation loss doesn't improve after a given patience.
6
-
7
- Args:
8
- patience (int): How long to wait after last time validation auc improved.
9
- """
10
-
11
- def __init__(self, patience):
12
- self.patience = patience
13
- self.trial_counter = 0
14
- self.best_auc = 0
15
- self.best_weights = None
16
-
17
- def stop_training(self, val_auc, weights):
18
- """whether to stop training.
19
-
20
- Args:
21
- val_auc (float): auc score in val data.
22
- weights (tensor): the weights of model
23
- """
24
- if val_auc > self.best_auc:
25
- self.best_auc = val_auc
26
- self.trial_counter = 0
27
- self.best_weights = copy.deepcopy(weights)
28
- return False
29
- elif self.trial_counter + 1 < self.patience:
30
- self.trial_counter += 1
31
- return False
32
- else:
1
+ import copy
2
+
3
+
4
+ class EarlyStopper(object):
5
+ """Early stops the training if validation loss doesn't improve after a given patience.
6
+
7
+ Args:
8
+ patience (int): How long to wait after last time validation auc improved.
9
+ """
10
+
11
+ def __init__(self, patience):
12
+ self.patience = patience
13
+ self.trial_counter = 0
14
+ self.best_auc = 0
15
+ self.best_weights = None
16
+
17
+ def stop_training(self, val_auc, weights):
18
+ """whether to stop training.
19
+
20
+ Args:
21
+ val_auc (float): auc score in val data.
22
+ weights (tensor): the weights of model
23
+ """
24
+ if val_auc > self.best_auc:
25
+ self.best_auc = val_auc
26
+ self.trial_counter = 0
27
+ self.best_weights = copy.deepcopy(weights)
28
+ return False
29
+ elif self.trial_counter + 1 < self.patience:
30
+ self.trial_counter += 1
31
+ return False
32
+ else:
33
33
  return True