18
18
实现特征预处理,本文介绍结构化数据特征预处理方案。
19
19
- 开发了 Parameter Server 的分布式训练框架,支持在 Kubernetes 上对 worker
20
20
进行弹性调度。在资源不足的情况下,能快速开始训练任务,缩短模型迭代等待时间。
21
- 详细见 [ ElasticDL:同时提升研发效率和机群利用率] ( ./elasticdl-antfin-introduction.md )
21
+ 详细见
22
+ [ ElasticDL:同时提升研发效率和机群利用率] ( ./elasticdl-antfin-introduction.md )
22
23
23
24
## 深度学习中结构化数据的特征预处理
24
25
25
26
在对结构化数据进行深度学习建模时,常需要将数据转换成更适合深度学习算法训练的格
26
27
式,常见的特征变换方式有:
27
28
28
29
- 对数值型特征进行[ 标准化] ( https://en.wikipedia.org/wiki/Feature_scaling#Standardization_(Z-score_Normalization) )
29
- 变换。
30
- - 对数值型特征进行[ 分桶] ( https://en.wikipedia.org/wiki/Data_binning ) 变换,
31
- 输出特征值所在分桶的整数序号 。
32
- - 对字符型特征进行[ 哈希] ( https://en.wikipedia.org/wiki/Hash_function )
33
- 分桶变换, 即对字符串进行哈希后对桶数取模,映射成整数输出。
30
+ 变换。
31
+ - 对数值型特征进行[ 分桶] ( https://en.wikipedia.org/wiki/Data_binning ) 变换,输出特
32
+ 征值所在分桶的整数序号 。
33
+ - 对字符型特征进行[ 哈希] ( https://en.wikipedia.org/wiki/Hash_function ) 分桶变换,
34
+ 即对字符串进行哈希后对桶数取模,映射成整数输出。
34
35
- 对字符型特征进行查词表变换,输出词在词表中的整数序号。
35
36
36
37
然而在特征变换之前,需要对数据集进行统计分析,得到特征的全局统计量。利用全
@@ -86,7 +87,8 @@ ElasticDL 支持分布式训练 Keras 模型,为了方便用户将特征预处
86
87
| IndexLookup | 将字符串通过查词表转成整数,输出词所在词表的索引 | 特征值集合(词表) |
87
88
88
89
特征变换 layer 的使用教程请查看
89
- [ Preprocess Inputs using ElasticDL Preprocessing Layers] ( https://github.com/sql-machine-learning/elasticdl/blob/develop/docs/tutorials/preprocessing_tutorial.md )
90
+ [ Preprocess Inputs using ElasticDL Preprocessing
91
+ Layers] ( https://github.com/sql-machine-learning/elasticdl/blob/develop/docs/tutorials/preprocessing_tutorial.md )
90
92
91
93
### Keras 模型训练定义
92
94
@@ -104,19 +106,16 @@ def custom_model():
104
106
outputs = tf.keras.layers.Dense(3 , name = " output" )(x)
105
107
return tf.keras.Model(inputs = inputs, outputs = outputs, name = " simple-model" )
106
108
107
-
108
109
def loss (labels , predictions ):
109
110
return tf.reduce_mean(
110
111
tf.nn.sparse_softmax_cross_entropy_with_logits(
111
112
tf.cast(tf.reshape(labels, [- 1 ]), tf.int32), predictions
112
113
)
113
114
)
114
115
115
-
116
116
def optimizer (lr = 0.1 ):
117
117
return tf.optimizers.SGD(lr)
118
118
119
-
120
119
def eval_metrics_fn ():
121
120
return {
122
121
" accuracy" : lambda labels , predictions : tf.equal(
@@ -125,7 +124,6 @@ def eval_metrics_fn():
125
124
)
126
125
}
127
126
128
-
129
127
def dataset_fn (dataset , mode , metadata ):
130
128
def _parse_data (record ):
131
129
features = tf.strings.to_number(record[0 :- 1 ], tf.float32)
@@ -136,22 +134,28 @@ def dataset_fn(dataset, mode, metadata):
136
134
return dataset
137
135
```
138
136
139
- 模型定义完成后,在ElasticDL提供的基础镜像中,放入模型文件生成新的镜像,即可在 PAI 平台上提交分布式训练。
137
+ 模型定义完成后,在ElasticDL提供的基础镜像中,放入模型文件生成新的镜像,即可在
138
+ PAI 平台上提交分布式训练。
140
139
141
140
## PAI 平台上集成特征预处理的 DeepCTR 算法
142
141
143
- 为了让用户能快速将 ElasticDL 应用到真实业务场景,ElasticDL 在 [ PAI] ( https://pai.alipay.com )
142
+ 为了让用户能快速将 ElasticDL 应用到真实业务场景,ElasticDL 在
143
+ [ PAI] ( https://pai.alipay.com )
144
144
平台上提供了 ElasticDL-DeepCTR 组件,如下图所示:
145
145
146
146
![ PAI ElasticDL DeepCTR] ( ../images/pai_gui/pai_elasticdl_deepctr.jpg )
147
147
148
148
该算法组件有如下特点:
149
149
150
- - 根据用户配置的特征来自动生成特征预处理逻辑,并与深度学习 CTR 算法相结合,组成完整的模型。
151
- - 提供了常用的 CTR 预估算法,包括 Wide & Deep, DeepFM, Deep Cross Network 和 xDeepFM。
152
- - 分布式策略采用 ParameterServer,可以根据数据量来配置 worker 的数量来加速模型训练。
150
+ - 根据用户配置的特征来自动生成特征预处理逻辑,并与深度学习 CTR
151
+ 算法相结合,组成完整的模型。
152
+ - 提供了常用的 CTR 预估算法,包括 Wide & Deep, DeepFM, Deep Cross Network 和
153
+ xDeepFM。
154
+ - 分布式策略采用 ParameterServer,可以根据数据量来配置 worker
155
+ 的数量来加速模型训练。
153
156
154
- 为了验证模型性能,我们选用了 [ Kaggle Display Advertising Challenge] ( https://www.kaggle.com/c/criteo-display-ad-challenge )
157
+ 为了验证模型性能,我们选用了 [ Kaggle Display Advertising
158
+ Challenge] ( https://www.kaggle.com/c/criteo-display-ad-challenge )
155
159
的数据集,来测试模型性能。将组件的标准化特征列和分箱特征列都配置成 I0-I13,
156
160
哈希特征列配置成 C0-C13,最终使用 xDeepFM 模型的 logloss 为
157
161
0.45634 (Kaggle best logloss: 0.44463)。通过很简单的配置,
0 commit comments