Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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

This comment has been minimized.

Copy link

@db1741 db1741 commented Aug 5, 2020

how to execute it

@arjunrockz

This comment has been minimized.

Copy link

@arjunrockz arjunrockz commented Oct 31, 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.

@jffryteo

This comment has been minimized.

Copy link

@jffryteo 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