Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
6732a284
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看板
未验证
提交
6732a284
编写于
2月 07, 2020
作者:
Z
zhang wenhui
提交者:
GitHub
2月 07, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix gru_dygraph (#4248)
* fix gru_dygraph * fix mmoe doc
上级
f9853b7f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
47 addition
and
21 deletion
+47
-21
PaddleRec/gru4rec/dy_graph/README.md
PaddleRec/gru4rec/dy_graph/README.md
+8
-0
PaddleRec/gru4rec/dy_graph/gru4rec_dy.py
PaddleRec/gru4rec/dy_graph/gru4rec_dy.py
+19
-11
PaddleRec/multi-task/MMoE/README.md
PaddleRec/multi-task/MMoE/README.md
+3
-0
PaddleRec/multi-task/MMoE/mmoe_train.py
PaddleRec/multi-task/MMoE/mmoe_train.py
+17
-10
未找到文件。
PaddleRec/gru4rec/dy_graph/README.md
浏览文件 @
6732a284
# gru4rec 动态图实现
# 环境配置
paddle 1.7
# 下载数据
```
wget https://paddlerec.bj.bcebos.com/gru4rec/dy_graph/data_rsc15.tar
tar xvf data_rsc15.tar
```
# 数据格式
数据格式及预处理处理同静态图相同。
# 训练及预测
```
...
...
PaddleRec/gru4rec/dy_graph/gru4rec_dy.py
浏览文件 @
6732a284
...
...
@@ -21,6 +21,7 @@ import paddle.fluid.core as core
from
paddle.fluid.dygraph.nn
import
Embedding
import
paddle.fluid.framework
as
framework
from
paddle.fluid.optimizer
import
SGDOptimizer
from
paddle.fluid.optimizer
import
AdagradOptimizer
from
paddle.fluid.dygraph.base
import
to_variable
import
numpy
as
np
import
six
...
...
@@ -67,7 +68,7 @@ class SimpleGRURNN(fluid.Layer):
dtype
=
"float32"
,
default_initializer
=
fluid
.
initializer
.
UniformInitializer
(
low
=-
self
.
_init_scale
,
high
=
self
.
_init_scale
))
self
.
weight_1_arr
.
append
(
self
.
add_parameter
(
'w_%d'
%
i
,
weight_1
))
self
.
weight_1_arr
.
append
(
self
.
add_parameter
(
'w
1
_%d'
%
i
,
weight_1
))
weight_2
=
self
.
create_parameter
(
attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
UniformInitializer
(
...
...
@@ -76,7 +77,7 @@ class SimpleGRURNN(fluid.Layer):
dtype
=
"float32"
,
default_initializer
=
fluid
.
initializer
.
UniformInitializer
(
low
=-
self
.
_init_scale
,
high
=
self
.
_init_scale
))
self
.
weight_2_arr
.
append
(
self
.
add_parameter
(
'w_%d'
%
i
,
weight_2
))
self
.
weight_2_arr
.
append
(
self
.
add_parameter
(
'w
2
_%d'
%
i
,
weight_2
))
weight_3
=
self
.
create_parameter
(
attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
UniformInitializer
(
...
...
@@ -85,7 +86,7 @@ class SimpleGRURNN(fluid.Layer):
dtype
=
"float32"
,
default_initializer
=
fluid
.
initializer
.
UniformInitializer
(
low
=-
self
.
_init_scale
,
high
=
self
.
_init_scale
))
self
.
weight_3_arr
.
append
(
self
.
add_parameter
(
'w_%d'
%
i
,
weight_3
))
self
.
weight_3_arr
.
append
(
self
.
add_parameter
(
'w
3
_%d'
%
i
,
weight_3
))
bias_1
=
self
.
create_parameter
(
attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
UniformInitializer
(
...
...
@@ -93,7 +94,7 @@ class SimpleGRURNN(fluid.Layer):
shape
=
[
self
.
_hidden_size
*
2
],
dtype
=
"float32"
,
default_initializer
=
fluid
.
initializer
.
Constant
(
0.0
))
self
.
bias_1_arr
.
append
(
self
.
add_parameter
(
'b_%d'
%
i
,
bias_1
))
self
.
bias_1_arr
.
append
(
self
.
add_parameter
(
'b
1
_%d'
%
i
,
bias_1
))
bias_2
=
self
.
create_parameter
(
attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
UniformInitializer
(
...
...
@@ -101,7 +102,7 @@ class SimpleGRURNN(fluid.Layer):
shape
=
[
self
.
_hidden_size
*
1
],
dtype
=
"float32"
,
default_initializer
=
fluid
.
initializer
.
Constant
(
0.0
))
self
.
bias_2_arr
.
append
(
self
.
add_parameter
(
'b_%d'
%
i
,
bias_2
))
self
.
bias_2_arr
.
append
(
self
.
add_parameter
(
'b
2
_%d'
%
i
,
bias_2
))
def
forward
(
self
,
input_embedding
,
init_hidden
=
None
):
hidden_array
=
[]
...
...
@@ -278,10 +279,10 @@ def train_ptb_lm():
init_scale
=
0.1
max_grad_norm
=
5.0
epoch_start_decay
=
10
max_epoch
=
3
max_epoch
=
5
dropout
=
0.0
lr_decay
=
0.5
base_learning_rate
=
1.0
base_learning_rate
=
0.05
elif
model_type
==
"medium"
:
num_layers
=
2
batch_size
=
20
...
...
@@ -353,15 +354,22 @@ def train_ptb_lm():
log_interval
=
total_batch_size
//
20
bd
=
[]
lr_arr
=
[
1.0
]
lr_arr
=
[
base_learning_rate
]
for
i
in
range
(
1
,
max_epoch
):
bd
.
append
(
total_batch_size
*
i
)
new_lr
=
base_learning_rate
*
(
lr_decay
**
max
(
i
+
1
-
epoch_start_decay
,
0.0
))
lr_arr
.
append
(
new_lr
)
sgd
=
SGDOptimizer
(
learning_rate
=
fluid
.
layers
.
piecewise_decay
(
boundaries
=
bd
,
values
=
lr_arr
))
sgd
=
AdagradOptimizer
(
parameter_list
=
ptb_model
.
parameters
(),
learning_rate
=
fluid
.
layers
.
piecewise_decay
(
boundaries
=
bd
,
values
=
lr_arr
))
print
(
"parameters:--------------------------------"
)
for
para
in
ptb_model
.
parameters
():
print
(
para
.
name
)
print
(
"parameters:--------------------------------"
)
def
eval
(
model
,
data
):
print
(
"begion to eval"
)
...
...
@@ -450,7 +458,7 @@ def train_ptb_lm():
print
(
"Saved model to: %s.
\n
"
%
save_model_dir
)
eval
(
ptb_model
,
test_data
)
eval
(
ptb_model
,
test_data
)
#
eval(ptb_model, test_data)
train_ptb_lm
()
PaddleRec/multi-task/MMoE/README.md
浏览文件 @
6732a284
...
...
@@ -8,6 +8,9 @@ MMoE是经典的多任务(multi-task)模型,原论文[Modeling Task Relati
我们基于实际工业界场景实现了MMoE的核心思想。
## 配置
1.
6 及以上
## 数据
我们采用了随机数据作为训练数据,可以根据自己的数据调整data部分。
...
...
PaddleRec/multi-task/MMoE/mmoe_train.py
浏览文件 @
6732a284
import
paddle.fluid
as
fluid
import
numpy
as
np
dict_dim
=
1000
emb_dim
=
64
import
time
from
args
import
*
def
fc_layers
(
input
,
layers
,
acts
,
prefix
):
...
...
@@ -59,7 +58,7 @@ def mmoe_layer(inputs, expert_num=8, gate_num=3):
return
outs
def
model
():
def
model
(
dict_dim
,
emb_dim
):
label_like
=
fluid
.
layers
.
data
(
name
=
"label_like"
,
shape
=
[
-
1
,
1
],
...
...
@@ -116,13 +115,18 @@ def model():
return
cost
,
[
a_data
,
label_like
,
label_comment
,
label_share
]
batch_size
=
5
args
=
parse_args
()
batch_size
=
args
.
batch_size
dict_dim
=
args
.
dict_dim
emb_dim
=
args
.
emb_dim
print
(
"batch_size:[%d], dict_dim:[%d], emb_dim:[%d], learning_rate:[%.4f]"
%
(
batch_size
,
dict_dim
,
emb_dim
,
args
.
base_lr
))
loss
,
data_list
=
model
()
sgd
=
fluid
.
optimizer
.
SGD
(
learning_rate
=
0.001
)
loss
,
data_list
=
model
(
dict_dim
,
emb_dim
)
sgd
=
fluid
.
optimizer
.
SGD
(
learning_rate
=
args
.
base_lr
)
sgd
.
minimize
(
loss
)
use_cuda
=
True
place
=
fluid
.
CUDAPlace
(
0
)
if
use_cuda
else
fluid
.
CPUPlace
()
place
=
fluid
.
CUDAPlace
(
0
)
if
args
.
use_gpu
else
fluid
.
CPUPlace
()
feeder
=
fluid
.
DataFeeder
(
feed_list
=
data_list
,
place
=
place
)
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
fluid
.
default_startup_program
())
...
...
@@ -131,6 +135,7 @@ for batch_id in range(100):
np
.
random
.
randint
(
2
,
size
=
(
batch_size
,
1
)).
astype
(
'int64'
)
for
i
in
range
(
4
)
]
begin
=
time
.
time
()
loss_data
,
=
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
{
"a"
:
data
[
0
],
...
...
@@ -139,4 +144,6 @@ for batch_id in range(100):
"label_share"
:
data
[
3
]
},
fetch_list
=
[
loss
.
name
])
print
(
batch_id
,
" loss:"
,
float
(
np
.
array
(
loss_data
)))
end
=
time
.
time
()
print
(
"batch_id:[%d], loss:[%.5f], batch_time:[%.5f s]"
%
(
batch_id
,
float
(
np
.
array
(
loss_data
)),
end
-
begin
))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录