Skip to content

fix self.init_hidden never used #95

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

Merged
merged 2 commits into from
Jun 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions beginner_source/nlp/advanced_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def __init__(self, vocab_size, tag_to_ix, embedding_dim, hidden_dim):
self.hidden = self.init_hidden()

def init_hidden(self):
return (autograd.Variable(torch.randn(2, 1, self.hidden_dim)),
autograd.Variable(torch.randn(2, 1, self.hidden_dim)))
return (autograd.Variable(torch.randn(2, 1, self.hidden_dim // 2)),
autograd.Variable(torch.randn(2, 1, self.hidden_dim // 2)))

def _forward_alg(self, feats):
# Do the forward algorithm to compute the partition function
Expand Down Expand Up @@ -217,7 +217,7 @@ def _forward_alg(self, feats):
def _get_lstm_features(self, sentence):
self.hidden = self.init_hidden()
embeds = self.word_embeds(sentence).view(len(sentence), 1, -1)
lstm_out, self.hidden = self.lstm(embeds)
lstm_out, self.hidden = self.lstm(embeds, self.hidden)

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

lstm_out = lstm_out.view(len(sentence), self.hidden_dim)
lstm_feats = self.hidden2tag(lstm_out)
return lstm_feats
Expand Down