I have a tensor slice dataset made from two ragged tensors.
tensor_a is like: <tf.RaggedTensor [[3, 3, 5], [3, 3, 14, 4, 17, 20], [3, 14, 22, 17]]>
tensor_b is like: <tf.RaggedTensor [[-1, 1, -1], [-1, -1, 1, -1, -1, -1], [-1, 1, -1, 2]]>
(Same index, same length for tensor_a and tensor_b.)
I made the dataset by
dataset = tf.data.Dataset.from_tensor_slices((tensor_a, tensor_b))
dataset
<TensorSliceDataset element_spec=(RaggedTensorSpec(TensorShape([None]), tf.int64, 0, tf.int64), RaggedTensorSpec(TensorShape([None]), tf.int32, 0, tf.int64))>
How to pad the sequences in my dataset? I've tried tf.pad
and tf.keras.preprocessing.sequence.pad_sequences
but haven't found a right way.
You could try something like this:
For pre-padding, just adjust the
pad
function: