Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bidirectional_dynamic_rnn: make sequence length optional #5588

Closed
cbockman opened this issue Nov 13, 2016 · 9 comments
Closed

bidirectional_dynamic_rnn: make sequence length optional #5588

cbockman opened this issue Nov 13, 2016 · 9 comments
Labels
stat:contribution welcome Status - Contributions welcome

Comments

@cbockman
Copy link
Contributor

Qualifier: very new to TF, so I may be missing something very obvious. If so, apologies.

DOCUMENTATION:

Is a little conflicting:

"sequence_length: An int32/int64 vector, size [batch_size], containing the actual lengths for each of the sequences." <-- implies sequence_length is required

However...

"The initial state for both directions is zero by default (but can be set optionally) and no intermediate states are ever returned -- the network is fully unrolled for the given (passed in) length(s) of the sequence(s) or completely unrolled if length(s) is not given." <-- implies sequence_length is not required.

FUNCTIONALITY"

Base on the function itself ("dynamic"), I would assume that allowing sequence_length=None is intended (although, in either case, the documentation should be straightened out).

Assuming we do want to allow seq_length=None, the offending portion within bidirectional_dynamic_rnn would appear to be:

inputs_reverse = array_ops.reverse_sequence(...seq_lengths=sequence_length...)

reverse_sequence appears to require seq_lengths != None

Oddly enough, bidirectional_rnn may(?) be robust to this problem, as it uses _reverse_seq, which handles lengths=None.

That said, I haven't tested this extensively, as I'm of course not 100% sure I've interpreted the above correctly and as to what the intended functionality is.

Given guidance, I could take a stab at a pull request to address the above. Or maybe this is a quick fix/known issue (or non-issue...).

@girving
Copy link
Contributor

girving commented Nov 14, 2016

@ebrevdo My understanding is that sequence lengths should be required, since it doesn't make sense to do dynamic rnn fanciness otherwise. However, that language does seem to imply it's optional. Thoughts?

@girving girving added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Nov 14, 2016
@ebrevdo
Copy link
Contributor

ebrevdo commented Nov 14, 2016

You don't need sequence_lengths to do dynamic RNN; the fact that your time dimension is one of the axes of the inputs, and can vary from step to step, is what makes it dynamic. Providing sequence_lengths is necessary for correctness though: if you pass these in, your final state value will be the true final state at the end of the sequence. Otherwise it'll just keep calculating to the end of your inputs (which may include padding inputs - and this will throw your state off). That said, it does seem that if sequence_lengths is None, we should just use array_ops.reverse to do a blind reversal. The way bidirectional_rnn does. PRs welcome.

@ebrevdo ebrevdo added stat:awaiting response Status - Awaiting response from author and removed stat:awaiting tensorflower Status - Awaiting response from tensorflower labels Nov 14, 2016
@girving girving added stat:contribution welcome Status - Contributions welcome and removed stat:awaiting response Status - Awaiting response from author labels Nov 14, 2016
@girving girving changed the title bidirectional_dynamic_rnn inconsistent documentation (& possibly functionality) re: sequence_length bidirectional_dynamic_rnn: make sequence length optional Nov 14, 2016
@Jonbean
Copy link

Jonbean commented Feb 24, 2017

A follow up question: if we use padding inputs, and provide sequence_lengths to bidirectional_dynamic_rnn, would the backwark rnn read from the padding end or the true end of these padding inputs?
e.g.

inputs = [[1,2,3,4], [5,2,3,0], [9,8,0,0]]
would the backward rnn read from 0 or 3 in the second row? same question in row 3.

@ebrevdo
Copy link
Contributor

ebrevdo commented Mar 3, 2017 via email

@vanpersie32
Copy link

According to link1 and link2, backward rnn read the sequence from the true end of the padded input @Jonbean

@Jonbean
Copy link

Jonbean commented Nov 24, 2017

@vanpersie32 Thank you so much for pointing this out.

@zh794390558
Copy link
Contributor

@ebrevdo

Otherwise it'll just keep calculating to the end of your inputs (which may include padding inputs - and this will throw your state off). That said, it does seem that if sequence_lengths is None, we should just use array_ops.reverse to do a blind reversal.

Does this operation has performance degraded?

@ebrevdo
Copy link
Contributor

ebrevdo commented Dec 17, 2017 via email

@farhadGithub
Copy link

So in this example: inputs = [[9,8,0,0]]
does the backward start reading from 8 or from 0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:contribution welcome Status - Contributions welcome
Projects
None yet
Development

No branches or pull requests

7 participants