generative deep learning because your targets are one-hot encodedyou'll use categorical_crossentropy as the loss to train the model listing model compilat ion configurat ion optimizer keras optimizers rmsprop(lr= model compile(loss='categorical_crossentropy'optimizer=optimizertraining the language model and sampling from it given trained model and seed text snippetyou can generate new text by doing the following repeatedly draw from the model probability distribution for the next charactergiven the generated text available so far reweight the distribution to certain temperature sample the next character at random according to the reweighted distribution add the new character at the end of the available text this is the code you use to reweight the original probability distribution coming out of the model and draw character index from it (the sampling functionlisting funct ion sample he next charact er given the model' predict ions def sample(predstemperature= )preds np asarray(predsastype('float 'preds np log(predstemperature exp_preds np exp(predspreds exp_preds np sum(exp_predsprobas np random multinomial( preds return np argmax(probasfinallythe following loop repeatedly trains and generates text you begin generating text using range of different temperatures after every epoch this allows you to see how the generated text evolves as the model begins to convergeas well as the impact of temperature in the sampling strategy listing import random import sys text -generation loop trains the model for epochs for epoch in range( )fits the model for one iteration print('epoch'epochon the data model fit(xybatch_size= epochs= selects text start_index random randint( len(textmaxlen seed at generated_text text[start_indexstart_index maxlenrandom print('--generating with seed"generated_text '"'for temperature in [ ]print(temperature:'temperaturesys stdout write(generated_textlicensed to tries range of different sampling temperatures