Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
db1bb822
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
db1bb822
编写于
10月 26, 2017
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
follow comments
上级
8e3ecf5d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
28 addition
and
31 deletion
+28
-31
paddle/operators/math/context_project.h
paddle/operators/math/context_project.h
+3
-6
paddle/operators/sequence_conv_op.cc
paddle/operators/sequence_conv_op.cc
+13
-13
paddle/operators/sequence_conv_op.h
paddle/operators/sequence_conv_op.h
+8
-8
python/paddle/v2/framework/tests/test_seq_conv.py
python/paddle/v2/framework/tests/test_seq_conv.py
+4
-4
未找到文件。
paddle/operators/math/context_project.h
浏览文件 @
db1bb822
...
...
@@ -34,18 +34,15 @@ using EigenMatrix = framework::EigenMatrix<T, MajorType, IndexType>;
* \param in Input data.
* \param Shape The shape of Input data,
* [minibatch, number_of_input_features].
* \param type A float LoDTensor.
* [minibatch, input_hidden_size].
*
* \param padding_data Padding data.
* \param Shape The shape of Padding data,
* [up_pad + down_pad, number_of_input_features].
* \param type A float Tensor.
* [up_pad + down_pad, input_hidden_size].
*
* \param col Col data.
* \param Shape The shape of Col data,
* [minibatch, context_length * number_of_input_features].
* \param type A float Tensor.
* [minibatch, context_length * input_hidden_size].
*
* For a mini-batch of 2 variable lengths sentences, containing 3, and 1
* time-steps:
...
...
paddle/operators/sequence_conv_op.cc
浏览文件 @
db1bb822
...
...
@@ -30,9 +30,9 @@ class SequenceConvOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"Output(Out) of SequenceConvOp should not be null."
);
int
context_length
=
ctx
->
Attrs
().
Get
<
int
>
(
"context
_l
ength"
);
bool
padding_trainable
=
ctx
->
Attrs
().
Get
<
bool
>
(
"padding
_t
rainable"
);
int
context_start
=
ctx
->
Attrs
().
Get
<
int
>
(
"context
_s
tart"
);
int
context_length
=
ctx
->
Attrs
().
Get
<
int
>
(
"context
L
ength"
);
bool
padding_trainable
=
ctx
->
Attrs
().
Get
<
bool
>
(
"padding
T
rainable"
);
int
context_start
=
ctx
->
Attrs
().
Get
<
int
>
(
"context
S
tart"
);
auto
in_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
filter_dims
=
ctx
->
GetInputDim
(
"Filter"
);
...
...
@@ -54,7 +54,7 @@ class SequenceConvOp : public framework::OperatorWithKernel {
if
(
context_start
==
0
&&
context_length
==
1
)
{
PADDLE_THROW
(
"If context_start is 0 and context_length is 1, padding
_t
rainable "
"If context_start is 0 and context_length is 1, padding
T
rainable "
"should be false."
);
}
PADDLE_ENFORCE
(
padding_dim
.
size
()
==
2
,
...
...
@@ -81,7 +81,7 @@ class SequenceConvGradOp : public framework::OperatorWithKernel {
"Gradient of output(Out) should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"The input(X) should not be null."
);
if
(
ctx
->
Attrs
().
Get
<
bool
>
(
"padding
_t
rainable"
)
&&
if
(
ctx
->
Attrs
().
Get
<
bool
>
(
"padding
T
rainable"
)
&&
ctx
->
HasOutput
(
framework
::
GradVarName
(
"PaddingData"
)))
{
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"PaddingData"
),
ctx
->
GetInputDim
(
"PaddingData"
));
...
...
@@ -128,25 +128,25 @@ class SequenceConvOpMaker : public framework::OpProtoAndCheckerMaker {
"this LoDTensor is a matrix with shape (T, D), where, T is the "
"total time steps in this mini-batch, D is the output feature size."
);
AddAttr
<
bool
>
(
"padding
_t
rainable"
,
AddAttr
<
bool
>
(
"padding
T
rainable"
,
"(bool, default false) the padding data of SequenceConvOp "
"is trainable or not."
)
.
SetDefault
(
false
);
AddAttr
<
int
>
(
"context
_l
ength"
,
"(int, default 3) the context
_l
ength of SequenceConvOp is the "
AddAttr
<
int
>
(
"context
L
ength"
,
"(int, default 3) the context
L
ength of SequenceConvOp is the "
"height of the convolution kernel."
)
.
SetDefault
(
3
)
.
GreaterThan
(
0
);
AddAttr
<
int
>
(
"context
_s
tart"
,
"(int, default 0) the context
_s
tart of SequenceConvOp "
AddAttr
<
int
>
(
"context
S
tart"
,
"(int, default 0) the context
S
tart of SequenceConvOp "
"represents the beginning of the convolution of the number of "
"rows of sequence, which can be negative."
)
.
SetDefault
(
0
);
AddAttr
<
int
>
(
"context
_s
tride"
,
"(int, default 1) the context
_s
tride of SequenceConvOp "
AddAttr
<
int
>
(
"context
S
tride"
,
"(int, default 1) the context
S
tride of SequenceConvOp "
"represents the step length of convolution. "
"Currently, SequenceConvOp only supports"
"context
_s
tride=1."
)
"context
S
tride=1."
)
.
SetDefault
(
1
)
.
GreaterThan
(
0
);
...
...
paddle/operators/sequence_conv_op.h
浏览文件 @
db1bb822
...
...
@@ -35,10 +35,10 @@ class SequenceConvKernel : public framework::OpKernel<T> {
out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
context
.
ShareLoD
(
"X"
,
"Out"
);
int
context_start
=
context
.
Attr
<
int
>
(
"context
_s
tart"
);
int
context_length
=
context
.
Attr
<
int
>
(
"context
_l
ength"
);
int
context_stride
=
context
.
Attr
<
int
>
(
"context
_s
tride"
);
bool
padding_trainable
=
context
.
Attr
<
bool
>
(
"padding
_t
rainable"
);
int
context_start
=
context
.
Attr
<
int
>
(
"context
S
tart"
);
int
context_length
=
context
.
Attr
<
int
>
(
"context
L
ength"
);
int
context_stride
=
context
.
Attr
<
int
>
(
"context
S
tride"
);
bool
padding_trainable
=
context
.
Attr
<
bool
>
(
"padding
T
rainable"
);
// InferShape by in_lod
PADDLE_ENFORCE_EQ
(
in
->
lod
().
size
(),
1UL
,
...
...
@@ -89,10 +89,10 @@ class SequenceConvGradKernel : public framework::OpKernel<T> {
auto
*
in
=
context
.
Input
<
LoDTensor
>
(
"X"
);
auto
*
filter
=
context
.
Input
<
Tensor
>
(
"Filter"
);
int
context_start
=
context
.
Attr
<
int
>
(
"context
_s
tart"
);
int
context_length
=
context
.
Attr
<
int
>
(
"context
_l
ength"
);
int
context_stride
=
context
.
Attr
<
int
>
(
"context
_s
tride"
);
bool
padding_trainable
=
context
.
Attr
<
bool
>
(
"padding
_t
rainable"
);
int
context_start
=
context
.
Attr
<
int
>
(
"context
S
tart"
);
int
context_length
=
context
.
Attr
<
int
>
(
"context
L
ength"
);
int
context_stride
=
context
.
Attr
<
int
>
(
"context
S
tride"
);
bool
padding_trainable
=
context
.
Attr
<
bool
>
(
"padding
T
rainable"
);
PADDLE_ENFORCE_EQ
(
in
->
lod
().
size
(),
1UL
,
"Only support one level sequence now."
);
...
...
python/paddle/v2/framework/tests/test_seq_conv.py
浏览文件 @
db1bb822
...
...
@@ -45,10 +45,10 @@ class TestSeqProject(OpTest):
self
.
inputs_val_no_f
=
[
'PaddingData'
,
'X'
]
self
.
attrs
=
{
'context
_s
tart'
:
self
.
context_start
,
'context
_l
ength'
:
self
.
context_length
,
'padding
_t
rainable'
:
self
.
padding_trainable
,
'context
_s
tride'
:
self
.
context_stride
'context
S
tart'
:
self
.
context_start
,
'context
L
ength'
:
self
.
context_length
,
'padding
T
rainable'
:
self
.
padding_trainable
,
'context
S
tride'
:
self
.
context_stride
}
out
=
np
.
zeros
(
(
self
.
input_size
[
0
],
self
.
output_represention
)).
astype
(
'float32'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录