Skip to content

Commit 0b7d82b

Browse files
committed
doc: refine English description
1 parent 0c4697f commit 0b7d82b

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

paddle/fluid/operators/sequence_enumerate_op.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,23 @@ class SequenceEnumerateOpMaker : public framework::OpProtoAndCheckerMaker {
5050
"(2-D LoDTensor with the 2nd dimension equal to 1) "
5151
"Input LoDTensor of SequenceEnumerate operator.");
5252
AddOutput("Out",
53-
"(2-D LoDTensor with the 2nd dimension equal to 1) "
53+
"(2-D LoDTensor with the 2nd dimension equal to win_size) "
5454
"Output LoDTensor of SequenceEnumerate operator.");
5555
AddAttr<int>("win_size", "(int) The enumerate sequence window size.")
5656
.AddCustomChecker([](const int& win_size) {
5757
PADDLE_ENFORCE(win_size >= 2,
58-
"The window size should be greater than 2.");
58+
"The window size should be not less than 2.");
5959
});
6060
AddAttr<int>("pad_value", "(int) The enumerate sequence padding value.")
6161
.SetDefault(0);
6262
AddComment(R"DOC(
6363
Sequence Enumerate Operator.
6464
65-
Sequence enumerate operator generate a new LoDTensor
66-
with the same 1st dimension length as the original LoDTensor,
67-
and with the 2nd dimension equal to the input window length,
68-
the new sub-sequence on 2nd dimension is enumerated one by one on the original sequence.
69-
The values of the last insufficient part areall filled with the input pad_value.
70-
65+
Generate a new sequence for the input index sequence, which enumerates all the
66+
sub-sequences with length win_size of the input.
67+
The enumerated sequence has the same 1st dimension with variable input, and
68+
the 2nd dimension is win_size, padded by pad_value if necessary in generation.
69+
7170
Examples:
7271
Case 1:
7372
Input:

python/paddle/fluid/layers/nn.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5522,13 +5522,12 @@ def flatten(x, axis=1, name=None):
55225522
return out
55235523

55245524

5525-
def sequence_enumerate(input, win_size, pad_value, name=None):
5525+
def sequence_enumerate(input, win_size, pad_value=0, name=None):
55265526
"""
5527-
Generate a new LoDTensor
5528-
with the same 1st dimension length as the original LoDTensor,
5529-
and with the 2nd dimension equal to the input window length,
5530-
the new sub-sequence on 2nd dimension is enumerated one by one on the original sequence.
5531-
The values of the last insufficient part areall filled with the input pad_value.
5527+
Generate a new sequence for the input index sequence, which enumerates all the
5528+
sub-sequences with length win_size of the input.
5529+
The enumerated sequence has the same 1st dimension with variable input, and
5530+
the 2nd dimension is win_size, padded by pad_value if necessary in generation.
55325531
55335532
Examples:
55345533
Case 1:
@@ -5545,9 +5544,9 @@ def sequence_enumerate(input, win_size, pad_value, name=None):
55455544
Out.dims = [5, 2]
55465545
55475546
Args:
5548-
input (Variable): The input variable which is a LoDTensor
5549-
win_size (int): The enumerate sequence window size.
5550-
pad_value (int): The enumerate sequence padding value.
5547+
input (Variable): The input variable which is a index sequence.
5548+
win_size (int): The window size for enumerating all sub-sequences.
5549+
pad_value (int): The padding value, default 0.
55515550
55525551
Returns:
55535552
Variable: The enumerate sequence variable which is a LoDTensor.

python/paddle/fluid/tests/unittests/test_sequence_enumerate_op.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ def init_test_case(self):
6868
self.out_seq = np.array(out_seq).astype("int64")
6969

7070

71+
class TestSequenceEnumerateOpLargeWinSize(TestSequenceEnumerateOp):
72+
def init_test_case(self):
73+
self.in_seq = np.random.randint(0, 10, (30, 1)).astype("int32")
74+
self.lod = [[9, 4, 11, 6]]
75+
self.win_size = 5
76+
self.pad_value = 0
77+
out_seq = sequence_enumerate(self.in_seq, self.lod, self.win_size,
78+
self.pad_value)
79+
self.out_seq = np.array(out_seq).astype("int32")
80+
81+
7182
class TestSequenceEnumerateOpMaxWinSize(TestSequenceEnumerateOp):
7283
def init_test_case(self):
7384
self.in_seq = np.random.randint(0, 10, (30, 1)).astype("int32")
@@ -79,5 +90,16 @@ def init_test_case(self):
7990
self.out_seq = np.array(out_seq).astype("int32")
8091

8192

93+
class TestSequenceEnumerateOpLargePadValue(TestSequenceEnumerateOp):
94+
def init_test_case(self):
95+
self.in_seq = np.random.randint(0, 10, (30, 1)).astype("int32")
96+
self.lod = [[9, 4, 11, 6]]
97+
self.win_size = 5
98+
self.pad_value = 5
99+
out_seq = sequence_enumerate(self.in_seq, self.lod, self.win_size,
100+
self.pad_value)
101+
self.out_seq = np.array(out_seq).astype("int32")
102+
103+
82104
if __name__ == "__main__":
83105
unittest.main()

0 commit comments

Comments
 (0)