How to handle variable length of sequences when using RNNCell

Hi! I am considering using the RNNCell to handle a sequence task. I know that batch processing with padding and packing can accelerate the calculation. However, it is not feasible in my task because the data needs preprocessing at each time step.

Now I am considering to output the hidden state of the RNN at each time step using RNNCell. But I couldn’t figure out how to handle the variable length of sequences. I don’t know if masking the output would work.

Has anbody had this problem? Thanks for your help!

You can find the answer to this question by reading any work that requires teacher forcing on github. It may not be the most efficient solution but it works.


Here is one example, just read the forward function for DecoderWithAttention class.
1 Like