提交 0b7d82be 编写于 作者: C chenweihang

doc: refine English description

上级 0c4697f8
......@@ -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<int>("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<int>("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:
......
......@@ -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.
......
......@@ -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()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册