I am trying to use the Dataset API to prepare a TFRecordDataset of text sequences. After processing, I have a dictionary of tensors for each record. Each record contains two sequences.
I am using padded_batch to apply padding
dataset = dataset.padded_batch(batch_size, padded_shapes= {
'seq1': tf.TensorShape([None]),
'seq2': tf.TensorShape([None])
})
This pads each sequence to the maximum sequence lengths in the batch. However, I would like to choose an arbitrary sequence length and pad to this length when the true sequence length is less else truncate the sequence.
When I try replacing None with 100 for example, I encounter a DataLossError
DataLossError: Attempted to pad to a smaller size than the input element.
Is there a way to do this to achieve similar functionality as tf.image.resize_image_with_crop_or_pad on a sequence?