Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created October 5, 2020 03:52
Show Gist options
  • Save amankharwal/c99f80e5eb9284c900f3b2fff0209b0b to your computer and use it in GitHub Desktop.
Save amankharwal/c99f80e5eb9284c900f3b2fff0209b0b to your computer and use it in GitHub Desktop.
def generate_text(seed_text, next_words, model, max_sequence_len):
for _ in range(next_words):
token_list = tokenizer.texts_to_sequences([seed_text])[0]
token_list = pad_sequences([token_list], maxlen=max_sequence_len-1, padding=’pre’)
predicted = model.predict_classes(token_list, verbose=0)
output_word = “”
for word,index in tokenizer.word_index.items():
if index == predicted:
output_word = word
break
seed_text += “ “+output_word
return seed_text.title()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment