Created
September 25, 2016 21:25
-
-
Save mrdrozdov/8e52880522176d4d0b6c1aff21324baa to your computer and use it in GitHub Desktop.
Simpler Chainer RNN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RNN_Sentence(Chain): | |
| def __init__(self, model_dim, word_embedding_dim, vocab_size, compose_network, | |
| seq_length, | |
| num_classes, | |
| initial_embeddings, | |
| ): | |
| super(RNN_Sentence, self).__init__( | |
| embed=L.EmbedID(vocab_size, word_embedding_dim, initialW=initial_embeddings), # word embedding | |
| mid=L.LSTM(word_embedding_dim, model_dim), # the first LSTM layer | |
| out=L.Linear(model_dim, num_classes), # the feed-forward output layer | |
| ) | |
| self.seq_length = seq_length | |
| def reset_state(self): | |
| self.mid.reset_state() | |
| def __call__(self, sent): | |
| x = self.embed(sent) | |
| for i in range(self.seq_length): | |
| self.mid(x[:, i:i+1]) | |
| h = self.mid.h | |
| y = self.out(h) | |
| return y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment