I would like to do backward-direction LSTM on a padded sequence, which requires reversing the input sequence without the padding.
For a batch like this (where _ stands for padding):
a b c _ _ _
d e f g _ _
h i j k l m
if would like to get:
c b a _ _ _
g f e d _ _
m l k j i h
TensorFlow has a function tf.reverse_sequence that takes the input tensor and lengths of the sequences in the batch and returns the reversed batch. Is there an easy way of doing it in Pytorch?