I'm having trouble understanding the input parameter for tensorflow's dynamic_rnn
. It'd help a lot if I could understand how to convert static_rnn
inputs to dynamic_rnn
inputs.
For a static_rnn
, the input is supposed to be a length T
list of tensors whose shapes are [batch_size, input_size]
, where T
is the sequence length. This makes sense to me.
For a dynamic_rnn
, the input is supposed to be a Tensor of shape [batch_size, max_time, ...]
. I don't understand how to incorporate input_size
here. More generally, I don't know what else you could put in the ellipsis.
Say, for example, that my data consists of 50-character-long sentences, so the input_size
is the number of letters in the alphabet. For a static_rnn
, I'd make a length 50 list of tensors whose shapes are [batch_size, input_size]
. How do I convert this list of tensors to a single tensor, so that I can feed it to a dynamic_rnn
?
Your dynamic_rnn
input should be of shape [batch_size, sequence_length, input_size]
.
Basically the tensor represents batch_size
examples of length sequence_length
, and whatever is left in the ellipsis is the shape of a single sequence element.
The thing is, with dynamic_rnn
you don't need to know sequence_length beforehand, so your input placeholder could look like
x = tf.placeholder(tf.int32, shape=(batch_size, None, input_size))
Which comes in pretty handy. Furthermore, examples in a single batch can have different lengths (but must be padded to the same length), but you must pass the sequence_length
parameter to dynamic_rnn
so it knows when to stop calculations for each example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With