Skip to content

Instantly share code, notes, and snippets.

@cerisara
Created February 25, 2016 09:18
Show Gist options
  • Save cerisara/86c5135a0b886055b446 to your computer and use it in GitHub Desktop.
Save cerisara/86c5135a0b886055b446 to your computer and use it in GitHub Desktop.
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