paddle.static.nn. sequence_slice ( input, offset, length, name=None ) [source]

Static Graph

Sequence Slice Layer

The layer crops a subsequence from given sequence with given start offset and subsequence length.

It only supports sequence data (LoDTensor with lod_level equal to 1).

  - Case:

Given the input Variable **input**: = [[a1, a2], [b1, b2], [c1, c2], [d1, d2], [e1, e2]],
    input.lod = [[3, 2]],
    input.dims = (5, 2),

with = [[0], [1]] and = [[2], [1]],

the output Variable will be = [[a1, a2], [b1, b2], [e1, e2]],
    out.lod = [[2, 1]],
    out.dims = (3, 2).


The first dimension size of input, offset and length should be equal. The offset should start from 0.

  • input (Variable) – LoDTensor, The input Variable which consists of the complete sequences.The data type can be float32, float64, int32 or int64

  • offset (Variable) – LoDTensor, The offset to slice each sequence. The data type is int32 or int64.

  • length (Variable) – LoDTensor, The length of each subsequence. The data type is int32 or int64.

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


The output subsequences.

Return type



import paddle

import numpy as np
seqs ='x', shape=[10, 5],
                 dtype='float32', lod_level=1)
offset = paddle.assign(np.array([[0, 1]]).astype("int32"))
length = paddle.assign(np.array([[2, 1]]).astype("int32"))
subseqs = paddle.static.nn.sequence_slice(input=seqs, offset=offset,