Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
48a76c01
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
48a76c01
编写于
12月 01, 2018
作者:
Q
Qiao Longfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update reader to add feature extend mode
上级
ad7ba363
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
25 addition
and
6 deletion
+25
-6
fluid/PaddleRec/ctr/network_conf.py
fluid/PaddleRec/ctr/network_conf.py
+7
-3
fluid/PaddleRec/ctr/reader.py
fluid/PaddleRec/ctr/reader.py
+17
-2
fluid/PaddleRec/ctr/train.py
fluid/PaddleRec/ctr/train.py
+1
-1
未找到文件。
fluid/PaddleRec/ctr/network_conf.py
浏览文件 @
48a76c01
...
@@ -3,13 +3,17 @@ import math
...
@@ -3,13 +3,17 @@ import math
dense_feature_dim
=
13
dense_feature_dim
=
13
def
ctr_dnn_model
(
embedding_size
,
sparse_feature_dim
):
def
ctr_dnn_model
(
embedding_size
,
sparse_feature_dim
,
extend_id_range
=
False
):
dense_input
=
fluid
.
layers
.
data
(
dense_input
=
fluid
.
layers
.
data
(
name
=
"dense_input"
,
shape
=
[
dense_feature_dim
],
dtype
=
'float32'
)
name
=
"dense_input"
,
shape
=
[
dense_feature_dim
],
dtype
=
'float32'
)
sparse_feature_num
=
26
if
extend_id_range
:
sparse_feature_num
=
26
+
26
*
25
sparse_input_ids
=
[
sparse_input_ids
=
[
fluid
.
layers
.
data
(
fluid
.
layers
.
data
(
name
=
"C"
+
str
(
i
),
shape
=
[
1
],
lod_level
=
1
,
dtype
=
'int64'
)
name
=
"C"
+
str
(
i
),
shape
=
[
1
],
lod_level
=
1
,
dtype
=
'int64'
)
for
i
in
range
(
1
,
27
)
for
i
in
range
(
0
,
sparse_feature_num
)
]
]
def
embedding_layer
(
input
):
def
embedding_layer
(
input
):
...
@@ -18,7 +22,7 @@ def ctr_dnn_model(embedding_size, sparse_feature_dim):
...
@@ -18,7 +22,7 @@ def ctr_dnn_model(embedding_size, sparse_feature_dim):
is_sparse
=
True
,
is_sparse
=
True
,
# you need to patch https://github.com/PaddlePaddle/Paddle/pull/14190
# you need to patch https://github.com/PaddlePaddle/Paddle/pull/14190
# if you want to set is_distributed to True
# if you want to set is_distributed to True
is_distributed
=
Fals
e
,
is_distributed
=
Tru
e
,
size
=
[
sparse_feature_dim
,
embedding_size
],
size
=
[
sparse_feature_dim
,
embedding_size
],
param_attr
=
fluid
.
ParamAttr
(
name
=
"SparseFeatFactors"
,
initializer
=
fluid
.
initializer
.
Uniform
()))
param_attr
=
fluid
.
ParamAttr
(
name
=
"SparseFeatFactors"
,
initializer
=
fluid
.
initializer
.
Uniform
()))
...
...
fluid/PaddleRec/ctr/reader.py
浏览文件 @
48a76c01
...
@@ -2,12 +2,15 @@ class Dataset:
...
@@ -2,12 +2,15 @@ class Dataset:
def
__init__
(
self
):
def
__init__
(
self
):
pass
pass
class
CriteoDataset
(
Dataset
):
class
CriteoDataset
(
Dataset
):
def
__init__
(
self
,
sparse_feature_dim
):
def
__init__
(
self
,
sparse_feature_dim
,
fix_id_range
=
True
,
extend_id_range
=
False
):
self
.
cont_min_
=
[
0
,
-
3
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
self
.
cont_min_
=
[
0
,
-
3
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
self
.
cont_max_
=
[
20
,
600
,
100
,
50
,
64000
,
500
,
100
,
50
,
500
,
10
,
10
,
10
,
50
]
self
.
cont_max_
=
[
20
,
600
,
100
,
50
,
64000
,
500
,
100
,
50
,
500
,
10
,
10
,
10
,
50
]
self
.
cont_diff_
=
[
20
,
603
,
100
,
50
,
64000
,
500
,
100
,
50
,
500
,
10
,
10
,
10
,
50
]
self
.
cont_diff_
=
[
20
,
603
,
100
,
50
,
64000
,
500
,
100
,
50
,
500
,
10
,
10
,
10
,
50
]
self
.
hash_dim_
=
sparse_feature_dim
self
.
hash_dim_
=
sparse_feature_dim
self
.
fix_id_range_
=
fix_id_range
self
.
extend_id_range_
=
extend_id_range
# here, training data are lines with line_index < train_idx_
# here, training data are lines with line_index < train_idx_
self
.
train_idx_
=
41256555
self
.
train_idx_
=
41256555
self
.
continuous_range_
=
range
(
1
,
14
)
self
.
continuous_range_
=
range
(
1
,
14
)
...
@@ -35,7 +38,19 @@ class CriteoDataset(Dataset):
...
@@ -35,7 +38,19 @@ class CriteoDataset(Dataset):
else
:
else
:
dense_feature
.
append
((
float
(
features
[
idx
])
-
self
.
cont_min_
[
idx
-
1
])
/
self
.
cont_diff_
[
idx
-
1
])
dense_feature
.
append
((
float
(
features
[
idx
])
-
self
.
cont_min_
[
idx
-
1
])
/
self
.
cont_diff_
[
idx
-
1
])
for
idx
in
self
.
categorical_range_
:
for
idx
in
self
.
categorical_range_
:
sparse_feature
.
append
([
hash
(
"%d_%s"
%
(
idx
,
features
[
idx
]))
%
self
.
hash_dim_
])
feature_id
=
hash
(
"%d_%s"
%
(
idx
,
features
[
idx
]))
if
self
.
fix_id_range_
:
feature_id
=
feature_id
%
self
.
hash_dim_
sparse_feature
.
append
([
feature_id
])
if
self
.
extend_id_range_
:
for
i
in
range
(
len
(
self
.
categorical_range_
)):
for
j
in
range
(
i
+
1
,
len
(
self
.
categorical_range_
)):
idx1
=
self
.
categorical_range_
[
i
]
idx2
=
self
.
categorical_range_
[
j
]
feature_id
=
hash
(
"%d_%s_%d_%s"
%
(
idx1
,
features
[
idx1
],
idx2
,
features
[
idx2
]))
if
self
.
fix_id_range_
:
feature_id
=
feature_id
%
self
.
hash_dim_
sparse_feature
.
append
([
feature_id
])
label
=
[
int
(
features
[
0
])]
label
=
[
int
(
features
[
0
])]
yield
[
dense_feature
]
+
sparse_feature
+
[
label
]
yield
[
dense_feature
]
+
sparse_feature
+
[
label
]
...
...
fluid/PaddleRec/ctr/train.py
浏览文件 @
48a76c01
...
@@ -148,7 +148,7 @@ def train():
...
@@ -148,7 +148,7 @@ def train():
if
not
os
.
path
.
isdir
(
args
.
model_output_dir
):
if
not
os
.
path
.
isdir
(
args
.
model_output_dir
):
os
.
mkdir
(
args
.
model_output_dir
)
os
.
mkdir
(
args
.
model_output_dir
)
loss
,
data_list
,
auc_var
,
batch_auc_var
=
ctr_dnn_model
(
args
.
embedding_size
,
args
.
sparse_feature_dim
)
loss
,
data_list
,
auc_var
,
batch_auc_var
=
ctr_dnn_model
(
args
.
embedding_size
,
args
.
sparse_feature_dim
,
False
)
optimizer
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
1e-4
)
optimizer
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
1e-4
)
optimizer
.
minimize
(
loss
)
optimizer
.
minimize
(
loss
)
if
args
.
cloud_train
:
if
args
.
cloud_train
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录