Created
February 25, 2016 09:18
-
-
Save cerisara/86c5135a0b886055b446 to your computer and use it in GitHub Desktop.
generate sequence from LSTM in Keras: attempt from https://www.reddit.com/r/MachineLearning/comments/3dqdqr/keras_lstm_limitations/
This file contains 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
complete_sentences = [["*-START-*"] for a in range(1000)] | |
sents = np.zeros((nb_samples, timesteps+1, len(vocab))) | |
for x in range(nb_samples): | |
sents[i,0,word2index["*-START-*"]] = 1. # init the sequences | |
for t in range(timesteps): | |
preds = self.model.predict(sents[:,0:t+1], verbose=0) | |
# get the maximum predictions for this timestep for each sample | |
next_word_indices = np.argmax(preds[:,t], axis=1) | |
# fill in the input at the next timestep with the prediction from this timestep | |
for i in range(nb_samples): | |
sents[i, t+1, next_word_indices[i]] = 1. | |
next_words = [index2word[x] for x in next_word_indices] | |
for i in range(len(next_words)): | |
complete_sentences[i].append(next_words[i]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment