From 0b7d82befba589da0a00168625f6d16c84c87290 Mon Sep 17 00:00:00 2001 From: chenweihang Date: Fri, 31 Aug 2018 12:48:32 +0000 Subject: [PATCH] doc: refine English description --- .../fluid/operators/sequence_enumerate_op.cc | 15 ++++++------- python/paddle/fluid/layers/nn.py | 17 +++++++------- .../unittests/test_sequence_enumerate_op.py | 22 +++++++++++++++++++ 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/paddle/fluid/operators/sequence_enumerate_op.cc b/paddle/fluid/operators/sequence_enumerate_op.cc index 307a4ece92..ae0241bd77 100644 --- a/paddle/fluid/operators/sequence_enumerate_op.cc +++ b/paddle/fluid/operators/sequence_enumerate_op.cc @@ -50,24 +50,23 @@ class SequenceEnumerateOpMaker : public framework::OpProtoAndCheckerMaker { "(2-D LoDTensor with the 2nd dimension equal to 1) " "Input LoDTensor of SequenceEnumerate operator."); AddOutput("Out", - "(2-D LoDTensor with the 2nd dimension equal to 1) " + "(2-D LoDTensor with the 2nd dimension equal to win_size) " "Output LoDTensor of SequenceEnumerate operator."); AddAttr("win_size", "(int) The enumerate sequence window size.") .AddCustomChecker([](const int& win_size) { PADDLE_ENFORCE(win_size >= 2, - "The window size should be greater than 2."); + "The window size should be not less than 2."); }); AddAttr("pad_value", "(int) The enumerate sequence padding value.") .SetDefault(0); AddComment(R"DOC( Sequence Enumerate Operator. -Sequence enumerate operator generate a new LoDTensor -with the same 1st dimension length as the original LoDTensor, -and with the 2nd dimension equal to the input window length, -the new sub-sequence on 2nd dimension is enumerated one by one on the original sequence. -The values of the last insufficient part areall filled with the input pad_value. - +Generate a new sequence for the input index sequence, which enumerates all the +sub-sequences with length win_size of the input. +The enumerated sequence has the same 1st dimension with variable input, and +the 2nd dimension is win_size, padded by pad_value if necessary in generation. + Examples: Case 1: Input: diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 14ebe22b62..ffb9858108 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -5522,13 +5522,12 @@ def flatten(x, axis=1, name=None): return out -def sequence_enumerate(input, win_size, pad_value, name=None): +def sequence_enumerate(input, win_size, pad_value=0, name=None): """ - Generate a new LoDTensor - with the same 1st dimension length as the original LoDTensor, - and with the 2nd dimension equal to the input window length, - the new sub-sequence on 2nd dimension is enumerated one by one on the original sequence. - The values of the last insufficient part areall filled with the input pad_value. + Generate a new sequence for the input index sequence, which enumerates all the + sub-sequences with length win_size of the input. + The enumerated sequence has the same 1st dimension with variable input, and + the 2nd dimension is win_size, padded by pad_value if necessary in generation. Examples: Case 1: @@ -5545,9 +5544,9 @@ def sequence_enumerate(input, win_size, pad_value, name=None): Out.dims = [5, 2] Args: - input (Variable): The input variable which is a LoDTensor - win_size (int): The enumerate sequence window size. - pad_value (int): The enumerate sequence padding value. + input (Variable): The input variable which is a index sequence. + win_size (int): The window size for enumerating all sub-sequences. + pad_value (int): The padding value, default 0. Returns: Variable: The enumerate sequence variable which is a LoDTensor. diff --git a/python/paddle/fluid/tests/unittests/test_sequence_enumerate_op.py b/python/paddle/fluid/tests/unittests/test_sequence_enumerate_op.py index f2e5844c7f..9814ec0a15 100644 --- a/python/paddle/fluid/tests/unittests/test_sequence_enumerate_op.py +++ b/python/paddle/fluid/tests/unittests/test_sequence_enumerate_op.py @@ -68,6 +68,17 @@ class TesSequenceEnumerateOpInt64(TestSequenceEnumerateOp): self.out_seq = np.array(out_seq).astype("int64") +class TestSequenceEnumerateOpLargeWinSize(TestSequenceEnumerateOp): + def init_test_case(self): + self.in_seq = np.random.randint(0, 10, (30, 1)).astype("int32") + self.lod = [[9, 4, 11, 6]] + self.win_size = 5 + self.pad_value = 0 + out_seq = sequence_enumerate(self.in_seq, self.lod, self.win_size, + self.pad_value) + self.out_seq = np.array(out_seq).astype("int32") + + class TestSequenceEnumerateOpMaxWinSize(TestSequenceEnumerateOp): def init_test_case(self): self.in_seq = np.random.randint(0, 10, (30, 1)).astype("int32") @@ -79,5 +90,16 @@ class TestSequenceEnumerateOpMaxWinSize(TestSequenceEnumerateOp): self.out_seq = np.array(out_seq).astype("int32") +class TestSequenceEnumerateOpLargePadValue(TestSequenceEnumerateOp): + def init_test_case(self): + self.in_seq = np.random.randint(0, 10, (30, 1)).astype("int32") + self.lod = [[9, 4, 11, 6]] + self.win_size = 5 + self.pad_value = 5 + out_seq = sequence_enumerate(self.in_seq, self.lod, self.win_size, + self.pad_value) + self.out_seq = np.array(out_seq).astype("int32") + + if __name__ == "__main__": unittest.main() -- GitLab