Skip to content

Instantly share code, notes, and snippets.

@mohdsanadzakirizvi
Created August 7, 2019 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohdsanadzakirizvi/503586374468024bcbcb3e1a4408927a to your computer and use it in GitHub Desktop.
Save mohdsanadzakirizvi/503586374468024bcbcb3e1a4408927a to your computer and use it in GitHub Desktop.
# generate a sequence of characters with a language model
def generate_seq(model, mapping, seq_length, seed_text, n_chars):
in_text = seed_text
# generate a fixed number of characters
for _ in range(n_chars):
# encode the characters as integers
encoded = [mapping[char] for char in in_text]
# truncate sequences to a fixed length
encoded = pad_sequences([encoded], maxlen=seq_length, truncating='pre')
# predict character
yhat = model.predict_classes(encoded, verbose=0)
# reverse map integer to character
out_char = ''
for char, index in mapping.items():
if index == yhat:
out_char = char
break
# append to input
in_text += char
return in_text
@db1741
Copy link

db1741 commented Aug 5, 2020

how to execute it

@arjunrockz
Copy link

can u give some examples for the above model. In the analytics vidya is was mentioned example will be given but the space is blank.
A sample input for the above function will be very helpful.

@jffryteo
Copy link

jffryteo commented Nov 6, 2020

can u give some examples for the above model. In the analytics vidya is was mentioned example will be given but the space is blank.
A sample input for the above function will be very helpful.

same here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment