Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
35905e00
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看板
提交
35905e00
编写于
10月 12, 2019
作者:
F
frankwhzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update gru4rec api
上级
80b01801
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
28 deletion
+29
-28
PaddleRec/gru4rec/net.py
PaddleRec/gru4rec/net.py
+28
-27
PaddleRec/gru4rec/utils.py
PaddleRec/gru4rec/utils.py
+1
-1
未找到文件。
PaddleRec/gru4rec/net.py
浏览文件 @
35905e00
...
...
@@ -10,12 +10,12 @@ def all_vocab_network(vocab_size,
gru_lr_x
=
1.0
fc_lr_x
=
1.0
# Input data
src_wordseq
=
fluid
.
layers
.
data
(
name
=
"src_wordseq"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
dst_wordseq
=
fluid
.
layers
.
data
(
name
=
"dst_wordseq"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
src_wordseq
=
fluid
.
data
(
name
=
"src_wordseq"
,
shape
=
[
None
,
1
],
dtype
=
"int64"
,
lod_level
=
1
)
dst_wordseq
=
fluid
.
data
(
name
=
"dst_wordseq"
,
shape
=
[
None
,
1
],
dtype
=
"int64"
,
lod_level
=
1
)
emb
=
fluid
.
layers
.
embedding
(
emb
=
fluid
.
embedding
(
input
=
src_wordseq
,
size
=
[
vocab_size
,
hid_size
],
param_attr
=
fluid
.
ParamAttr
(
...
...
@@ -56,13 +56,13 @@ def train_bpr_network(vocab_size, neg_size, hid_size, drop_out=0.2):
gru_lr_x
=
1.0
fc_lr_x
=
1.0
# Input data
src
=
fluid
.
layers
.
data
(
name
=
"src"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
pos_label
=
fluid
.
layers
.
data
(
name
=
"pos_label"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
neg_size
+
1
],
dtype
=
"int64"
,
lod_level
=
1
)
src
=
fluid
.
data
(
name
=
"src"
,
shape
=
[
None
,
1
],
dtype
=
"int64"
,
lod_level
=
1
)
pos_label
=
fluid
.
data
(
name
=
"pos_label"
,
shape
=
[
None
,
1
],
dtype
=
"int64"
,
lod_level
=
1
)
label
=
fluid
.
data
(
name
=
"label"
,
shape
=
[
None
,
neg_size
+
1
],
dtype
=
"int64"
,
lod_level
=
1
)
emb_src
=
fluid
.
layers
.
embedding
(
emb_src
=
fluid
.
embedding
(
input
=
src
,
size
=
[
vocab_size
,
hid_size
],
param_attr
=
fluid
.
ParamAttr
(
...
...
@@ -90,7 +90,7 @@ def train_bpr_network(vocab_size, neg_size, hid_size, drop_out=0.2):
gru_h0_drop
=
fluid
.
layers
.
dropout
(
gru_h0
,
dropout_prob
=
drop_out
)
label_re
=
fluid
.
layers
.
sequence_reshape
(
input
=
label
,
new_dim
=
1
)
emb_label
=
fluid
.
layers
.
embedding
(
emb_label
1
=
fluid
.
embedding
(
input
=
label_re
,
size
=
[
vocab_size
,
hid_size
],
param_attr
=
fluid
.
ParamAttr
(
...
...
@@ -98,6 +98,7 @@ def train_bpr_network(vocab_size, neg_size, hid_size, drop_out=0.2):
initializer
=
fluid
.
initializer
.
XavierInitializer
(),
learning_rate
=
emb_lr_x
))
emb_label
=
fluid
.
layers
.
squeeze
(
input
=
emb_label1
,
axes
=
[
1
])
emb_label_drop
=
fluid
.
layers
.
dropout
(
emb_label
,
dropout_prob
=
drop_out
)
gru_exp
=
fluid
.
layers
.
expand
(
...
...
@@ -120,13 +121,13 @@ def train_cross_entropy_network(vocab_size, neg_size, hid_size, drop_out=0.2):
gru_lr_x
=
1.0
fc_lr_x
=
1.0
# Input data
src
=
fluid
.
layers
.
data
(
name
=
"src"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
pos_label
=
fluid
.
layers
.
data
(
name
=
"pos_label"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
neg_size
+
1
],
dtype
=
"int64"
,
lod_level
=
1
)
src
=
fluid
.
data
(
name
=
"src"
,
shape
=
[
None
,
1
],
dtype
=
"int64"
,
lod_level
=
1
)
pos_label
=
fluid
.
data
(
name
=
"pos_label"
,
shape
=
[
None
,
1
],
dtype
=
"int64"
,
lod_level
=
1
)
label
=
fluid
.
data
(
name
=
"label"
,
shape
=
[
None
,
neg_size
+
1
],
dtype
=
"int64"
,
lod_level
=
1
)
emb_src
=
fluid
.
layers
.
embedding
(
emb_src
=
fluid
.
embedding
(
input
=
src
,
size
=
[
vocab_size
,
hid_size
],
param_attr
=
fluid
.
ParamAttr
(
...
...
@@ -154,13 +155,14 @@ def train_cross_entropy_network(vocab_size, neg_size, hid_size, drop_out=0.2):
gru_h0_drop
=
fluid
.
layers
.
dropout
(
gru_h0
,
dropout_prob
=
drop_out
)
label_re
=
fluid
.
layers
.
sequence_reshape
(
input
=
label
,
new_dim
=
1
)
emb_label
=
fluid
.
layers
.
embedding
(
emb_label
1
=
fluid
.
embedding
(
input
=
label_re
,
size
=
[
vocab_size
,
hid_size
],
param_attr
=
fluid
.
ParamAttr
(
name
=
"emb"
,
initializer
=
fluid
.
initializer
.
XavierInitializer
(),
learning_rate
=
emb_lr_x
))
emb_label
=
fluid
.
layers
.
squeeze
(
input
=
emb_label1
,
axes
=
[
1
])
emb_label_drop
=
fluid
.
layers
.
dropout
(
emb_label
,
dropout_prob
=
drop_out
)
...
...
@@ -180,8 +182,8 @@ def train_cross_entropy_network(vocab_size, neg_size, hid_size, drop_out=0.2):
def
infer_network
(
vocab_size
,
batch_size
,
hid_size
,
dropout
=
0.2
):
src
=
fluid
.
layers
.
data
(
name
=
"src"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
emb_src
=
fluid
.
layers
.
embedding
(
src
=
fluid
.
data
(
name
=
"src"
,
shape
=
[
None
,
1
],
dtype
=
"int64"
,
lod_level
=
1
)
emb_src
=
fluid
.
embedding
(
input
=
src
,
size
=
[
vocab_size
,
hid_size
],
param_attr
=
"emb"
)
emb_src_drop
=
fluid
.
layers
.
dropout
(
emb_src
,
dropout_prob
=
dropout
,
is_test
=
True
)
...
...
@@ -198,12 +200,11 @@ def infer_network(vocab_size, batch_size, hid_size, dropout=0.2):
gru_h0_drop
=
fluid
.
layers
.
dropout
(
gru_h0
,
dropout_prob
=
dropout
,
is_test
=
True
)
all_label
=
fluid
.
layers
.
data
(
all_label
=
fluid
.
data
(
name
=
"all_label"
,
shape
=
[
vocab_size
,
1
],
dtype
=
"int64"
,
append_batch_size
=
False
)
emb_all_label
=
fluid
.
layers
.
embedding
(
dtype
=
"int64"
)
emb_all_label
=
fluid
.
embedding
(
input
=
all_label
,
size
=
[
vocab_size
,
hid_size
],
param_attr
=
"emb"
)
emb_all_label_drop
=
fluid
.
layers
.
dropout
(
emb_all_label
,
dropout_prob
=
dropout
,
is_test
=
True
)
...
...
@@ -211,7 +212,7 @@ def infer_network(vocab_size, batch_size, hid_size, dropout=0.2):
all_pre
=
fluid
.
layers
.
matmul
(
gru_h0_drop
,
emb_all_label_drop
,
transpose_y
=
True
)
pos_label
=
fluid
.
layers
.
data
(
name
=
"pos_label"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
pos_label
=
fluid
.
data
(
name
=
"pos_label"
,
shape
=
[
None
,
1
],
dtype
=
"int64"
,
lod_level
=
1
)
acc
=
fluid
.
layers
.
accuracy
(
input
=
all_pre
,
label
=
pos_label
,
k
=
20
)
return
acc
PaddleRec/gru4rec/utils.py
浏览文件 @
35905e00
...
...
@@ -110,7 +110,7 @@ def prepare_data(file_dir,
batch_size
*
20
)
else
:
vocab_size
=
get_vocab_size
(
vocab_path
)
reader
=
paddle
.
batch
(
reader
=
paddle
.
io
.
batch
(
test
(
file_dir
,
buffer_size
,
data_type
=
DataType
.
SEQ
),
batch_size
)
return
vocab_size
,
reader
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录