Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
e0a34dae
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e0a34dae
编写于
8月 19, 2020
作者:
H
huangxinjing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adjust the dense structure in the wide&deep multi-table
上级
3259dafa
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
33 addition
and
17 deletion
+33
-17
model_zoo/official/recommend/wide_and_deep_multitable/src/config.py
...official/recommend/wide_and_deep_multitable/src/config.py
+2
-1
model_zoo/official/recommend/wide_and_deep_multitable/src/wide_and_deep.py
...l/recommend/wide_and_deep_multitable/src/wide_and_deep.py
+27
-13
model_zoo/official/recommend/wide_and_deep_multitable/train_and_eval_distribute.py
...end/wide_and_deep_multitable/train_and_eval_distribute.py
+4
-3
未找到文件。
model_zoo/official/recommend/wide_and_deep_multitable/src/config.py
浏览文件 @
e0a34dae
...
...
@@ -32,6 +32,7 @@ def argparse_init():
parser
.
add_argument
(
"--ftrl_lr"
,
type
=
float
,
default
=
0.1
)
# The ftrl lr.
parser
.
add_argument
(
"--l2_coef"
,
type
=
float
,
default
=
0.0
)
# The l2 coefficient.
parser
.
add_argument
(
"--is_tf_dataset"
,
type
=
bool
,
default
=
True
)
# The l2 coefficient.
parser
.
add_argument
(
"--dropout_flag"
,
type
=
int
,
default
=
1
)
# The dropout rate
parser
.
add_argument
(
"--output_path"
,
type
=
str
,
default
=
"./output/"
)
# The location of the output file.
parser
.
add_argument
(
"--ckpt_path"
,
type
=
str
,
default
=
"./checkpoints/"
)
# The location of the checkpoints file.
...
...
@@ -83,7 +84,6 @@ class WideDeepConfig():
self
.
weight_bias_init
=
[
'normal'
,
'normal'
]
self
.
emb_init
=
'normal'
self
.
init_args
=
[
-
0.01
,
0.01
]
self
.
dropout_flag
=
False
self
.
l2_coef
=
args
.
l2_coef
self
.
ftrl_lr
=
args
.
ftrl_lr
self
.
adam_lr
=
args
.
adam_lr
...
...
@@ -93,3 +93,4 @@ class WideDeepConfig():
self
.
eval_file_name
=
args
.
eval_file_name
self
.
loss_file_name
=
args
.
loss_file_name
self
.
ckpt_path
=
args
.
ckpt_path
self
.
dropout_flag
=
bool
(
args
.
dropout_flag
)
model_zoo/official/recommend/wide_and_deep_multitable/src/wide_and_deep.py
浏览文件 @
e0a34dae
...
...
@@ -89,9 +89,11 @@ class DenseLayer(nn.Cell):
output_dim
,
weight_bias_init
,
act_str
,
keep_prob
=
0.
7
,
keep_prob
=
0.
8
,
scale_coef
=
1.0
,
convert_dtype
=
True
):
use_activation
=
True
,
convert_dtype
=
True
,
drop_out
=
False
):
super
(
DenseLayer
,
self
).
__init__
()
weight_init
,
bias_init
=
weight_bias_init
self
.
weight
=
init_method
(
weight_init
,
[
input_dim
,
output_dim
],
...
...
@@ -101,11 +103,13 @@ class DenseLayer(nn.Cell):
self
.
matmul
=
P
.
MatMul
(
transpose_b
=
False
)
self
.
bias_add
=
P
.
BiasAdd
()
self
.
cast
=
P
.
Cast
()
self
.
dropout
=
Dropout
(
keep_prob
=
0.8
)
self
.
dropout
=
Dropout
(
keep_prob
=
keep_prob
)
self
.
mul
=
P
.
Mul
()
self
.
realDiv
=
P
.
RealDiv
()
self
.
scale_coef
=
scale_coef
self
.
use_activation
=
use_activation
self
.
convert_dtype
=
convert_dtype
self
.
drop_out
=
drop_out
def
_init_activation
(
self
,
act_str
):
act_str
=
act_str
.
lower
()
...
...
@@ -118,23 +122,26 @@ class DenseLayer(nn.Cell):
return
act_func
def
construct
(
self
,
x
):
"""
DenseLayer construct
"""
x
=
self
.
act_func
(
x
)
if
self
.
training
:
'''
Construct Dense layer
'''
if
self
.
training
and
self
.
drop_out
:
x
=
self
.
dropout
(
x
)
x
=
self
.
mul
(
x
,
self
.
scale_coef
)
if
self
.
convert_dtype
:
x
=
self
.
cast
(
x
,
mstype
.
float16
)
weight
=
self
.
cast
(
self
.
weight
,
mstype
.
float16
)
bias
=
self
.
cast
(
self
.
bias
,
mstype
.
float16
)
wx
=
self
.
matmul
(
x
,
weight
)
wx
=
self
.
bias_add
(
wx
,
bias
)
if
self
.
use_activation
:
wx
=
self
.
act_func
(
wx
)
wx
=
self
.
cast
(
wx
,
mstype
.
float32
)
else
:
wx
=
self
.
matmul
(
x
,
self
.
weight
)
wx
=
self
.
realDiv
(
wx
,
self
.
scale_coef
)
output
=
self
.
bias_add
(
wx
,
self
.
bias
)
return
output
wx
=
self
.
bias_add
(
wx
,
self
.
bias
)
if
self
.
use_activation
:
wx
=
self
.
act_func
(
wx
)
return
wx
class
WideDeepModel
(
nn
.
Cell
):
...
...
@@ -211,33 +218,40 @@ class WideDeepModel(nn.Cell):
self
.
all_dim_list
[
1
],
self
.
weight_bias_init
,
self
.
deep_layer_act
,
drop_out
=
config
.
dropout_flag
,
convert_dtype
=
True
)
self
.
dense_layer_2
=
DenseLayer
(
self
.
all_dim_list
[
1
],
self
.
all_dim_list
[
2
],
self
.
weight_bias_init
,
self
.
deep_layer_act
,
drop_out
=
config
.
dropout_flag
,
convert_dtype
=
True
)
self
.
dense_layer_3
=
DenseLayer
(
self
.
all_dim_list
[
2
],
self
.
all_dim_list
[
3
],
self
.
weight_bias_init
,
self
.
deep_layer_act
,
drop_out
=
config
.
dropout_flag
,
convert_dtype
=
True
)
self
.
dense_layer_4
=
DenseLayer
(
self
.
all_dim_list
[
3
],
self
.
all_dim_list
[
4
],
self
.
weight_bias_init
,
self
.
deep_layer_act
,
drop_out
=
config
.
dropout_flag
,
convert_dtype
=
True
)
self
.
dense_layer_5
=
DenseLayer
(
self
.
all_dim_list
[
4
],
self
.
all_dim_list
[
5
],
self
.
weight_bias_init
,
self
.
deep_layer_act
,
drop_out
=
config
.
dropout_flag
,
convert_dtype
=
True
)
self
.
deep_predict
=
DenseLayer
(
self
.
all_dim_list
[
5
],
self
.
all_dim_list
[
6
],
self
.
weight_bias_init
,
self
.
deep_layer_act
,
convert_dtype
=
True
)
drop_out
=
config
.
dropout_flag
,
convert_dtype
=
True
,
use_activation
=
False
)
self
.
gather_v2
=
P
.
GatherV2
()
self
.
mul
=
P
.
Mul
()
...
...
model_zoo/official/recommend/wide_and_deep_multitable/train_and_eval_distribute.py
浏览文件 @
e0a34dae
...
...
@@ -96,9 +96,10 @@ def train_and_eval(config):
keep_checkpoint_max
=
10
)
ckpoint_cb
=
ModelCheckpoint
(
prefix
=
'widedeep_train'
,
directory
=
config
.
ckpt_path
,
config
=
ckptconfig
)
model
.
train
(
epochs
,
ds_train
,
callbacks
=
[
TimeMonitor
(
ds_train
.
get_dataset_size
()),
eval_callback
,
callback
,
ckpoint_cb
])
callback_list
=
[
TimeMonitor
(
ds_train
.
get_dataset_size
()),
eval_callback
,
callback
]
if
int
(
get_rank
())
==
0
:
callback_list
.
append
(
ckpoint_cb
)
model
.
train
(
epochs
,
ds_train
,
callbacks
=
callback_list
)
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录