Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
305de2d0
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看板
提交
305de2d0
编写于
1月 24, 2019
作者:
W
wangsijiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add deepmf nn
上级
6494c6fc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
172 addition
and
0 deletion
+172
-0
fluid/PaddleRec/ctr/deepmf_conf.py
fluid/PaddleRec/ctr/deepmf_conf.py
+117
-0
fluid/PaddleRec/ctr/network_conf.py
fluid/PaddleRec/ctr/network_conf.py
+55
-0
未找到文件。
fluid/PaddleRec/ctr/deepmf_conf.py
0 → 100644
浏览文件 @
305de2d0
import
paddle.fluid
as
fluid
import
math
dense_feature_dim
=
13
user_dense_feature_dim
=
13
item_dense_feature_dim
=
13
## text cnn conf
WORD_SIZE
=
100000
EMBED_SIZE
=
64
CNN_DIM
=
128
CNN_FILTER_SIZE
=
5
def
text_cnn
(
word
):
"""
"""
embed
=
fluid
.
layers
.
embedding
(
input
=
word
,
size
=
[
WORD_SIZE
,
EMBED_SIZE
],
dtype
=
'float32'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
1
/
math
.
sqrt
(
WORD_SIZE
))),
is_sparse
=
IS_SPARSE
,
is_distributed
=
False
)
cnn
=
fluid
.
nets
.
sequence_conv_pool
(
input
=
embed
,
num_filters
=
CNN_DIM
,
filter_size
=
CNN_FILTER_SIZE
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
1
/
math
.
sqrt
(
CNN_FILTER_SIZE
*
embed
.
shape
[
1
]))),
act
=
'tanh'
,
pool_type
=
"max"
)
return
cnn
def
deepmf_ctr_model
(
embedding_size
,
sparse_feature_dim
):
def
embedding_layer
(
input
):
return
fluid
.
layers
.
embedding
(
input
=
input
,
is_sparse
=
True
,
# you need to patch https://github.com/PaddlePaddle/Paddle/pull/14190
# if you want to set is_distributed to True
is_distributed
=
False
,
size
=
[
sparse_feature_dim
,
embedding_size
],
param_attr
=
fluid
.
ParamAttr
(
name
=
"SparseFeatFactors"
,
initializer
=
fluid
.
initializer
.
Uniform
()))
user_dense_input
=
fluid
.
layers
.
data
(
name
=
"dense_input"
,
shape
=
[
user_dense_feature_dim
],
dtype
=
'float32'
)
user_sparse_input_ids
=
[
fluid
.
layers
.
data
(
name
=
"USER"
+
str
(
i
),
shape
=
[
1
],
lod_level
=
1
,
dtype
=
'int64'
)
for
i
in
range
(
1
,
user_sparse_slot_num
)]
item_dense_input
=
fluid
.
layers
.
data
(
name
=
"dense_input"
,
shape
=
[
item_dense_feature_dim
],
dtype
=
'float32'
)
item_sparse_input_ids
=
[
fluid
.
layers
.
data
(
name
=
"ITEM"
+
str
(
i
),
shape
=
[
1
],
lod_level
=
1
,
dtype
=
'int64'
)
for
i
in
range
(
1
,
item_sparse_slot_num
)]
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
datas
=
[
user_dense_input
]
+
[
item_dense_input
]
+
user_sparse_input_ids
+
item_sparse_input_ids
+
[
label
]
py_reader
=
fluid
.
layers
.
create_py_reader_by_data
(
capacity
=
64
,
feed_list
=
datas
,
name
=
'py_reader'
,
use_double_buffer
=
True
)
words
=
fluid
.
layers
.
read_file
(
py_reader
)
user_sparse_embed_seq
=
list
(
map
(
embedding_layer
,
words
[
2
:
user_sparse_slot_num
+
2
]))
item_sparse_embed_seq
=
list
(
map
(
embedding_layer
,
words
[
user_sparse_slot_num
+
2
:
user_sparse_slot_num
+
item_sparse_slot_num
+
2
]))
user_concated
=
fluid
.
layers
.
concat
(
user_sparse_embed_seq
+
words
[
0
:
1
],
axis
=
1
)
item_concated
=
fluid
.
layers
.
concat
(
item_sparse_embed_seq
+
words
[
1
:
2
],
axis
=
1
)
user_fc1
=
fluid
.
layers
.
fc
(
input
=
user_concated
,
size
=
400
,
act
=
'relu'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
1
/
math
.
sqrt
(
concated
.
shape
[
1
]))))
user_fc2
=
fluid
.
layers
.
fc
(
input
=
fc1
,
size
=
128
,
act
=
'relu'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
1
/
math
.
sqrt
(
fc1
.
shape
[
1
]))))
user_fc3
=
fluid
.
layers
.
fc
(
input
=
fc2
,
size
=
64
,
act
=
'tanh'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
1
/
math
.
sqrt
(
fc2
.
shape
[
1
]))))
item_fc1
=
fluid
.
layers
.
fc
(
input
=
user_concated
,
size
=
400
,
act
=
'relu'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
1
/
math
.
sqrt
(
concated
.
shape
[
1
]))))
item_fc2
=
fluid
.
layers
.
fc
(
input
=
fc1
,
size
=
128
,
act
=
'relu'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
1
/
math
.
sqrt
(
fc1
.
shape
[
1
]))))
item_fc3
=
fluid
.
layers
.
fc
(
input
=
fc2
,
size
=
64
,
act
=
'tanh'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
1
/
math
.
sqrt
(
fc2
.
shape
[
1
]))))
sim
=
fluid
.
layers
.
cos_sim
(
X
=
user_fc3
,
Y
=
item_fc3
)
predict
=
fluid
.
layers
.
fc
(
input
=
sim
,
size
=
2
,
act
=
'softmax'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
1
/
math
.
sqrt
(
fc3
.
shape
[
1
]))))
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
predict
,
label
=
words
[
-
1
])
avg_cost
=
fluid
.
layers
.
reduce_sum
(
cost
)
accuracy
=
fluid
.
layers
.
accuracy
(
input
=
predict
,
label
=
words
[
-
1
])
auc_var
,
batch_auc_var
,
auc_states
=
\
fluid
.
layers
.
auc
(
input
=
predict
,
label
=
words
[
-
1
],
num_thresholds
=
2
**
12
,
slide_steps
=
20
)
return
avg_cost
,
auc_var
,
batch_auc_var
,
py_reader
fluid/PaddleRec/ctr/network_conf.py
浏览文件 @
305de2d0
...
@@ -33,6 +33,61 @@ def text_cnn(word):
...
@@ -33,6 +33,61 @@ def text_cnn(word):
return
cnn
return
cnn
def
deepmf_ctr_model
(
embedding_size
,
sparse_feature_dim
):
def
embedding_layer
(
input
):
return
fluid
.
layers
.
embedding
(
input
=
input
,
is_sparse
=
True
,
# you need to patch https://github.com/PaddlePaddle/Paddle/pull/14190
# if you want to set is_distributed to True
is_distributed
=
False
,
size
=
[
sparse_feature_dim
,
embedding_size
],
param_attr
=
fluid
.
ParamAttr
(
name
=
"SparseFeatFactors"
,
initializer
=
fluid
.
initializer
.
Uniform
()))
dense_input
=
fluid
.
layers
.
data
(
name
=
"dense_input"
,
shape
=
[
dense_feature_dim
],
dtype
=
'float32'
)
sparse_input_ids
=
[
fluid
.
layers
.
data
(
name
=
"C"
+
str
(
i
),
shape
=
[
1
],
lod_level
=
1
,
dtype
=
'int64'
)
for
i
in
range
(
1
,
27
)]
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
datas
=
[
dense_input
]
+
sparse_input_ids
+
[
label
]
py_reader
=
fluid
.
layers
.
create_py_reader_by_data
(
capacity
=
64
,
feed_list
=
datas
,
name
=
'py_reader'
,
use_double_buffer
=
True
)
words
=
fluid
.
layers
.
read_file
(
py_reader
)
sparse_embed_seq
=
list
(
map
(
embedding_layer
,
words
[
1
:
-
1
]))
concated
=
fluid
.
layers
.
concat
(
sparse_embed_seq
+
words
[
0
:
1
],
axis
=
1
)
fc1
=
fluid
.
layers
.
fc
(
input
=
concated
,
size
=
400
,
act
=
'relu'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
1
/
math
.
sqrt
(
concated
.
shape
[
1
]))))
fc2
=
fluid
.
layers
.
fc
(
input
=
fc1
,
size
=
400
,
act
=
'relu'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
1
/
math
.
sqrt
(
fc1
.
shape
[
1
]))))
fc3
=
fluid
.
layers
.
fc
(
input
=
fc2
,
size
=
400
,
act
=
'relu'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
1
/
math
.
sqrt
(
fc2
.
shape
[
1
]))))
predict
=
fluid
.
layers
.
fc
(
input
=
fc3
,
size
=
2
,
act
=
'softmax'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
1
/
math
.
sqrt
(
fc3
.
shape
[
1
]))))
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
predict
,
label
=
words
[
-
1
])
avg_cost
=
fluid
.
layers
.
reduce_sum
(
cost
)
accuracy
=
fluid
.
layers
.
accuracy
(
input
=
predict
,
label
=
words
[
-
1
])
auc_var
,
batch_auc_var
,
auc_states
=
\
fluid
.
layers
.
auc
(
input
=
predict
,
label
=
words
[
-
1
],
num_thresholds
=
2
**
12
,
slide_steps
=
20
)
return
avg_cost
,
auc_var
,
batch_auc_var
,
py_reader
def
ctr_deepfm_model
(
factor_size
,
sparse_feature_dim
,
dense_feature_dim
,
sparse_input
):
def
ctr_deepfm_model
(
factor_size
,
sparse_feature_dim
,
dense_feature_dim
,
sparse_input
):
def
dense_fm_layer
(
input
,
emb_dict_size
,
factor_size
,
fm_param_attr
):
def
dense_fm_layer
(
input
,
emb_dict_size
,
factor_size
,
fm_param_attr
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录