sequence_enumerate

paddle.static.nn. sequence_enumerate ( input, win_size, pad_value=0, name=None ) [source]
Generate a new sequence for the input index sequence with

shape [d_1, win_size], which enumerates all the sub-sequences with length win_size of the input with shape [d_1, 1], and padded by pad_value if necessary in generation.

Please note that the input must be Tensor.

Input x:
    x.lod = [[0, 3, 5]]
    x.data = [[1], [2], [3], [4], [5]]
    x.dims = [5, 1]

Attrs:
    win_size = 2
    pad_value = 0

Output:
    out.lod = [[0, 3, 5]]
    out.data = [[1, 2], [2, 3], [3, 0], [4, 5], [5, 0]]
    out.dims = [5, 2]
Parameters
  • input (Tensor) – The input variable which is a index sequence, which should be a Tensor with shape [d_1, 1] and 1-level lod info. The data type should be int32 or int64.

  • win_size (int) – The window size for enumerating all sub-sequences.

  • pad_value (int, optional) – The padding value, default 0.

  • name (str, optional) – For detailed information, please refer to Name. Usually name is no need to set and None by default.

Returns

Tensor, The enumerate sequence variable which is a Tensor with shape [d_1, win_size] and 1-level lod info. The data type is same as input.

Examples

>>> import paddle
>>> paddle.enable_static()

>>> x = paddle.static.data(name='x', shape=[-1, 1], dtype='int32', lod_level=1)
>>> out = paddle.static.nn.sequence_enumerate(input=x, win_size=3, pad_value=0)