Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
5c6fc3f9
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5c6fc3f9
编写于
1月 24, 2018
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make TestLstmpOp inherit from TestLstmOp
上级
9ecc54a1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
11 addition
and
47 deletion
+11
-47
python/paddle/v2/fluid/tests/test_lstm_op.py
python/paddle/v2/fluid/tests/test_lstm_op.py
+3
-3
python/paddle/v2/fluid/tests/test_lstmp_op.py
python/paddle/v2/fluid/tests/test_lstmp_op.py
+8
-44
未找到文件。
python/paddle/v2/fluid/tests/test_lstm_op.py
浏览文件 @
5c6fc3f9
...
@@ -42,7 +42,7 @@ def relu(x):
...
@@ -42,7 +42,7 @@ def relu(x):
return
np
.
maximum
(
x
,
0
)
return
np
.
maximum
(
x
,
0
)
ACTVATION
=
{
ACT
I
VATION
=
{
'identity'
:
identity
,
'identity'
:
identity
,
'sigmoid'
:
sigmoid
,
'sigmoid'
:
sigmoid
,
'tanh'
:
tanh
,
'tanh'
:
tanh
,
...
@@ -158,8 +158,8 @@ class TestLstmOp(OpTest):
...
@@ -158,8 +158,8 @@ class TestLstmOp(OpTest):
w_b
=
b
[:,
0
:
4
*
self
.
D
]
w_b
=
b
[:,
0
:
4
*
self
.
D
]
w_c
=
b
[:,
4
*
self
.
D
:]
if
self
.
use_peepholes
else
None
w_c
=
b
[:,
4
*
self
.
D
:]
if
self
.
use_peepholes
else
None
h
,
c
=
lstm
(
x
,
self
.
lod
,
h0
,
c0
,
w
,
w_b
,
w_c
,
self
.
is_reverse
,
h
,
c
=
lstm
(
x
,
self
.
lod
,
h0
,
c0
,
w
,
w_b
,
w_c
,
self
.
is_reverse
,
ACT
VATION
[
self
.
act_gate
],
ACT
VATION
[
self
.
act_cell
],
ACT
IVATION
[
self
.
act_gate
],
ACTI
VATION
[
self
.
act_cell
],
ACTVATION
[
self
.
act_cand
])
ACT
I
VATION
[
self
.
act_cand
])
self
.
inputs
=
{
'Input'
:
(
x
,
self
.
lod
),
'Weight'
:
w
}
self
.
inputs
=
{
'Input'
:
(
x
,
self
.
lod
),
'Weight'
:
w
}
...
...
python/paddle/v2/fluid/tests/test_lstmp_op.py
浏览文件 @
5c6fc3f9
...
@@ -13,39 +13,13 @@
...
@@ -13,39 +13,13 @@
#limitations under the License.
#limitations under the License.
import
unittest
import
unittest
import
numpy
as
np
import
numpy
as
np
from
op_test
import
OpTest
import
test_lstm_op
as
LstmTest
SIGMOID_THRESHOLD_MIN
=
-
40.0
SIGMOID_THRESHOLD_MAX
=
13.0
EXP_MAX_INPUT
=
40.0
def
identity
(
x
):
return
x
def
sigmoid
(
x
):
y
=
np
.
copy
(
x
)
y
[
x
<
SIGMOID_THRESHOLD_MIN
]
=
SIGMOID_THRESHOLD_MIN
y
[
x
>
SIGMOID_THRESHOLD_MAX
]
=
SIGMOID_THRESHOLD_MAX
return
1.
/
(
1.
+
np
.
exp
(
-
y
))
def
tanh
(
x
):
y
=
-
2.
*
x
y
[
y
>
EXP_MAX_INPUT
]
=
EXP_MAX_INPUT
return
(
2.
/
(
1.
+
np
.
exp
(
y
)))
-
1.
def
relu
(
x
):
return
np
.
maximum
(
x
,
0
)
ACTIVATION
=
{
ACTIVATION
=
{
'identity'
:
identity
,
'identity'
:
LstmTest
.
identity
,
'sigmoid'
:
sigmoid
,
'sigmoid'
:
LstmTest
.
sigmoid
,
'tanh'
:
tanh
,
'tanh'
:
LstmTest
.
tanh
,
'relu'
:
relu
'relu'
:
LstmTest
.
relu
}
}
...
@@ -55,7 +29,7 @@ def lstmp(
...
@@ -55,7 +29,7 @@ def lstmp(
lod
,
# 1 x N
lod
,
# 1 x N
h0
=
None
,
# N x D
h0
=
None
,
# N x D
c0
=
None
,
# N x D
c0
=
None
,
# N x D
w_r
=
None
,
# P x
5
D
w_r
=
None
,
# P x
4
D
w_rh
=
None
,
# D x P
w_rh
=
None
,
# D x P
w_b
=
None
,
# 1 x 4D
w_b
=
None
,
# 1 x 4D
w_c
=
None
,
# 1 x 3D
w_c
=
None
,
# 1 x 3D
...
@@ -130,26 +104,16 @@ def lstmp(
...
@@ -130,26 +104,16 @@ def lstmp(
return
projection
,
cell
return
projection
,
cell
class
TestLstmpOp
(
OpTest
):
class
TestLstmpOp
(
LstmTest
.
TestLstmOp
):
def
reset_argument
(
self
):
def
reset_argument
(
self
):
pass
pass
def
setUp
(
self
):
def
setUp
(
self
):
self
.
lod
=
[[
0
,
2
,
5
,
7
]]
self
.
set_argument
()
# hidden size
self
.
D
=
16
# projection size
# projection size
self
.
P
=
10
self
.
P
=
10
self
.
act_gate
=
'sigmoid'
self
.
act_cell
=
'tanh'
self
.
act_cand
=
'tanh'
self
.
act_proj
=
self
.
act_cell
self
.
act_proj
=
self
.
act_cell
self
.
has_initial_state
=
False
self
.
is_reverse
=
False
self
.
use_peepholes
=
True
self
.
reset_argument
()
self
.
reset_argument
()
self
.
op_type
=
'lstmp'
self
.
op_type
=
'lstmp'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录