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

How to reinitialize the hidden states of RNNs? #587

Open
qlan3 opened this issue Dec 22, 2022 · 0 comments
Open

How to reinitialize the hidden states of RNNs? #587

qlan3 opened this issue Dec 22, 2022 · 0 comments

Comments

@qlan3
Copy link

qlan3 commented Dec 22, 2022

I want use initial_state in this way but get an error: AttributeError: 'Transformed' object has no attribute 'init_hidden_state'
What is the best way to to this?

import haiku as hk

class RNN(hk.Module):
  def __init__(self, hidden_size=4, name=None):
    super().__init__(name=name)
    self.rnn = hk.LSTM(hidden_size)

  def __call__(self, h, x):
    out, h = self.rnn(x, h)
    return h, out

  def init_hidden_state(self, batch_size=1):
    return self.rnn.initial_state(batch_size)

model = hk.without_apply_rng(hk.transform(lambda h, x: RNN(4)(h, x)))
h = model.init_hidden_state(1)
@qlan3 qlan3 changed the title How to use reinitialize the hidden states of RNNs? How to reinitialize the hidden states of RNNs? Dec 22, 2022
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

No branches or pull requests

1 participant