sequence_slice(input, offset, length, name=None)
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**: input.data = [[a1, a2], [b1, b2], [c1, c2], [d1, d2], [e1, e2]], input.lod = [[3, 2]], input.dims = (5, 2), with offset.data = [, ] and length.data = [, ], the output Variable will be out.data = [[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 is float32 or float64.
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.fluid as fluid import numpy as np seqs = fluid.data(name='x', shape=[10, 5], dtype='float32', lod_level=1) offset = fluid.layers.assign(input=np.array([[0, 1]]).astype("int32")) length = fluid.layers.assign(input=np.array([[2, 1]]).astype("int32")) subseqs = fluid.layers.sequence_slice(input=seqs, offset=offset, length=length)