sequence_enumerate

paddle.fluid.layers.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 LodTensor.

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 (Variable) – The input variable which is a index sequence, which should be a LodTensor with shape [d_1, 1] and 1-level lod info. The data type should be float32, float64, int8, 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: The enumerate sequence variable which is a LoDTensor with shape [d_1, win_size] and 1-level lod info. The data type is same as input.

Return Type: Variable

Examples

import paddle.fluid as fluid

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