sequence_reverse

paddle.fluid.layers.sequence_lod. sequence_reverse ( x, name=None ) [source]

Notes: The Op only receives LoDTensor as input. If your input is Tensor, please use reverse Op.(fluid.layers. api_fluid_layers_reverse ).

This operator only supports LoDTensor as input. It will reverse each sequence for input LoDTensor. Currently it only supports 1-level LoDTensor. This operator is very useful when building a reverse api_fluid_layers_DynamicRNN network.

input(x) is a LoDTensor:
    x.lod  = [[0, 2, 5]]
    x.data = [[1,  2,  3,  4],
              [5,  6,  7,  8],
              [9, 10, 11, 12],
              [13,14, 15, 16],
              [17,18, 19, 20]]
    x.shape = [5, 4]

output LoDTensor with same shape and LoD info:
    out.lod  = [[0, 2, 5]]
    out.data = [[5,  6,  7,  8],
                [1,  2,  3,  4],
                [17,18, 19, 20],
                [13,14, 15, 16],
                [9, 10, 11, 12]]
    out.shape = [5, 4]
Parameters
  • x (Variable) – LoDTensor with 1-level LoD info. Currently it only supports 1-level LoDTensor. The data type should be float32, float64, int8, int32 or int64.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name .

Returns

LoDTensor reversed from input. The data type is same with input.

Return type

Variable

Examples

import paddle.fluid as fluid
x = fluid.data(name='x', shape=[None, 10], dtype='float32', lod_level=1)
x_reversed = fluid.layers.sequence_reverse(x)