提交 db1bb822 编写于 作者: C chengduoZH

follow comments

上级 8e3ecf5d
...@@ -34,18 +34,15 @@ using EigenMatrix = framework::EigenMatrix<T, MajorType, IndexType>; ...@@ -34,18 +34,15 @@ using EigenMatrix = framework::EigenMatrix<T, MajorType, IndexType>;
* \param in Input data. * \param in Input data.
* \param Shape The shape of Input data, * \param Shape The shape of Input data,
* [minibatch, number_of_input_features]. * [minibatch, input_hidden_size].
* \param type A float LoDTensor.
* *
* \param padding_data Padding data. * \param padding_data Padding data.
* \param Shape The shape of Padding data, * \param Shape The shape of Padding data,
* [up_pad + down_pad, number_of_input_features]. * [up_pad + down_pad, input_hidden_size].
* \param type A float Tensor.
* *
* \param col Col data. * \param col Col data.
* \param Shape The shape of Col data, * \param Shape The shape of Col data,
* [minibatch, context_length * number_of_input_features]. * [minibatch, context_length * input_hidden_size].
* \param type A float Tensor.
* *
* For a mini-batch of 2 variable lengths sentences, containing 3, and 1 * For a mini-batch of 2 variable lengths sentences, containing 3, and 1
* time-steps: * time-steps:
......
...@@ -30,9 +30,9 @@ class SequenceConvOp : public framework::OperatorWithKernel { ...@@ -30,9 +30,9 @@ class SequenceConvOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE(ctx->HasOutput("Out"), PADDLE_ENFORCE(ctx->HasOutput("Out"),
"Output(Out) of SequenceConvOp should not be null."); "Output(Out) of SequenceConvOp should not be null.");
int context_length = ctx->Attrs().Get<int>("context_length"); int context_length = ctx->Attrs().Get<int>("contextLength");
bool padding_trainable = ctx->Attrs().Get<bool>("padding_trainable"); bool padding_trainable = ctx->Attrs().Get<bool>("paddingTrainable");
int context_start = ctx->Attrs().Get<int>("context_start"); int context_start = ctx->Attrs().Get<int>("contextStart");
auto in_dims = ctx->GetInputDim("X"); auto in_dims = ctx->GetInputDim("X");
auto filter_dims = ctx->GetInputDim("Filter"); auto filter_dims = ctx->GetInputDim("Filter");
...@@ -54,7 +54,7 @@ class SequenceConvOp : public framework::OperatorWithKernel { ...@@ -54,7 +54,7 @@ class SequenceConvOp : public framework::OperatorWithKernel {
if (context_start == 0 && context_length == 1) { if (context_start == 0 && context_length == 1) {
PADDLE_THROW( PADDLE_THROW(
"If context_start is 0 and context_length is 1, padding_trainable " "If context_start is 0 and context_length is 1, paddingTrainable "
"should be false."); "should be false.");
} }
PADDLE_ENFORCE(padding_dim.size() == 2, PADDLE_ENFORCE(padding_dim.size() == 2,
...@@ -81,7 +81,7 @@ class SequenceConvGradOp : public framework::OperatorWithKernel { ...@@ -81,7 +81,7 @@ class SequenceConvGradOp : public framework::OperatorWithKernel {
"Gradient of output(Out) should not be null."); "Gradient of output(Out) should not be null.");
PADDLE_ENFORCE(ctx->HasInput("X"), "The input(X) should not be null."); PADDLE_ENFORCE(ctx->HasInput("X"), "The input(X) should not be null.");
if (ctx->Attrs().Get<bool>("padding_trainable") && if (ctx->Attrs().Get<bool>("paddingTrainable") &&
ctx->HasOutput(framework::GradVarName("PaddingData"))) { ctx->HasOutput(framework::GradVarName("PaddingData"))) {
ctx->SetOutputDim(framework::GradVarName("PaddingData"), ctx->SetOutputDim(framework::GradVarName("PaddingData"),
ctx->GetInputDim("PaddingData")); ctx->GetInputDim("PaddingData"));
...@@ -128,25 +128,25 @@ class SequenceConvOpMaker : public framework::OpProtoAndCheckerMaker { ...@@ -128,25 +128,25 @@ class SequenceConvOpMaker : public framework::OpProtoAndCheckerMaker {
"this LoDTensor is a matrix with shape (T, D), where, T is the " "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."); "total time steps in this mini-batch, D is the output feature size.");
AddAttr<bool>("padding_trainable", AddAttr<bool>("paddingTrainable",
"(bool, default false) the padding data of SequenceConvOp " "(bool, default false) the padding data of SequenceConvOp "
"is trainable or not.") "is trainable or not.")
.SetDefault(false); .SetDefault(false);
AddAttr<int>("context_length", AddAttr<int>("contextLength",
"(int, default 3) the context_length of SequenceConvOp is the " "(int, default 3) the contextLength of SequenceConvOp is the "
"height of the convolution kernel.") "height of the convolution kernel.")
.SetDefault(3) .SetDefault(3)
.GreaterThan(0); .GreaterThan(0);
AddAttr<int>("context_start", AddAttr<int>("contextStart",
"(int, default 0) the context_start of SequenceConvOp " "(int, default 0) the contextStart of SequenceConvOp "
"represents the beginning of the convolution of the number of " "represents the beginning of the convolution of the number of "
"rows of sequence, which can be negative.") "rows of sequence, which can be negative.")
.SetDefault(0); .SetDefault(0);
AddAttr<int>("context_stride", AddAttr<int>("contextStride",
"(int, default 1) the context_stride of SequenceConvOp " "(int, default 1) the contextStride of SequenceConvOp "
"represents the step length of convolution. " "represents the step length of convolution. "
"Currently, SequenceConvOp only supports" "Currently, SequenceConvOp only supports"
"context_stride=1.") "contextStride=1.")
.SetDefault(1) .SetDefault(1)
.GreaterThan(0); .GreaterThan(0);
......
...@@ -35,10 +35,10 @@ class SequenceConvKernel : public framework::OpKernel<T> { ...@@ -35,10 +35,10 @@ class SequenceConvKernel : public framework::OpKernel<T> {
out->mutable_data<T>(context.GetPlace()); out->mutable_data<T>(context.GetPlace());
context.ShareLoD("X", "Out"); context.ShareLoD("X", "Out");
int context_start = context.Attr<int>("context_start"); int context_start = context.Attr<int>("contextStart");
int context_length = context.Attr<int>("context_length"); int context_length = context.Attr<int>("contextLength");
int context_stride = context.Attr<int>("context_stride"); int context_stride = context.Attr<int>("contextStride");
bool padding_trainable = context.Attr<bool>("padding_trainable"); bool padding_trainable = context.Attr<bool>("paddingTrainable");
// InferShape by in_lod // InferShape by in_lod
PADDLE_ENFORCE_EQ(in->lod().size(), 1UL, PADDLE_ENFORCE_EQ(in->lod().size(), 1UL,
...@@ -89,10 +89,10 @@ class SequenceConvGradKernel : public framework::OpKernel<T> { ...@@ -89,10 +89,10 @@ class SequenceConvGradKernel : public framework::OpKernel<T> {
auto* in = context.Input<LoDTensor>("X"); auto* in = context.Input<LoDTensor>("X");
auto* filter = context.Input<Tensor>("Filter"); auto* filter = context.Input<Tensor>("Filter");
int context_start = context.Attr<int>("context_start"); int context_start = context.Attr<int>("contextStart");
int context_length = context.Attr<int>("context_length"); int context_length = context.Attr<int>("contextLength");
int context_stride = context.Attr<int>("context_stride"); int context_stride = context.Attr<int>("contextStride");
bool padding_trainable = context.Attr<bool>("padding_trainable"); bool padding_trainable = context.Attr<bool>("paddingTrainable");
PADDLE_ENFORCE_EQ(in->lod().size(), 1UL, PADDLE_ENFORCE_EQ(in->lod().size(), 1UL,
"Only support one level sequence now."); "Only support one level sequence now.");
......
...@@ -45,10 +45,10 @@ class TestSeqProject(OpTest): ...@@ -45,10 +45,10 @@ class TestSeqProject(OpTest):
self.inputs_val_no_f = ['PaddingData', 'X'] self.inputs_val_no_f = ['PaddingData', 'X']
self.attrs = { self.attrs = {
'context_start': self.context_start, 'contextStart': self.context_start,
'context_length': self.context_length, 'contextLength': self.context_length,
'padding_trainable': self.padding_trainable, 'paddingTrainable': self.padding_trainable,
'context_stride': self.context_stride 'contextStride': self.context_stride
} }
out = np.zeros( out = np.zeros(
(self.input_size[0], self.output_represention)).astype('float32') (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.
先完成此消息的编辑!
想要评论请 注册