sequence_unpad(x, length, name=None)
The input of the OP is Tensor and the output is LoDTensor. For padding operation, See: sequence_pad
The OP removes the padding data from the input based on the length information and returns a LoDTensor.
Case 1: Given input Variable **x**: x.data = [[ 1.0, 2.0, 3.0, 4.0, 5.0], [ 6.0, 7.0, 8.0, 9.0, 10.0], [11.0, 12.0, 13.0, 14.0, 15.0]], in which there are 3 sequences padded to length 5, and the acutal length specified by input Variable **length**: length.data = [2, 3, 4], after unpadding, the output Variable will be: out.data = [[1.0, 2.0, 6.0, 7.0, 8.0, 11.0, 12.0, 13.0, 14.0]] out.lod = [[0, 2, 5, 9]]
x (Variable) – A Tensor which contains padding data, and its shape size can not be less than 2. Supported data types: float32, float64, int32, int64.
length (Variable) – A 1D Tensor that stores the actual length of each sample, and the Tensor has the same shape with the 0th dimension of the X . Supported data types: 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
A LoDTensor whose recursive sequence length is consistent with the information of the length parameter and it has the same data type with input.
- Return type
import paddle.fluid as fluid import numpy # pad data x = fluid.data(name='x', shape=[10, 5], dtype='float32', lod_level=1) pad_value = fluid.layers.assign(input=numpy.array([0.0], dtype=numpy.float32)) pad_data, len = fluid.layers.sequence_pad(x=x, pad_value=pad_value) # unpad data unpad_data = fluid.layers.sequence_unpad(x=pad_data, length=len)