Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
f4188f73
M
models
项目概览
PaddlePaddle
/
models
接近 2 年 前同步成功
通知
230
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看板
提交
f4188f73
编写于
1月 03, 2019
作者:
Z
zhangwenhui03
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix fc/gru bias parameter
上级
84edc6f7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
15 addition
and
11 deletion
+15
-11
fluid/PaddleRec/multiview_simnet/nets.py
fluid/PaddleRec/multiview_simnet/nets.py
+15
-11
未找到文件。
fluid/PaddleRec/multiview_simnet/nets.py
浏览文件 @
f4188f73
...
@@ -33,7 +33,7 @@ class CNNEncoder(object):
...
@@ -33,7 +33,7 @@ class CNNEncoder(object):
""" cnn-encoder"""
""" cnn-encoder"""
def
__init__
(
self
,
def
__init__
(
self
,
param_name
=
"cnn
.w
"
,
param_name
=
"cnn"
,
win_size
=
3
,
win_size
=
3
,
ksize
=
128
,
ksize
=
128
,
act
=
'tanh'
,
act
=
'tanh'
,
...
@@ -51,13 +51,15 @@ class CNNEncoder(object):
...
@@ -51,13 +51,15 @@ class CNNEncoder(object):
filter_size
=
self
.
win_size
,
filter_size
=
self
.
win_size
,
act
=
self
.
act
,
act
=
self
.
act
,
pool_type
=
self
.
pool_type
,
pool_type
=
self
.
pool_type
,
param_attr
=
str
(
self
.
param_name
))
param_attr
=
str
(
str
(
self
.
param_name
)
+
"_param"
),
bias_attr
=
str
(
str
(
self
.
param_name
)
+
"_bias"
))
class
GrnnEncoder
(
object
):
class
GrnnEncoder
(
object
):
""" grnn-encoder """
""" grnn-encoder """
def
__init__
(
self
,
param_name
=
"grnn
.w
"
,
hidden_size
=
128
):
def
__init__
(
self
,
param_name
=
"grnn"
,
hidden_size
=
128
):
self
.
param_name
=
param_name
self
.
param_name
=
param_name
self
.
hidden_size
=
hidden_size
self
.
hidden_size
=
hidden_size
...
@@ -65,13 +67,15 @@ class GrnnEncoder(object):
...
@@ -65,13 +67,15 @@ class GrnnEncoder(object):
fc0
=
nn
.
fc
(
fc0
=
nn
.
fc
(
input
=
emb
,
input
=
emb
,
size
=
self
.
hidden_size
*
3
,
size
=
self
.
hidden_size
*
3
,
param_attr
=
str
(
str
(
self
.
param_name
)
+
"_fc"
)
param_attr
=
str
(
str
(
self
.
param_name
)
+
"_fc.w"
),
bias_attr
=
str
(
str
(
self
.
param_name
)
+
"_fc.b"
)
)
)
gru_h
=
nn
.
dynamic_gru
(
gru_h
=
nn
.
dynamic_gru
(
input
=
fc0
,
input
=
fc0
,
size
=
self
.
hidden_size
,
size
=
self
.
hidden_size
,
is_reverse
=
False
,
is_reverse
=
False
,
param_attr
=
str
(
self
.
param_name
))
param_attr
=
str
(
str
(
self
.
param_name
)
+
".param"
),
bias_attr
=
str
(
str
(
self
.
param_name
)
+
".bias"
))
return
nn
.
sequence_pool
(
input
=
gru_h
,
pool_type
=
'max'
)
return
nn
.
sequence_pool
(
input
=
gru_h
,
pool_type
=
'max'
)
...
@@ -139,17 +143,17 @@ class MultiviewSimnet(object):
...
@@ -139,17 +143,17 @@ class MultiviewSimnet(object):
# lookup embedding for each slot
# lookup embedding for each slot
q_embs
=
[
q_embs
=
[
nn
.
embedding
(
nn
.
embedding
(
input
=
query
,
size
=
self
.
emb_shape
,
param_attr
=
"emb
.w
"
)
input
=
query
,
size
=
self
.
emb_shape
,
param_attr
=
"emb"
)
for
query
in
q_slots
for
query
in
q_slots
]
]
pt_embs
=
[
pt_embs
=
[
nn
.
embedding
(
nn
.
embedding
(
input
=
title
,
size
=
self
.
emb_shape
,
param_attr
=
"emb
.w
"
)
input
=
title
,
size
=
self
.
emb_shape
,
param_attr
=
"emb"
)
for
title
in
pt_slots
for
title
in
pt_slots
]
]
nt_embs
=
[
nt_embs
=
[
nn
.
embedding
(
nn
.
embedding
(
input
=
title
,
size
=
self
.
emb_shape
,
param_attr
=
"emb
.w
"
)
input
=
title
,
size
=
self
.
emb_shape
,
param_attr
=
"emb"
)
for
title
in
nt_slots
for
title
in
nt_slots
]
]
...
@@ -170,9 +174,9 @@ class MultiviewSimnet(object):
...
@@ -170,9 +174,9 @@ class MultiviewSimnet(object):
nt_concat
=
nn
.
concat
(
nt_encodes
)
nt_concat
=
nn
.
concat
(
nt_encodes
)
# projection of hidden layer
# projection of hidden layer
q_hid
=
nn
.
fc
(
q_concat
,
size
=
self
.
hidden_size
,
param_attr
=
'q_fc.w'
)
q_hid
=
nn
.
fc
(
q_concat
,
size
=
self
.
hidden_size
,
param_attr
=
'q_fc.w'
,
bias_attr
=
'q_fc.b'
)
pt_hid
=
nn
.
fc
(
pt_concat
,
size
=
self
.
hidden_size
,
param_attr
=
't_fc.w'
)
pt_hid
=
nn
.
fc
(
pt_concat
,
size
=
self
.
hidden_size
,
param_attr
=
't_fc.w'
,
bias_attr
=
't_fc.b'
)
nt_hid
=
nn
.
fc
(
nt_concat
,
size
=
self
.
hidden_size
,
param_attr
=
't_fc.w'
)
nt_hid
=
nn
.
fc
(
nt_concat
,
size
=
self
.
hidden_size
,
param_attr
=
't_fc.w'
,
bias_attr
=
't_fc.b'
)
# cosine of hidden layers
# cosine of hidden layers
cos_pos
=
nn
.
cos_sim
(
q_hid
,
pt_hid
)
cos_pos
=
nn
.
cos_sim
(
q_hid
,
pt_hid
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录