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

Updated docstring for LSTM layer - Specifying order of outputs #11726

Merged
merged 2 commits into from Dec 9, 2018

Conversation

eyalzk
Copy link
Contributor

@eyalzk eyalzk commented Nov 24, 2018

Summary

When using the LSTM layer with return_state = True the last states are returned in addition to the output of the layer. However, it is not clear from the documentation what is the order of the returned states (hidden state vs. cell state). For example, in:
output, state_1, state_2 = LSTM(100, return_state=True)(x)
I would like to know which of state_1\2 is the last hidden state and which one is the cell state.

PR Overview

Following the code I'm pretty sure I got the order right - [hidden state, cell state]. However if you decide to include this change it would be nice for another set of eyes to make sure the order is correct.

  • [n] This PR requires new unit tests [y/n] (make sure tests are included)
  • [y] This PR requires to update the documentation [y/n] (make sure the docs are up-to-date)
  • [y] This PR is backwards compatible [y/n]
  • [n] This PR changes the current API [y/n] (all API changes need to be approved by fchollet)

… the

state elements (hidden vs. cell state) when using return_state=True.
@gabrieldemarmiesse
Copy link
Contributor

Thank you for the PR. We currently have issues with travis, causing tests to fail. It's not due to your pull request. Please be patient while we fix the broken tests.

@@ -2096,7 +2096,8 @@ class LSTM(RNN):
return_sequences: Boolean. Whether to return the last output
in the output sequence, or the full sequence.
return_state: Boolean. Whether to return the last state
in addition to the output.
in addition to the output. The returned elements of the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, @eyalzk. How about adding related descriptions into L293-299 (class RNN)? For example, the number of state tensors is 1 (RNN and GRU) or 2 (LSTM).

Copy link
Contributor Author

@eyalzk eyalzk Nov 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your reply @taehoonlee .
I agree that extra reference in the RNN layer docstring is a good idea.
However, the RNN layer can potentially be used with a custom RNN cell with more than 2 defined states. So what I would change in your suggested phrasing, is just to include the 'For example' part :)
For example, the number of state tensors is 1 (RNN and GRU) or 2 (LSTM)
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eyalzk, Good point. I agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! @taehoonlee
Added a new commit.

Copy link
Contributor

@gabrieldemarmiesse gabrieldemarmiesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for the pull request!

@gabrieldemarmiesse gabrieldemarmiesse merged commit 4449be1 into keras-team:master Dec 9, 2018
kiku-jw pushed a commit to kiku-jw/keras that referenced this pull request Mar 4, 2019
…-team#11726)

* Updated the doc for LSTM layer. It was not clear what is the order of the
state elements (hidden vs. cell state) when using return_state=True.

* Updated doc for RNN layer accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants