text generation with lstm nextyou'll extract partially overlapping sequences of length maxlenone-hot encode themand pack them in numpy array of shape (sequencesmaxlenunique_characterssimultaneouslyyou'll prepare an array containing the corresponding targetsthe one-hot-encoded characters that come after each extracted sequence listing vect orizing sequences of charact ers you'll extract sequences of characters maxlen you'll sample new sequence every three characters step sentences [holds the extracted sequences next_chars [for in range( len(textmaxlenstep)sentences append(text[ii maxlen]next_chars append(text[ maxlen]holds the targets (the follow-up characterslist of unique characters in the corpus print('number of sequences:'len(sentences)chars sorted(list(set(text))print('unique characters:'len(chars)dictionary that maps unique characters to their index in the list charschar_indices dict((charchars index(char)for char in charsprint('vectorization ' np zeros((len(sentences)maxlenlen(chars))dtype=np booly np zeros((len(sentences)len(chars))dtype=np boolfor isentence in enumerate(sentences)for tchar in enumerate(sentence) [itchar_indices[char] one-hot encodes the characters into binary arrays [ichar_indices[next_chars[ ]] building the network this network is single lstm layer followed by dense classifier and softmax over all possible characters but note that recurrent neural networks aren' the only way to do sequence data generation convnets also have proven extremely successful at this task in recent times listing single-layer lstm model for next -charact er predict ion from keras import layers model keras models sequential(model add(layers lstm( input_shape=(maxlenlen(chars)))model add(layers dense(len(chars)activation='softmax')licensed to